diff --git a/src/components/contacts.rs b/src/components/contacts.rs index 9feb6e42a..e1c4a169d 100644 --- a/src/components/contacts.rs +++ b/src/components/contacts.rs @@ -98,9 +98,7 @@ impl ContactManager { if self.card.external_resource() { self.mode = ViewMode::ReadOnly; - let _ = self - .content - .resize(self.content.size().0, 2, Cell::default()); + let _ = self.content.resize(self.content.size().0, 2, None); write_string_to_grid( "This contact's origin is external and cannot be edited within meli.", &mut self.content, diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs index 2e74dbf86..067b13210 100644 --- a/src/components/mail/listing.rs +++ b/src/components/mail/listing.rs @@ -1604,11 +1604,7 @@ impl Listing { ListingFocus::Menu => self.menu_cursor_pos, }; if min_width > width || height < total_height || self.dirty { - let _ = self.menu_content.resize( - min_width * 2, - total_height, - self.menu_content.default_cell, - ); + let _ = self.menu_content.resize(min_width * 2, total_height, None); let bottom_right = pos_dec(self.menu_content.size(), (1, 1)); let mut y = 0; for a in 0..self.accounts.len() { diff --git a/src/state.rs b/src/state.rs index 1553c5238..2f65c0c38 100644 --- a/src/state.rs +++ b/src/state.rs @@ -515,15 +515,13 @@ impl State { } self.cols = termcols.unwrap_or(72) as usize; self.rows = termrows.unwrap_or(120) as usize; - if !self.grid.resize(self.cols, self.rows, Cell::with_char(' ')) { + if !self.grid.resize(self.cols, self.rows, None) { panic!( "Terminal size too big: ({} cols, {} rows)", self.cols, self.rows ); } - let _ = self - .overlay_grid - .resize(self.cols, self.rows, Cell::with_char(' ')); + let _ = self.overlay_grid.resize(self.cols, self.rows, None); self.rcv_event(UIEvent::Resize); self.display_messages_dirty = true; diff --git a/src/terminal/cells.rs b/src/terminal/cells.rs index ecc3ab841..98a3e51fc 100644 --- a/src/terminal/cells.rs +++ b/src/terminal/cells.rs @@ -148,12 +148,13 @@ impl CellBuffer { /// Resizes `CellBuffer` to the given number of rows and columns, using the given `Cell` as /// a blank. #[must_use] - pub fn resize(&mut self, newcols: usize, newrows: usize, blank: Cell) -> bool { + pub fn resize(&mut self, newcols: usize, newrows: usize, blank: Option) -> bool { let newlen = newcols * newrows; if (self.cols, self.rows) == (newcols, newrows) || newlen >= Self::MAX_SIZE { return !(newlen >= Self::MAX_SIZE); } + let blank = blank.unwrap_or(self.default_cell); let mut newbuf: Vec = Vec::with_capacity(newlen); for y in 0..newrows { for x in 0..newcols { @@ -178,7 +179,8 @@ impl CellBuffer { } /// Clears `self`, using the given `Cell` as a blank. - pub fn clear(&mut self, blank: Cell) { + pub fn clear(&mut self, blank: Option) { + let blank = blank.unwrap_or(self.default_cell); for cell in self.cellvec_mut().iter_mut() { *cell = blank; } @@ -1086,11 +1088,7 @@ macro_rules! inspect_bounds { let (upper_left, bottom_right) = $area; if $x > (get_x(bottom_right)) || $x >= get_x(bounds) { if $grid.growable { - if !$grid.resize( - std::cmp::max($x + 1, $grid.cols), - $grid.rows, - $grid.default_cell, - ) { + if !$grid.resize(std::cmp::max($x + 1, $grid.cols), $grid.rows, None) { break; }; } else { @@ -1105,11 +1103,7 @@ macro_rules! inspect_bounds { } if $y > (get_y(bottom_right)) || $y >= get_y(bounds) { if $grid.growable { - if !$grid.resize( - $grid.cols, - std::cmp::max($y + 1, $grid.rows), - $grid.default_cell, - ) { + if !$grid.resize($grid.cols, std::cmp::max($y + 1, $grid.rows), None) { break; }; } else { @@ -1139,7 +1133,7 @@ pub fn write_string_to_grid( if !grid.resize( std::cmp::max(grid.cols, x + 2), std::cmp::max(grid.rows, y + 2), - grid.default_cell, + None, ) { return (x, y); } @@ -1158,7 +1152,7 @@ pub fn write_string_to_grid( if !grid.resize( std::cmp::max(grid.cols, x + 2), std::cmp::max(grid.rows, y + 2), - grid.default_cell, + None, ) { return (x, y); } diff --git a/src/terminal/embed/grid.rs b/src/terminal/embed/grid.rs index 848dc9ce9..cb922fd35 100644 --- a/src/terminal/embed/grid.rs +++ b/src/terminal/embed/grid.rs @@ -108,13 +108,13 @@ impl EmbedGrid { self.scroll_region.bottom = new_val.1.saturating_sub(1); self.terminal_size = new_val; - if !self.grid.resize(new_val.0, new_val.1, Cell::default()) { + if !self.grid.resize(new_val.0, new_val.1, None) { panic!( "Terminal size too big: ({} cols, {} rows)", new_val.0, new_val.1 ); } - self.grid.clear(Cell::default()); + self.grid.clear(Some(Cell::default())); self.cursor = (0, 0); self.wrap_next = false; let winsize = Winsize {