diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-14 03:19:49 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-14 03:29:06 -0500 |
commit | 160942c40cbeb7503147c0895217644161fcc84b (patch) | |
tree | 87592d28566aacdc2179a8bd27db63303e055a77 | |
parent | 7c5809e747b52b6d0f1c207e2e138618b075457e (diff) | |
download | vt100-rust-160942c40cbeb7503147c0895217644161fcc84b.tar.gz vt100-rust-160942c40cbeb7503147c0895217644161fcc84b.zip |
remove current_cell/current_cell_mut
it had an unstated precondition that the cursor was not positioned off
the end of a row, which happened to be true in all existing uses, but
was hard to verify. moving the unwrap out to the call site makes it
easier to audit each use.
-rw-r--r-- | src/grid.rs | 14 | ||||
-rw-r--r-- | src/screen.rs | 7 |
2 files changed, 6 insertions, 15 deletions
diff --git a/src/grid.rs b/src/grid.rs index de98da1..085e744 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -171,16 +171,6 @@ impl Grid { .and_then(|r| r.get_mut(pos.col)) } - pub fn current_cell(&self) -> &crate::cell::Cell { - self.drawing_cell(self.pos) - .expect("cursor not pointing to a cell") - } - - pub fn current_cell_mut(&mut self) -> &mut crate::cell::Cell { - self.drawing_cell_mut(self.pos) - .expect("cursor not pointing to a cell") - } - pub fn scrollback_len(&self) -> usize { self.scrollback_len } @@ -458,8 +448,8 @@ impl Grid { pub fn insert_cells(&mut self, count: u16) { let size = self.size; let pos = self.pos; - let wide = - pos.col < size.cols && self.current_cell().is_wide_continuation(); + let wide = pos.col < size.cols + && self.drawing_cell(pos).unwrap().is_wide_continuation(); let row = self.current_row_mut(); for _ in 0..count { if wide { diff --git a/src/screen.rs b/src/screen.rs index 6c3d629..9e81ee2 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -906,12 +906,12 @@ impl Screen { next_cell.set(' ', attrs); } - let cell = self.grid_mut().current_cell_mut(); + let cell = self.grid_mut().drawing_cell_mut(pos).unwrap(); cell.set(c, attrs); self.grid_mut().col_inc(1); if width > 1 { let pos = self.grid().pos(); - if self.grid().current_cell().is_wide() { + if self.grid().drawing_cell(pos).unwrap().is_wide() { let next_next_pos = crate::grid::Pos { row: pos.row, col: pos.col + 1, @@ -928,7 +928,8 @@ impl Screen { .wrap(false); } } - let next_cell = self.grid_mut().current_cell_mut(); + let next_cell = + self.grid_mut().drawing_cell_mut(pos).unwrap(); next_cell.clear(crate::attrs::Attrs::default()); next_cell.set_wide_continuation(true); self.grid_mut().col_inc(1); |