aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-02 14:52:30 -0400
committerJesse Luehrs <doy@tozt.net>2019-11-02 14:52:30 -0400
commitbf8b298d125a29321947867a6f60ea133ebe3675 (patch)
tree87be517ccfe2d7db1b933fc676f145e768717f29
parent031e1936c74463f187d012238bcf6b187e3c1a1f (diff)
downloadvt100-rust-bf8b298d125a29321947867a6f60ea133ebe3675.tar.gz
vt100-rust-bf8b298d125a29321947867a6f60ea133ebe3675.zip
fix screen resizing
-rw-r--r--src/grid.rs11
-rw-r--r--src/screen.rs3
-rw-r--r--tests/basic.rs30
3 files changed, 43 insertions, 1 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 2842d02..1ebc539 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -27,6 +27,17 @@ impl Grid {
pub fn set_size(&mut self, size: Size) {
self.size = size;
+
+ if self.scroll_bottom >= size.rows {
+ self.scroll_bottom = size.rows - 1;
+ }
+ if self.scroll_bottom < self.scroll_top {
+ self.scroll_top = 0;
+ }
+
+ self.row_clamp_top(false);
+ self.row_clamp_bottom(false);
+ self.col_clamp();
}
pub fn pos(&self) -> &Pos {
diff --git a/src/screen.rs b/src/screen.rs
index df619a6..20c8de0 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -790,8 +790,9 @@ impl Screen {
}
pub fn set_window_size(&mut self, rows: u16, cols: u16) {
+ self.state.grid.set_size(crate::grid::Size { rows, cols });
self.state
- .grid_mut()
+ .alternate_grid
.set_size(crate::grid::Size { rows, cols });
}
diff --git a/tests/basic.rs b/tests/basic.rs
index 46d9265..0d97bb5 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -18,10 +18,40 @@ fn set_window_size() {
let mut screen = vt100::Screen::new(24, 80);
assert_eq!(screen.rows(), 24);
assert_eq!(screen.cols(), 80);
+ assert_eq!(screen.cursor_position(), (0, 0));
screen.set_window_size(34, 8);
assert_eq!(screen.rows(), 34);
assert_eq!(screen.cols(), 8);
+ assert_eq!(screen.cursor_position(), (0, 0));
+
+ screen.process(b"\x1b[30;5H");
+ assert_eq!(screen.cursor_position(), (29, 4));
+
+ screen.set_window_size(24, 80);
+ assert_eq!(screen.rows(), 24);
+ assert_eq!(screen.cols(), 80);
+ assert_eq!(screen.cursor_position(), (23, 4));
+
+ screen.set_window_size(34, 8);
+ assert_eq!(screen.rows(), 34);
+ assert_eq!(screen.cols(), 8);
+ assert_eq!(screen.cursor_position(), (23, 4));
+
+ screen.process(b"\x1b[?1049h");
+ assert_eq!(screen.rows(), 34);
+ assert_eq!(screen.cols(), 8);
+ assert_eq!(screen.cursor_position(), (0, 0));
+
+ screen.set_window_size(24, 80);
+ assert_eq!(screen.rows(), 24);
+ assert_eq!(screen.cols(), 80);
+ assert_eq!(screen.cursor_position(), (0, 0));
+
+ screen.process(b"\x1b[?1049l");
+ assert_eq!(screen.rows(), 24);
+ assert_eq!(screen.cols(), 80);
+ assert_eq!(screen.cursor_position(), (23, 4));
}
#[test]