From dc5efa534b80264f2e5a83ab60056c0834925aea Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 20 Nov 2019 06:06:36 -0500 Subject: handle wrapped cursors properly on output --- src/grid.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/grid.rs') diff --git a/src/grid.rs b/src/grid.rs index 80d44ba..8076a6c 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -212,7 +212,29 @@ impl Grid { wrapping = row.wrapped(); } - crate::term::MoveFromTo::new(prev_pos, self.pos).write_buf(contents); + // writing a character to the last column of a row doesn't wrap the + // cursor immediately - it waits until the next character is actually + // drawn. it is only possible for the cursor to have this kind of + // position after drawing a character though, so if we end in this + // position, we need to redraw the character at the end of the row. + if prev_pos != self.pos && self.pos.col >= self.size.cols { + let mut pos = Pos { + row: self.pos.row, + col: self.size.cols - 2, + }; + if !self.visible_cell(pos).unwrap().is_wide() { + pos = Pos { + row: self.pos.row, + col: self.size.cols - 1, + }; + } + crate::term::MoveFromTo::new(prev_pos, pos).write_buf(contents); + let cell = self.visible_cell(pos).unwrap(); + contents.extend(cell.contents().as_bytes()); + } else { + crate::term::MoveFromTo::new(prev_pos, self.pos) + .write_buf(contents); + } prev_attrs } @@ -244,7 +266,29 @@ impl Grid { wrapping = row.wrapped(); } - crate::term::MoveFromTo::new(prev_pos, self.pos).write_buf(contents); + // writing a character to the last column of a row doesn't wrap the + // cursor immediately - it waits until the next character is actually + // drawn. it is only possible for the cursor to have this kind of + // position after drawing a character though, so if we end in this + // position, we need to redraw the character at the end of the row. + if prev_pos != self.pos && self.pos.col >= self.size.cols { + let mut pos = Pos { + row: self.pos.row, + col: self.size.cols - 2, + }; + if !self.visible_cell(pos).unwrap().is_wide() { + pos = Pos { + row: self.pos.row, + col: self.size.cols - 1, + }; + } + crate::term::MoveFromTo::new(prev_pos, pos).write_buf(contents); + let cell = self.visible_cell(pos).unwrap(); + contents.extend(cell.contents().as_bytes()); + } else { + crate::term::MoveFromTo::new(prev_pos, self.pos) + .write_buf(contents); + } prev_attrs } -- cgit v1.2.3-54-g00ecf