diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-03 16:08:57 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-03 16:08:57 -0500 |
commit | 7958770a507d17e4beed17009206322c6d8fb7c0 (patch) | |
tree | 751d57929e56ec7d67c48b6c4f7a256de2f2dda1 | |
parent | 2f1eee8fcd050ac6e7411b700857e7c1db465d24 (diff) | |
download | vt100-rust-7958770a507d17e4beed17009206322c6d8fb7c0.tar.gz vt100-rust-7958770a507d17e4beed17009206322c6d8fb7c0.zip |
decsc should also save graphic rendition and origin mode
-rw-r--r-- | src/grid.rs | 8 | ||||
-rw-r--r-- | src/screen.rs | 16 | ||||
-rw-r--r-- | tests/escape.rs | 21 |
3 files changed, 41 insertions, 4 deletions
diff --git a/src/grid.rs b/src/grid.rs index 571918b..cfb04de 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -6,6 +6,7 @@ pub struct Grid { scroll_top: u16, scroll_bottom: u16, origin_mode: bool, + saved_origin_mode: bool, } impl Grid { @@ -18,6 +19,7 @@ impl Grid { scroll_top: 0, scroll_bottom: size.rows - 1, origin_mode: false, + saved_origin_mode: false, } } @@ -58,12 +60,14 @@ impl Grid { self.col_clamp(); } - pub fn save_pos(&mut self) { + pub fn save_cursor(&mut self) { self.saved_pos = self.pos; + self.saved_origin_mode = self.origin_mode; } - pub fn restore_pos(&mut self) { + pub fn restore_cursor(&mut self) { self.pos = self.saved_pos; + self.origin_mode = self.saved_origin_mode; } pub fn rows(&self) -> impl Iterator<Item = &crate::row::Row> { diff --git a/src/screen.rs b/src/screen.rs index bdcdcae..d40e9ea 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -53,6 +53,7 @@ struct State { alternate_grid: crate::grid::Grid, attrs: crate::attrs::Attrs, + saved_attrs: crate::attrs::Attrs, title: String, icon_name: String, @@ -70,6 +71,7 @@ impl State { alternate_grid: crate::grid::Grid::new(size), attrs: crate::attrs::Attrs::default(), + saved_attrs: crate::attrs::Attrs::default(), title: String::default(), icon_name: String::default(), @@ -128,6 +130,16 @@ impl State { self.clear_mode(Mode::AlternateScreen); } + fn save_cursor(&mut self) { + self.grid_mut().save_cursor(); + self.saved_attrs = self.attrs; + } + + fn restore_cursor(&mut self) { + self.grid_mut().restore_cursor(); + self.attrs = self.saved_attrs; + } + fn set_output(&mut self, output: Output) { self.outputs.insert(output); } @@ -263,12 +275,12 @@ impl State { // ESC 7 fn decsc(&mut self) { - self.grid_mut().save_pos(); + self.save_cursor(); } // ESC 8 fn decrc(&mut self) { - self.grid_mut().restore_pos(); + self.restore_cursor(); } // ESC = diff --git a/tests/escape.rs b/tests/escape.rs index 6793b5c..6c70aee 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -175,4 +175,25 @@ fn decsc() { screen.process(b"\x1b8"); assert_eq!(screen.cursor_position(), (0, 3)); + + screen.process(b"\x1bc\x1b[31m\x1b[5;15r\x1b[?6hfoo\x1b7"); + assert_eq!(screen.cursor_position(), (4, 3)); + assert_eq!( + screen.contents_formatted(0, 0, 23, 79), + "\n\n\n\n\x1b[31mfoo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + + screen.process(b"\x1b[32m\x1b[?6lbar"); + assert_eq!(screen.cursor_position(), (0, 3)); + assert_eq!( + screen.contents_formatted(0, 0, 23, 79), + "\x1b[32mbar\n\n\n\n\x1b[31mfoo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); + + screen.process(b"\x1b8\x1b[Hz"); + assert_eq!(screen.cursor_position(), (4, 1)); + assert_eq!( + screen.contents_formatted(0, 0, 23, 79), + "\x1b[32mbar\n\n\n\n\x1b[31mzoo\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + ); } |