aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-08 04:33:31 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-08 09:51:11 -0500
commit8a609443b4ae06e58e0334751bbdb76e31068d37 (patch)
tree23a4847c3f907e527f17aad199cd90ee1db9d189
parent76aeb85e99e088151c867d86858705bf38c345de (diff)
downloadvt100-rust-8a609443b4ae06e58e0334751bbdb76e31068d37.tar.gz
vt100-rust-8a609443b4ae06e58e0334751bbdb76e31068d37.zip
fix RI at the top of the screen
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/grid.rs9
-rw-r--r--tests/escape.rs6
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aecda1b..b428575 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@
* Clearing cells now correctly sets the cell background color.
* Fixed a couple bugs in wide character handling in `contents_formatted` and
`contents_diff`.
+* Fixed RI when the cursor is at the top of the screen (fixes scrolling up in
+ `less`, for instance).
## [0.3.1] - 2019-11-06
diff --git a/src/grid.rs b/src/grid.rs
index ad2fa22..3c262fe 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -337,9 +337,16 @@ impl Grid {
}
pub fn row_dec_scroll(&mut self, count: u16) {
+ // need to account for clamping by both row_clamp_top and by
+ // saturating_sub
+ let extra_lines = if count > self.pos.row {
+ count - self.pos.row
+ } else {
+ 0
+ };
self.pos.row = self.pos.row.saturating_sub(count);
let lines = self.row_clamp_top(true);
- self.scroll_down(lines);
+ self.scroll_down(lines + extra_lines);
}
pub fn row_set(&mut self, i: u16) {
diff --git a/tests/escape.rs b/tests/escape.rs
index 0ad92ed..88c926a 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -15,6 +15,12 @@ fn ri() {
let mut parser = vt100::Parser::new(24, 80);
parser.process(b"foo\nbar\x1bMbaz");
assert_eq!(parser.screen().contents(), "foo baz\n bar");
+
+ parser.process(b"\x1bc1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24");
+ assert_eq!(parser.screen().contents(), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24");
+
+ parser.process(b"\x1b[H\x1bM");
+ assert_eq!(parser.screen().contents(), "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23");
}
#[test]