Browse Source

Use default_cell in CellBuffer resize(), clear()

jmap-eventsource
Manos Pitsidianakis 11 months ago
parent
commit
1c25ae12eb
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 4
      src/components/contacts.rs
  2. 6
      src/components/mail/listing.rs
  3. 6
      src/state.rs
  4. 22
      src/terminal/cells.rs
  5. 4
      src/terminal/embed/grid.rs

4
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,

6
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() {

6
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;

22
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<Cell>) -> 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<Cell> = 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<Cell>) {
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);
}

4
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 {

Loading…
Cancel
Save