diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-03 13:54:34 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-03 13:54:34 -0500 |
commit | 3fb01c1d74debdb4c8fd7395f7a2e0671dfac46b (patch) | |
tree | dacde910750bdbf072eecb9c4a6de1322f123235 | |
parent | 7a915a84819ef52561306c74ec813f57974265d2 (diff) | |
download | vt100-rust-3fb01c1d74debdb4c8fd7395f7a2e0671dfac46b.tar.gz vt100-rust-3fb01c1d74debdb4c8fd7395f7a2e0671dfac46b.zip |
clean up public api a bit
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/screen.rs | 88 | ||||
-rw-r--r-- | tests/basic.rs | 24 | ||||
-rw-r--r-- | tests/escape.rs | 52 | ||||
-rw-r--r-- | tests/init.rs | 18 | ||||
-rw-r--r-- | tests/mode.rs | 343 | ||||
-rw-r--r-- | tests/processing.rs | 76 |
7 files changed, 318 insertions, 285 deletions
@@ -12,4 +12,4 @@ mod unicode; pub use attrs::Color; pub use cell::Cell; -pub use screen::Screen; +pub use screen::{MouseProtocolMode, MouseProtocolEncoding, Screen}; diff --git a/src/screen.rs b/src/screen.rs index ad37ad1..be569b2 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -10,7 +10,7 @@ enum Output { #[derive(enumset::EnumSetType, Debug)] enum Mode { - KeypadApplication, + ApplicationKeypad, ApplicationCursor, HideCursor, AlternateScreen, @@ -18,7 +18,7 @@ enum Mode { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -enum MouseProtocolMode { +pub enum MouseProtocolMode { None, Press, PressRelease, @@ -35,7 +35,7 @@ impl Default for MouseProtocolMode { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -enum MouseProtocolEncoding { +pub enum MouseProtocolEncoding { Default, Utf8, Sgr, @@ -274,12 +274,12 @@ impl State { // ESC = fn deckpam(&mut self) { - self.set_mode(Mode::KeypadApplication); + self.set_mode(Mode::ApplicationKeypad); } // ESC > fn deckpnm(&mut self) { - self.clear_mode(Mode::KeypadApplication); + self.clear_mode(Mode::ApplicationKeypad); } // ESC M @@ -747,12 +747,10 @@ impl Screen { } } - pub fn rows(&self) -> u16 { - self.state.grid().size().rows - } - - pub fn cols(&self) -> u16 { - self.state.grid().size().cols + pub fn process(&mut self, bytes: &[u8]) { + for byte in bytes { + self.parser.advance(&mut self.state, *byte); + } } pub fn set_window_size(&mut self, rows: u16, cols: u16) { @@ -762,14 +760,9 @@ impl Screen { .set_size(crate::grid::Size { rows, cols }); } - pub fn process(&mut self, bytes: &[u8]) { - for byte in bytes { - self.parser.advance(&mut self.state, *byte); - } - } - - pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> { - self.state.cell(crate::grid::Pos { row, col }) + pub fn window_size(&self) -> (u16, u16) { + let size = self.state.grid().size(); + (size.rows, size.cols) } pub fn window_contents( @@ -796,8 +789,13 @@ impl Screen { .window_contents_formatted(row_start, col_start, row_end, col_end) } + pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> { + self.state.cell(crate::grid::Pos { row, col }) + } + pub fn cursor_position(&self) -> (u16, u16) { - (self.state.grid().pos().row, self.state.grid().pos().col) + let pos = self.state.grid().pos(); + (pos.row, pos.col) } pub fn fgcolor(&self) -> crate::attrs::Color { @@ -832,56 +830,40 @@ impl Screen { &self.state.icon_name } - pub fn hide_cursor(&self) -> bool { - self.state.mode(Mode::HideCursor) - } - - pub fn alternate_buffer_active(&self) -> bool { - self.state.mode(Mode::AlternateScreen) + pub fn check_audible_bell(&mut self) -> bool { + self.state.check_output(Output::AudibleBell) } - pub fn application_cursor(&self) -> bool { - self.state.mode(Mode::ApplicationCursor) + pub fn check_visual_bell(&mut self) -> bool { + self.state.check_output(Output::VisualBell) } pub fn application_keypad(&self) -> bool { - self.state.mode(Mode::KeypadApplication) - } - - pub fn bracketed_paste(&self) -> bool { - self.state.mode(Mode::BracketedPaste) - } - - pub fn mouse_reporting_press(&self) -> bool { - self.state.mouse_protocol_mode == MouseProtocolMode::Press - } - - pub fn mouse_reporting_press_release(&self) -> bool { - self.state.mouse_protocol_mode == MouseProtocolMode::PressRelease + self.state.mode(Mode::ApplicationKeypad) } - pub fn mouse_reporting_button_motion(&self) -> bool { - self.state.mouse_protocol_mode == MouseProtocolMode::ButtonMotion + pub fn application_cursor(&self) -> bool { + self.state.mode(Mode::ApplicationCursor) } - pub fn mouse_reporting_any_motion(&self) -> bool { - self.state.mouse_protocol_mode == MouseProtocolMode::AnyMotion + pub fn hide_cursor(&self) -> bool { + self.state.mode(Mode::HideCursor) } - pub fn mouse_reporting_utf8_mode(&self) -> bool { - self.state.mouse_protocol_encoding == MouseProtocolEncoding::Utf8 + pub fn alternate_screen(&self) -> bool { + self.state.mode(Mode::AlternateScreen) } - pub fn mouse_reporting_sgr_mode(&self) -> bool { - self.state.mouse_protocol_encoding == MouseProtocolEncoding::Sgr + pub fn bracketed_paste(&self) -> bool { + self.state.mode(Mode::BracketedPaste) } - pub fn check_audible_bell(&mut self) -> bool { - self.state.check_output(Output::AudibleBell) + pub fn mouse_protocol_mode(&self) -> MouseProtocolMode { + self.state.mouse_protocol_mode } - pub fn check_visual_bell(&mut self) -> bool { - self.state.check_output(Output::VisualBell) + pub fn mouse_protocol_encoding(&self) -> MouseProtocolEncoding { + self.state.mouse_protocol_encoding } } diff --git a/tests/basic.rs b/tests/basic.rs index 0d97bb5..071bdd3 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,8 +1,7 @@ #[test] fn object_creation() { let screen = vt100::Screen::new(24, 80); - assert_eq!(screen.rows(), 24); - assert_eq!(screen.cols(), 80); + assert_eq!(screen.window_size(), (24, 80)); } #[test] @@ -16,41 +15,34 @@ fn process_text() { #[test] 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.window_size(), (24, 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.window_size(), (34, 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.window_size(), (24, 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.window_size(), (34, 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.window_size(), (34, 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.window_size(), (24, 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.window_size(), (24, 80)); assert_eq!(screen.cursor_position(), (23, 4)); } diff --git a/tests/escape.rs b/tests/escape.rs index cf46241..999074c 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -48,16 +48,17 @@ fn ris() { assert!(!screen.underline()); assert!(!screen.inverse()); - assert!(!screen.hide_cursor()); + assert!(!screen.check_visual_bell()); + assert!(!screen.check_audible_bell()); assert!(!screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); - assert!(!screen.check_visual_bell()); - assert!(!screen.check_audible_bell()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"f\x1b[31m\x1b[47;1;3;4moo\x1b[7m\x1b[21;21H\x1b]2;window title\x07\x1b]1;window icon name\x07\x1b[?25l\x1b[?1h\x1b=\x1b[?9h\x1b[?1000h\x1b[?1006h\x1b[?2004h\x07\x1bg"); @@ -83,18 +84,20 @@ fn ris() { assert!(screen.underline()); assert!(screen.inverse()); - assert!(screen.hide_cursor()); + assert!(screen.check_visual_bell()); + assert!(screen.check_audible_bell()); assert!(screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(screen.mouse_reporting_sgr_mode()); - assert!(!screen.mouse_reporting_utf8_mode()); + assert!(screen.hide_cursor()); assert!(screen.bracketed_paste()); - assert!(screen.check_visual_bell()); - assert!(screen.check_audible_bell()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1bc"); assert_eq!(screen.cursor_position(), (0, 0)); @@ -123,18 +126,17 @@ fn ris() { assert!(!screen.underline()); assert!(!screen.inverse()); - assert!(!screen.hide_cursor()); + assert!(!screen.check_visual_bell()); + assert!(!screen.check_audible_bell()); assert!(!screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); - assert!(!screen.check_visual_bell()); - assert!(!screen.check_audible_bell()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); } #[test] diff --git a/tests/init.rs b/tests/init.rs index 4eb3910..ab56278 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -3,8 +3,7 @@ #[test] fn init() { let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.rows(), 24); - assert_eq!(screen.cols(), 80); + assert_eq!(screen.window_size(), (24, 80)); assert_eq!(screen.cursor_position(), (0, 0)); let cell = screen.cell(0, 0); @@ -36,14 +35,15 @@ fn init() { assert!(!screen.underline()); assert!(!screen.inverse()); - assert!(!screen.hide_cursor()); + assert!(!screen.check_visual_bell()); + assert!(!screen.check_audible_bell()); assert!(!screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); - assert!(!screen.check_visual_bell()); - assert!(!screen.check_audible_bell()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); } diff --git a/tests/mode.rs b/tests/mode.rs index d6807a9..2e10fee 100644 --- a/tests/mode.rs +++ b/tests/mode.rs @@ -3,276 +3,297 @@ #[test] fn modes() { let mut screen = vt100::Screen::new(24, 80); - assert!(!screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?1h"); - assert!(!screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?9h"); - assert!(!screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::Press + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?25l"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::Press + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?1000h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?1002h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::ButtonMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?1003h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?1005h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Utf8 + ); screen.process(b"\x1b[?1006h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?2004h"); - assert!(screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b="); - assert!(screen.hide_cursor()); assert!(screen.application_keypad()); assert!(screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1l"); - assert!(screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?9l"); - assert!(screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?25h"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1000l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1002l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::AnyMotion + ); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1003l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1005l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Sgr + ); screen.process(b"\x1b[?1006l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b[?2004l"); - assert!(!screen.hide_cursor()); assert!(screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); screen.process(b"\x1b>"); - assert!(!screen.hide_cursor()); assert!(!screen.application_keypad()); assert!(!screen.application_cursor()); - assert!(!screen.mouse_reporting_press()); - assert!(!screen.mouse_reporting_press_release()); - assert!(!screen.mouse_reporting_button_motion()); - assert!(!screen.mouse_reporting_any_motion()); - assert!(!screen.mouse_reporting_utf8_mode()); - assert!(!screen.mouse_reporting_sgr_mode()); + assert!(!screen.hide_cursor()); assert!(!screen.bracketed_paste()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert_eq!( + screen.mouse_protocol_encoding(), + vt100::MouseProtocolEncoding::Default + ); } #[test] @@ -287,12 +308,12 @@ fn alternate_buffer() { "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 0)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[m\x1b[2J\x1b[H1\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!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[?47h"); assert_eq!( @@ -300,7 +321,7 @@ fn alternate_buffer() { "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"foobar"); assert_eq!( @@ -308,12 +329,12 @@ fn alternate_buffer() { "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"\x1b[?47l"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[?47h"); assert_eq!( @@ -321,12 +342,12 @@ fn alternate_buffer() { "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"\x1b[?47l"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); // 1049 @@ -336,12 +357,12 @@ fn alternate_buffer() { "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 0)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[m\x1b[2J\x1b[H1\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!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[?1049h"); assert_eq!( @@ -349,7 +370,7 @@ fn alternate_buffer() { "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"foobar"); assert_eq!( @@ -357,12 +378,12 @@ fn alternate_buffer() { "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"\x1b[?1049l"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); screen.process(b"\x1b[?1049h"); assert_eq!( @@ -370,10 +391,10 @@ fn alternate_buffer() { "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" ); assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_buffer_active()); + assert!(screen.alternate_screen()); screen.process(b"\x1b[?1049l"); assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n"); assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_buffer_active()); + assert!(!screen.alternate_screen()); } diff --git a/tests/processing.rs b/tests/processing.rs index b5b212a..7ee651e 100644 --- a/tests/processing.rs +++ b/tests/processing.rs @@ -39,94 +39,130 @@ fn split_escape_sequences() { assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); screen.process(b"\x1b"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"["); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"?"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"1"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"0"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"0"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"0"); - assert!(!screen.mouse_reporting_press_release()); + assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"h"); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); assert_eq!(screen.title(), ""); screen.process(b"\x1b"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"]"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"0"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b";"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"a"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b" "); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"'"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"["); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"]"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"_"); assert_eq!(screen.title(), ""); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); screen.process(b"\x07"); assert_eq!(screen.title(), "a '[]_"); - assert!(screen.mouse_reporting_press_release()); + assert_eq!( + screen.mouse_protocol_mode(), + vt100::MouseProtocolMode::PressRelease + ); assert_eq!(screen.cursor_position(), (11, 23)); assert_eq!(screen.window_contents(0, 0, 23, 79), contents); } |