aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-20 06:06:36 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-20 06:06:36 -0500
commitdc5efa534b80264f2e5a83ab60056c0834925aea (patch)
tree731bc6f7ae722f0f3247f7188364f5e909563598
parent87dc3babbd086d6507942a32b09d8b1e654776ad (diff)
downloadvt100-rust-dc5efa534b80264f2e5a83ab60056c0834925aea.tar.gz
vt100-rust-dc5efa534b80264f2e5a83ab60056c0834925aea.zip
handle wrapped cursors properly on output
-rw-r--r--src/grid.rs48
-rw-r--r--tests/text.rs15
2 files changed, 61 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
}
diff --git a/tests/text.rs b/tests/text.rs
index cf90b89..a962741 100644
--- a/tests/text.rs
+++ b/tests/text.rs
@@ -221,3 +221,18 @@ fn wrap() {
assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "");
}
+
+#[test]
+fn wrap_weird() {
+ let mut parser = vt100::Parser::default();
+
+ let screen = parser.screen().clone();
+ parser.process(b"foo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo");
+ assert_eq!(parser.screen().contents_formatted(), &b"\x1b[?25h\x1b[m\x1b[H\x1b[Jfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo"[..]);
+ assert_eq!(parser.screen().contents_diff(&screen), &b"foo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo"[..]);
+
+ let screen = parser.screen().clone();
+ parser.process(b"\x1b[3;80H ");
+ assert_eq!(parser.screen().contents_formatted(), &b"\x1b[?25h\x1b[m\x1b[H\x1b[Jfoo\r\nfoo\r\nfoo\x1b[76C \r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\r\nfoo\x1b[3;80H "[..]);
+ assert_eq!(parser.screen().contents_diff(&screen), &b"\x1b[3;80H "[..]);
+}