diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-20 06:06:36 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-20 06:06:36 -0500 |
commit | dc5efa534b80264f2e5a83ab60056c0834925aea (patch) | |
tree | 731bc6f7ae722f0f3247f7188364f5e909563598 /src | |
parent | 87dc3babbd086d6507942a32b09d8b1e654776ad (diff) | |
download | vt100-rust-dc5efa534b80264f2e5a83ab60056c0834925aea.tar.gz vt100-rust-dc5efa534b80264f2e5a83ab60056c0834925aea.zip |
handle wrapped cursors properly on output
Diffstat (limited to 'src')
-rw-r--r-- | src/grid.rs | 48 |
1 files changed, 46 insertions, 2 deletions
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 } |