diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-03 13:22:23 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-03 13:22:23 -0500 |
commit | 942aff3577ec36879e6b8b0ca7a51863afd47319 (patch) | |
tree | 2d3649e0009f8e7431435b09b3e5972e75025b1e | |
parent | 31181841edec356c049fae56f78aa5ba1c086619 (diff) | |
download | vt100-rust-942aff3577ec36879e6b8b0ca7a51863afd47319.tar.gz vt100-rust-942aff3577ec36879e6b8b0ca7a51863afd47319.zip |
simplify
-rw-r--r-- | src/grid.rs | 22 | ||||
-rw-r--r-- | src/row.rs | 4 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/grid.rs b/src/grid.rs index f6d3786..364c67e 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -21,6 +21,10 @@ impl Grid { } } + fn new_row(&self) -> crate::row::Row { + crate::row::Row::new(self.size.cols) + } + pub fn size(&self) -> Size { self.size } @@ -134,33 +138,31 @@ impl Grid { pub fn erase_all(&mut self) { self.rows = vec![ - crate::row::Row::new(self.size.cols); + self.new_row(); self.size.rows as usize ]; } pub fn erase_all_forward(&mut self) { - let size = self.size; let pos = self.pos; for row in self.rows_mut().skip(pos.row as usize + 1) { - *row = crate::row::Row::new(size.cols); + row.clear(); } self.erase_row_forward(); } pub fn erase_all_backward(&mut self) { - let size = self.size; let pos = self.pos; for row in self.rows_mut().take(pos.row as usize) { - *row = crate::row::Row::new(size.cols); + row.clear(); } self.erase_row_backward(); } pub fn erase_row(&mut self) { - *self.current_row_mut() = crate::row::Row::new(self.size.cols); + self.current_row_mut().clear(); } pub fn erase_row_forward(&mut self) { @@ -215,7 +217,7 @@ impl Grid { self.rows.remove(self.scroll_bottom as usize); self.rows.insert( self.pos.row as usize, - crate::row::Row::new(self.size.cols), + self.new_row(), ); } } @@ -224,7 +226,7 @@ impl Grid { for _ in 0..(count.min(self.size.rows - self.pos.row)) { self.rows.insert( self.scroll_bottom as usize + 1, - crate::row::Row::new(self.size.cols), + self.new_row(), ); self.rows.remove(self.pos.row as usize); } @@ -234,7 +236,7 @@ impl Grid { for _ in 0..(count.min(self.size.rows - self.scroll_top)) { self.rows.insert( self.scroll_bottom as usize + 1, - crate::row::Row::new(self.size.cols), + self.new_row(), ); self.rows.remove(self.scroll_top as usize); } @@ -245,7 +247,7 @@ impl Grid { self.rows.remove(self.scroll_bottom as usize); self.rows.insert( self.scroll_top as usize, - crate::row::Row::new(self.size.cols), + self.new_row(), ); } } @@ -14,6 +14,10 @@ impl Row { } } + pub fn clear(&mut self) { + *self = Self::new(self.cells.len().try_into().unwrap()); + } + pub fn cells_mut( &mut self, ) -> impl Iterator<Item = &mut crate::cell::Cell> { |