From 160942c40cbeb7503147c0895217644161fcc84b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 14 Dec 2021 03:19:49 -0500 Subject: 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. --- src/grid.rs | 14 ++------------ 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); -- cgit v1.2.3-54-g00ecf