diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
commit | 4b4a9c18e4c55a2ba6558ef614292db9c18ab88a (patch) | |
tree | 03c9ada690835acbf3d1b02f46341bde5b579989 | |
parent | 59e7c620a516278719c1689ebebeb558bede5b60 (diff) | |
download | vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.tar.gz vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.zip |
expose the screen separately from the parser
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/parser.rs | 33 | ||||
-rw-r--r-- | src/screen.rs | 374 | ||||
-rw-r--r-- | tests/attr.rs | 367 | ||||
-rw-r--r-- | tests/basic.rs | 104 | ||||
-rw-r--r-- | tests/control.rs | 122 | ||||
-rw-r--r-- | tests/csi.rs | 393 | ||||
-rw-r--r-- | tests/escape.rs | 209 | ||||
-rw-r--r-- | tests/init.rs | 53 | ||||
-rw-r--r-- | tests/mode.rs | 455 | ||||
-rw-r--r-- | tests/osc.rs | 62 | ||||
-rw-r--r-- | tests/processing.rs | 320 | ||||
-rw-r--r-- | tests/scroll.rs | 82 | ||||
-rw-r--r-- | tests/split-escapes.rs | 14 | ||||
-rw-r--r-- | tests/text.rs | 412 | ||||
-rw-r--r-- | tests/weird.rs | 20 | ||||
-rw-r--r-- | tests/window_contents.rs | 89 |
17 files changed, 1630 insertions, 1485 deletions
@@ -12,8 +12,8 @@ //! # Synopsis //! //! ``` -//! let mut screen = vt100::Screen::new(24, 80); -//! screen.process(b"this text is \x1b[31mRED\x1b[m"); +//! let mut parser = vt100::Parser::new(24, 80); +//! parser.process(b"this text is \x1b[31mRED\x1b[m"); //! ``` // XXX this is broken with ale @@ -26,10 +26,12 @@ mod attrs; mod cell; mod grid; +mod parser; mod row; mod screen; mod unicode; pub use attrs::Color; pub use cell::Cell; +pub use parser::Parser; pub use screen::{MouseProtocolEncoding, MouseProtocolMode, Screen}; diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..2e27399 --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,33 @@ +pub struct Parser { + parser: vte::Parser, + screen: crate::screen::Screen, +} + +impl Parser { + /// Creates a new terminal parser of the given size. + pub fn new(rows: u16, cols: u16) -> Self { + Self { + parser: vte::Parser::new(), + screen: crate::screen::Screen::new(crate::grid::Size { + rows, + cols, + }), + } + } + + /// Processes the contents of the given byte string, and updates the + /// in-memory terminal state. + pub fn process(&mut self, bytes: &[u8]) { + for byte in bytes { + self.parser.advance(&mut self.screen, *byte); + } + } + + pub fn screen(&self) -> &crate::screen::Screen { + &self.screen + } + + pub fn screen_mut(&mut self) -> &mut crate::screen::Screen { + &mut self.screen + } +} diff --git a/src/screen.rs b/src/screen.rs index c630ecf..6a4a399 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -69,7 +69,7 @@ impl Default for MouseProtocolEncoding { } } -struct State { +pub struct Screen { grid: crate::grid::Grid, alternate_grid: crate::grid::Grid, @@ -85,8 +85,8 @@ struct State { mouse_protocol_encoding: MouseProtocolEncoding, } -impl State { - fn new(size: crate::grid::Size) -> Self { +impl Screen { + pub(crate) fn new(size: crate::grid::Size) -> Self { Self { grid: crate::grid::Grid::new(size), alternate_grid: crate::grid::Grid::new(size), @@ -104,6 +104,172 @@ impl State { } } + /// Resizes the terminal. + pub fn set_size(&mut self, rows: u16, cols: u16) { + self.grid.set_size(crate::grid::Size { rows, cols }); + self.alternate_grid + .set_size(crate::grid::Size { rows, cols }); + } + + /// Returns the current size of the terminal. + /// + /// The return value will be (rows, cols). + pub fn size(&self) -> (u16, u16) { + let size = self.grid().size(); + (size.rows, size.cols) + } + + /// Returns the text contents of the subset of the terminal given by the + /// parameters. + /// + /// This will not include any formatting information, and will be in plain + /// text format. + pub fn contents( + &self, + row_start: u16, + col_start: u16, + row_end: u16, + col_end: u16, + ) -> String { + self.grid().contents(row_start, col_start, row_end, col_end) + } + + /// Returns the formatted contents of the subset of the terminal given by + /// the parameters. + /// + /// Formatting information will be included inline as terminal escape + /// codes. The result will be suitable for feeding directly to a raw + /// terminal parser, and will result in the same visual output. Internal + /// terminal modes (such as application keypad mode or alternate screen + /// mode) will not be included here. + pub fn contents_formatted( + &self, + row_start: u16, + col_start: u16, + row_end: u16, + col_end: u16, + ) -> String { + self.grid() + .contents_formatted(row_start, col_start, row_end, col_end) + } + + /// Returns the `Cell` object at the given location in the terminal, if it + /// exists. + pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> { + self.grid().cell(crate::grid::Pos { row, col }) + } + + /// Returns the current cursor position of the terminal. + /// + /// The return value will be (row, col). + pub fn cursor_position(&self) -> (u16, u16) { + let pos = self.grid().pos(); + (pos.row, pos.col) + } + + /// Returns the currently active foreground color. + /// + /// This is the foreground color which will be used when writing text to a + /// new cell. + pub fn fgcolor(&self) -> crate::attrs::Color { + self.attrs.fgcolor + } + + /// Returns the currently active background color. + /// + /// This is the background color which will be used when writing text to a + /// new cell. + pub fn bgcolor(&self) -> crate::attrs::Color { + self.attrs.bgcolor + } + + /// Returns whether the bold text attribute is active. + /// + /// If true, text written to a new cell will have the bold text attribute. + pub fn bold(&self) -> bool { + self.attrs.bold() + } + + /// Returns whether the italic text attribute is active. + /// + /// If true, text written to a new cell will have the italic text attribute. + pub fn italic(&self) -> bool { + self.attrs.italic() + } + + /// Returns whether the underline text attribute is active. + /// + /// If true, text written to a new cell will have the underline text + /// attribute. + pub fn underline(&self) -> bool { + self.attrs.underline() + } + + /// Returns whether the inverse text attribute is active. + /// + /// If true, text written to a new cell will have the inverse text + /// attribute. + pub fn inverse(&self) -> bool { + self.attrs.inverse() + } + + /// Returns the terminal's window title. + pub fn title(&self) -> &str { + &self.title + } + + /// Returns the terminal's icon name. + pub fn icon_name(&self) -> &str { + &self.icon_name + } + + /// Returns whether an audible bell has occurred since the last time this + /// method was called. + pub fn check_audible_bell(&mut self) -> bool { + self.check_output(Output::AudibleBell) + } + + /// Returns whether an visual bell has occurred since the last time this + /// method was called. + pub fn check_visual_bell(&mut self) -> bool { + self.check_output(Output::VisualBell) + } + + /// Returns whether the terminal should be in application keypad mode. + pub fn application_keypad(&self) -> bool { + self.mode(Mode::ApplicationKeypad) + } + + /// Returns whether the terminal should be in application cursor mode. + pub fn application_cursor(&self) -> bool { + self.mode(Mode::ApplicationCursor) + } + + /// Returns whether the terminal should be in hide cursor mode. + pub fn hide_cursor(&self) -> bool { + self.mode(Mode::HideCursor) + } + + /// Returns whether the terminal should be in alternate screen mode. + pub fn alternate_screen(&self) -> bool { + self.mode(Mode::AlternateScreen) + } + + /// Returns whether the terminal should be in bracketed paste mode. + pub fn bracketed_paste(&self) -> bool { + self.mode(Mode::BracketedPaste) + } + + /// Returns the currently active `MouseProtocolMode` + pub fn mouse_protocol_mode(&self) -> MouseProtocolMode { + self.mouse_protocol_mode + } + + /// Returns the currently active `MouseProtocolEncoding` + pub fn mouse_protocol_encoding(&self) -> MouseProtocolEncoding { + self.mouse_protocol_encoding + } + fn grid(&self) -> &crate::grid::Grid { if self.mode(Mode::AlternateScreen) { &self.alternate_grid @@ -124,10 +290,6 @@ impl State { self.grid().row(pos) } - fn cell(&self, pos: crate::grid::Pos) -> Option<&crate::cell::Cell> { - self.grid().cell(pos) - } - fn cell_mut( &mut self, pos: crate::grid::Pos, @@ -204,7 +366,7 @@ impl State { } } -impl State { +impl Screen { fn text(&mut self, c: char) { let pos = self.grid().pos(); if pos.col > 0 { @@ -614,7 +776,7 @@ impl State { } } -impl vte::Perform for State { +impl vte::Perform for Screen { fn print(&mut self, c: char) { self.text(c) } @@ -765,200 +927,6 @@ impl vte::Perform for State { fn unhook(&mut self) {} } -/// Represents a terminal screen. -pub struct Screen { - parser: vte::Parser, - state: State, -} - -impl Screen { - /// Creates a new terminal screen of the given size. - pub fn new(rows: u16, cols: u16) -> Self { - Self { - parser: vte::Parser::new(), - state: State::new(crate::grid::Size { rows, cols }), - } - } - - /// Processes the contents of the given byte string, and updates the - /// in-memory terminal state. - pub fn process(&mut self, bytes: &[u8]) { - for byte in bytes { - self.parser.advance(&mut self.state, *byte); - } - } - - /// Resizes the terminal. - pub fn set_size(&mut self, rows: u16, cols: u16) { - self.state.grid.set_size(crate::grid::Size { rows, cols }); - self.state - .alternate_grid - .set_size(crate::grid::Size { rows, cols }); - } - - /// Returns the current size of the terminal. - /// - /// The return value will be (rows, cols). - pub fn size(&self) -> (u16, u16) { - let size = self.state.grid().size(); - (size.rows, size.cols) - } - - /// Returns the text contents of the subset of the terminal given by the - /// parameters. - /// - /// This will not include any formatting information, and will be in plain - /// text format. - pub fn contents( - &self, - row_start: u16, - col_start: u16, - row_end: u16, - col_end: u16, - ) -> String { - self.state - .grid() - .contents(row_start, col_start, row_end, col_end) - } - - /// Returns the formatted contents of the subset of the terminal given by - /// the parameters. - /// - /// Formatting information will be included inline as terminal escape - /// codes. The result will be suitable for feeding directly to a raw - /// terminal parser, and will result in the same visual output. Internal - /// terminal modes (such as application keypad mode or alternate screen - /// mode) will not be included here. - pub fn contents_formatted( - &self, - row_start: u16, - col_start: u16, - row_end: u16, - col_end: u16, - ) -> String { - self.state - .grid() - .contents_formatted(row_start, col_start, row_end, col_end) - } - - /// Returns the `Cell` object at the given location in the terminal, if it - /// exists. - pub fn cell(&self, row: u16, col: u16) -> Option<&crate::cell::Cell> { - self.state.cell(crate::grid::Pos { row, col }) - } - - /// Returns the current cursor position of the terminal. - /// - /// The return value will be (row, col). - pub fn cursor_position(&self) -> (u16, u16) { - let pos = self.state.grid().pos(); - (pos.row, pos.col) - } - - /// Returns the currently active foreground color. - /// - /// This is the foreground color which will be used when writing text to a - /// new cell. - pub fn fgcolor(&self) -> crate::attrs::Color { - self.state.attrs.fgcolor - } - - /// Returns the currently active background color. - /// - /// This is the background color which will be used when writing text to a - /// new cell. - pub fn bgcolor(&self) -> crate::attrs::Color { - self.state.attrs.bgcolor - } - - /// Returns whether the bold text attribute is active. - /// - /// If true, text written to a new cell will have the bold text attribute. - pub fn bold(&self) -> bool { - self.state.attrs.bold() - } - - /// Returns whether the italic text attribute is active. - /// - /// If true, text written to a new cell will have the italic text attribute. - pub fn italic(&self) -> bool { - self.state.attrs.italic() - } - - /// Returns whether the underline text attribute is active. - /// - /// If true, text written to a new cell will have the underline text - /// attribute. - pub fn underline(&self) -> bool { - self.state.attrs.underline() - } - - /// Returns whether the inverse text attribute is active. - /// - /// If true, text written to a new cell will have the inverse text - /// attribute. - pub fn inverse(&self) -> bool { - self.state.attrs.inverse() - } - - /// Returns the terminal's window title. - pub fn title(&self) -> &str { - &self.state.title - } - - /// Returns the terminal's icon name. - pub fn icon_name(&self) -> &str { - &self.state.icon_name - } - - /// Returns whether an audible bell has occurred since the last time this - /// method was called. - pub fn check_audible_bell(&mut self) -> bool { - self.state.check_output(Output::AudibleBell) - } - - /// Returns whether an visual bell has occurred since the last time this - /// method was called. - pub fn check_visual_bell(&mut self) -> bool { - self.state.check_output(Output::VisualBell) - } - - /// Returns whether the terminal should be in application keypad mode. - pub fn application_keypad(&self) -> bool { - self.state.mode(Mode::ApplicationKeypad) - } - - /// Returns whether the terminal should be in application cursor mode. - pub fn application_cursor(&self) -> bool { - self.state.mode(Mode::ApplicationCursor) - } - - /// Returns whether the terminal should be in hide cursor mode. - pub fn hide_cursor(&self) -> bool { - self.state.mode(Mode::HideCursor) - } - - /// Returns whether the terminal should be in alternate screen mode. - pub fn alternate_screen(&self) -> bool { - self.state.mode(Mode::AlternateScreen) - } - - /// Returns whether the terminal should be in bracketed paste mode. - pub fn bracketed_paste(&self) -> bool { - self.state.mode(Mode::BracketedPaste) - } - - /// Returns the currently active `MouseProtocolMode` - pub fn mouse_protocol_mode(&self) -> MouseProtocolMode { - self.state.mouse_protocol_mode - } - - /// Returns the currently active `MouseProtocolEncoding` - pub fn mouse_protocol_encoding(&self) -> MouseProtocolEncoding { - self.state.mouse_protocol_encoding - } -} - fn canonicalize_params_1(params: &[i64], default: u16) -> u16 { let first = params.get(0).copied().unwrap_or(0); if first == 0 { diff --git a/tests/attr.rs b/tests/attr.rs index 2cc94ba..18d20a2 100644 --- a/tests/attr.rs +++ b/tests/attr.rs @@ -2,215 +2,284 @@ #[test] fn colors() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - screen.process(b"foo\x1b[31mbar"); + parser.process(b"foo\x1b[31mbar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!( + parser.screen().cell(0, 0).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 0).unwrap().bgcolor(), + vt100::Color::Default + ); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 3).unwrap().fgcolor(), vt100::Color::Idx(1)); - assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "b"); + assert_eq!( + parser.screen().cell(0, 3).unwrap().fgcolor(), + vt100::Color::Idx(1) + ); + assert_eq!( + parser.screen().cell(0, 3).unwrap().bgcolor(), + vt100::Color::Default + ); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(1)); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(1)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - screen.process(b"\x1b[2D\x1b[45mab"); + parser.process(b"\x1b[2D\x1b[45mab"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 4).unwrap().fgcolor(), vt100::Color::Idx(1)); - assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::Idx(5)); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "a"); + assert_eq!( + parser.screen().cell(0, 4).unwrap().fgcolor(), + vt100::Color::Idx(1) + ); + assert_eq!( + parser.screen().cell(0, 4).unwrap().bgcolor(), + vt100::Color::Idx(5) + ); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(1)); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(5)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(1)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(5)); - screen.process(b"\x1b[m"); + parser.process(b"\x1b[m"); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - screen.process(b"\x1b[15;15Hfoo\x1b[31mbar\x1b[m"); + parser.process(b"\x1b[15;15Hfoo\x1b[31mbar\x1b[m"); - assert_eq!(screen.cell(14, 14).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(14, 14).unwrap().contents(), "f"); assert_eq!( - screen.cell(14, 14).unwrap().fgcolor(), + parser.screen().cell(14, 14).unwrap().fgcolor(), vt100::Color::Default ); assert_eq!( - screen.cell(14, 14).unwrap().bgcolor(), + parser.screen().cell(14, 14).unwrap().bgcolor(), vt100::Color::Default ); - assert_eq!(screen.cell(14, 17).unwrap().contents(), "b"); - assert_eq!(screen.cell(14, 17).unwrap().fgcolor(), vt100::Color::Idx(1)); + assert_eq!(parser.screen().cell(14, 17).unwrap().contents(), "b"); + assert_eq!( + parser.screen().cell(14, 17).unwrap().fgcolor(), + vt100::Color::Idx(1) + ); assert_eq!( - screen.cell(14, 17).unwrap().bgcolor(), + parser.screen().cell(14, 17).unwrap().bgcolor(), vt100::Color::Default ); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - screen.process(b"\x1b[2D\x1b[45mab"); + parser.process(b"\x1b[2D\x1b[45mab"); - assert_eq!(screen.cell(14, 18).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(14, 18).unwrap().contents(), "a"); assert_eq!( - screen.cell(14, 18).unwrap().fgcolor(), + parser.screen().cell(14, 18).unwrap().fgcolor(), vt100::Color::Default ); - assert_eq!(screen.cell(14, 18).unwrap().bgcolor(), vt100::Color::Idx(5)); + assert_eq!( + parser.screen().cell(14, 18).unwrap().bgcolor(), + vt100::Color::Idx(5) + ); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(5)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(5)); - screen.process(b"\x1b[m\x1b[2J\x1b[H"); - screen.process(b"a\x1b[38;5;123mb\x1b[48;5;158mc"); + parser.process(b"\x1b[m\x1b[2J\x1b[H"); + parser.process(b"a\x1b[38;5;123mb\x1b[48;5;158mc"); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(123)); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(158)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(123)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(158)); - assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 0).unwrap().bgcolor(), vt100::Color::Default); + assert_eq!( + parser.screen().cell(0, 0).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 0).unwrap().bgcolor(), + vt100::Color::Default + ); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::Idx(123)); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Default); + assert_eq!( + parser.screen().cell(0, 1).unwrap().fgcolor(), + vt100::Color::Idx(123) + ); + assert_eq!( + parser.screen().cell(0, 1).unwrap().bgcolor(), + vt100::Color::Default + ); - assert_eq!(screen.cell(0, 2).unwrap().fgcolor(), vt100::Color::Idx(123)); - assert_eq!(screen.cell(0, 2).unwrap().bgcolor(), vt100::Color::Idx(158)); + assert_eq!( + parser.screen().cell(0, 2).unwrap().fgcolor(), + vt100::Color::Idx(123) + ); + assert_eq!( + parser.screen().cell(0, 2).unwrap().bgcolor(), + vt100::Color::Idx(158) + ); - screen.process(b"\x1b[38;2;50;75;100md\x1b[48;2;125;150;175me"); + parser.process(b"\x1b[38;2;50;75;100md\x1b[48;2;125;150;175me"); - assert_eq!(screen.fgcolor(), vt100::Color::Rgb(50, 75, 100)); - assert_eq!(screen.bgcolor(), vt100::Color::Rgb(125, 150, 175)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Rgb(50, 75, 100)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Rgb(125, 150, 175)); assert_eq!( - screen.cell(0, 3).unwrap().fgcolor(), + parser.screen().cell(0, 3).unwrap().fgcolor(), vt100::Color::Rgb(50, 75, 100) ); - assert_eq!(screen.cell(0, 3).unwrap().bgcolor(), vt100::Color::Idx(158)); + assert_eq!( + parser.screen().cell(0, 3).unwrap().bgcolor(), + vt100::Color::Idx(158) + ); assert_eq!( - screen.cell(0, 4).unwrap().fgcolor(), + parser.screen().cell(0, 4).unwrap().fgcolor(), vt100::Color::Rgb(50, 75, 100) ); assert_eq!( - screen.cell(0, 4).unwrap().bgcolor(), + parser.screen().cell(0, 4).unwrap().bgcolor(), vt100::Color::Rgb(125, 150, 175) ); - screen.process(b"\x1b[m\x1b[2J\x1b[H"); - screen.process(b"\x1b[32;47mfoo"); + parser.process(b"\x1b[m\x1b[2J\x1b[H"); + parser.process(b"\x1b[32;47mfoo"); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(2)); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(7)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(2)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(7)); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::Idx(2)); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Idx(7)); + assert_eq!( + parser.screen().cell(0, 1).unwrap().fgcolor(), + vt100::Color::Idx(2) + ); + assert_eq!( + parser.screen().cell(0, 1).unwrap().bgcolor(), + vt100::Color::Idx(7) + ); - screen.process(b"\x1b[2J\x1b[H"); - screen.process(b"\x1b[39mfoo"); + parser.process(b"\x1b[2J\x1b[H"); + parser.process(b"\x1b[39mfoo"); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(7)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(7)); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Idx(7)); + assert_eq!( + parser.screen().cell(0, 1).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 1).unwrap().bgcolor(), + vt100::Color::Idx(7) + ); - screen.process(b"\x1b[2J\x1b[H"); - screen.process(b"\x1b[49mfoo"); + parser.process(b"\x1b[2J\x1b[H"); + parser.process(b"\x1b[49mfoo"); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Default); + assert_eq!( + parser.screen().cell(0, 1).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 1).unwrap().bgcolor(), + vt100::Color::Default + ); - screen.process(b"\x1b[m\x1b[2J\x1b[H"); - screen.process(b"\x1b[92;107mfoo"); + parser.process(b"\x1b[m\x1b[2J\x1b[H"); + parser.process(b"\x1b[92;107mfoo"); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(10)); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(15)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(10)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(15)); - assert_eq!(screen.cell(0, 1).unwrap().fgcolor(), vt100::Color::Idx(10)); - assert_eq!(screen.cell(0, 1).unwrap().bgcolor(), vt100::Color::Idx(15)); + assert_eq!( + parser.screen().cell(0, 1).unwrap().fgcolor(), + vt100::Color::Idx(10) + ); + assert_eq!( + parser.screen().cell(0, 1).unwrap().bgcolor(), + vt100::Color::Idx(15) + ); } #[test] fn attrs() { - let mut screen = vt100::Screen::new(24, 80); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); - - screen.process(b"f\x1b[1mo\x1b[3mo\x1b[4mo\x1b[7mo"); - assert!(screen.bold()); - assert!(screen.italic()); - assert!(screen.underline()); - assert!(screen.inverse()); - assert!(!screen.cell(0, 0).unwrap().bold()); - assert!(!screen.cell(0, 0).unwrap().italic()); - assert!(!screen.cell(0, 0).unwrap().underline()); - assert!(!screen.cell(0, 0).unwrap().inverse()); - assert!(screen.cell(0, 1).unwrap().bold()); - assert!(!screen.cell(0, 1).unwrap().italic()); - assert!(!screen.cell(0, 1).unwrap().underline()); - assert!(!screen.cell(0, 1).unwrap().inverse()); - assert!(screen.cell(0, 2).unwrap().bold()); - assert!(screen.cell(0, 2).unwrap().italic()); - assert!(!screen.cell(0, 2).unwrap().underline()); - assert!(!screen.cell(0, 2).unwrap().inverse()); - assert!(screen.cell(0, 3).unwrap().bold()); - assert!(screen.cell(0, 3).unwrap().italic()); - assert!(screen.cell(0, 3).unwrap().underline()); - assert!(!screen.cell(0, 3).unwrap().inverse()); - assert!(screen.cell(0, 4).unwrap().bold()); - assert!(screen.cell(0, 4).unwrap().italic()); - assert!(screen.cell(0, 4).unwrap().underline()); - assert!(screen.cell(0, 4).unwrap().inverse()); - - screen.process(b"\x1b[m"); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); - - screen.process(b"\x1b[2J\x1b[H"); - screen.process(b"\x1b[1;4mf"); - assert!(screen.bold()); - assert!(!screen.italic()); - assert!(screen.underline()); - assert!(!screen.inverse()); - assert!(screen.cell(0, 0).unwrap().bold()); - assert!(!screen.cell(0, 0).unwrap().italic()); - assert!(screen.cell(0, 0).unwrap().underline()); - assert!(!screen.cell(0, 0).unwrap().inverse()); - - screen.process(b"\x1b[22mo\x1b[24mo"); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); - assert!(!screen.cell(0, 1).unwrap().bold()); - assert!(!screen.cell(0, 1).unwrap().italic()); - assert!(screen.cell(0, 1).unwrap().underline()); - assert!(!screen.cell(0, 1).unwrap().inverse()); - assert!(!screen.cell(0, 2).unwrap().bold()); - assert!(!screen.cell(0, 2).unwrap().italic()); - assert!(!screen.cell(0, 2).unwrap().underline()); - assert!(!screen.cell(0, 2).unwrap().inverse()); - - screen.process(b"\x1b[1;3;4;7mo"); - assert!(screen.bold()); - assert!(screen.italic()); - assert!(screen.underline()); - assert!(screen.inverse()); - assert!(screen.cell(0, 3).unwrap().bold()); - assert!(screen.cell(0, 3).unwrap().italic()); - assert!(screen.cell(0, 3).unwrap().underline()); - assert!(screen.cell(0, 3).unwrap().inverse()); + let mut parser = vt100::Parser::new(24, 80); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); + + parser.process(b"f\x1b[1mo\x1b[3mo\x1b[4mo\x1b[7mo"); + assert!(parser.screen().bold()); + assert!(parser.screen().italic()); + assert!(parser.screen().underline()); + assert!(parser.screen().inverse()); + assert!(!parser.screen().cell(0, 0).unwrap().bold()); + assert!(!parser.screen().cell(0, 0).unwrap().italic()); + assert!(!parser.screen().cell(0, 0).unwrap().underline()); + assert!(!parser.screen().cell(0, 0).unwrap().inverse()); + assert!(parser.screen().cell(0, 1).unwrap().bold()); + assert!(!parser.screen().cell(0, 1).unwrap().italic()); + assert!(!parser.screen().cell(0, 1).unwrap().underline()); + assert!(!parser.screen().cell(0, 1).unwrap().inverse()); + assert!(parser.screen().cell(0, 2).unwrap().bold()); + assert!(parser.screen().cell(0, 2).unwrap().italic()); + assert!(!parser.screen().cell(0, 2).unwrap().underline()); + assert!(!parser.screen().cell(0, 2).unwrap().inverse()); + assert!(parser.screen().cell(0, 3).unwrap().bold()); + assert!(parser.screen().cell(0, 3).unwrap().italic()); + assert!(parser.screen().cell(0, 3).unwrap().underline()); + assert!(!parser.screen().cell(0, 3).unwrap().inverse()); + assert!(parser.screen().cell(0, 4).unwrap().bold()); + assert!(parser.screen().cell(0, 4).unwrap().italic()); + assert!(parser.screen().cell(0, 4).unwrap().underline()); + assert!(parser.screen().cell(0, 4).unwrap().inverse()); + + parser.process(b"\x1b[m"); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); + + parser.process(b"\x1b[2J\x1b[H"); + parser.process(b"\x1b[1;4mf"); + assert!(parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(parser.screen().underline()); + assert!(!parser.screen().inverse()); + assert!(parser.screen().cell(0, 0).unwrap().bold()); + assert!(!parser.screen().cell(0, 0).unwrap().italic()); + assert!(parser.screen().cell(0, 0).unwrap().underline()); + assert!(!parser.screen().cell(0, 0).unwrap().inverse()); + + parser.process(b"\x1b[22mo\x1b[24mo"); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); + assert!(!parser.screen().cell(0, 1).unwrap().bold()); + assert!(!parser.screen().cell(0, 1).unwrap().italic()); + assert!(parser.screen().cell(0, 1).unwrap().underline()); + assert!(!parser.screen().cell(0, 1).unwrap().inverse()); + assert!(!parser.screen().cell(0, 2).unwrap().bold()); + assert!(!parser.screen().cell(0, 2).unwrap().italic()); + assert!(!parser.screen().cell(0, 2).unwrap().underline()); + assert!(!parser.screen().cell(0, 2).unwrap().inverse()); + + parser.process(b"\x1b[1;3;4;7mo"); + assert!(parser.screen().bold()); + assert!(parser.screen().italic()); + assert!(parser.screen().underline()); + assert!(parser.screen().inverse()); + assert!(parser.screen().cell(0, 3).unwrap().bold()); + assert!(parser.screen().cell(0, 3).unwrap().italic()); + assert!(parser.screen().cell(0, 3).unwrap().underline()); + assert!(parser.screen().cell(0, 3).unwrap().inverse()); } diff --git a/tests/basic.rs b/tests/basic.rs index f26e175..afb090a 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,82 +1,94 @@ #[test] fn object_creation() { - let screen = vt100::Screen::new(24, 80); - assert_eq!(screen.size(), (24, 80)); + let parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().size(), (24, 80)); } #[test] fn process_text() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; - screen.process(input); - assert_eq!(screen.contents(0, 0, 0, 50), "foobar"); + parser.process(input); + assert_eq!(parser.screen().contents(0, 0, 0, 50), "foobar"); } #[test] fn set_size() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.size(), (24, 80)); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().size(), (24, 80)); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.set_size(34, 8); - assert_eq!(screen.size(), (34, 8)); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.screen_mut().set_size(34, 8); + assert_eq!(parser.screen().size(), (34, 8)); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[30;5H"); - assert_eq!(screen.cursor_position(), (29, 4)); + parser.process(b"\x1b[30;5H"); + assert_eq!(parser.screen().cursor_position(), (29, 4)); - screen.set_size(24, 80); - assert_eq!(screen.size(), (24, 80)); - assert_eq!(screen.cursor_position(), (23, 4)); + parser.screen_mut().set_size(24, 80); + assert_eq!(parser.screen().size(), (24, 80)); + assert_eq!(parser.screen().cursor_position(), (23, 4)); - screen.set_size(34, 8); - assert_eq!(screen.size(), (34, 8)); - assert_eq!(screen.cursor_position(), (23, 4)); + parser.screen_mut().set_size(34, 8); + assert_eq!(parser.screen().size(), (34, 8)); + assert_eq!(parser.screen().cursor_position(), (23, 4)); - screen.process(b"\x1b[?1049h"); - assert_eq!(screen.size(), (34, 8)); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[?1049h"); + assert_eq!(parser.screen().size(), (34, 8)); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.set_size(24, 80); - assert_eq!(screen.size(), (24, 80)); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.screen_mut().set_size(24, 80); + assert_eq!(parser.screen().size(), (24, 80)); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[?1049l"); - assert_eq!(screen.size(), (24, 80)); - assert_eq!(screen.cursor_position(), (23, 4)); + parser.process(b"\x1b[?1049l"); + assert_eq!(parser.screen().size(), (24, 80)); + assert_eq!(parser.screen().cursor_position(), (23, 4)); } #[test] fn cell_contents() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; - screen.process(input); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 5).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 6).unwrap().contents(), ""); + parser.process(input); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), ""); } #[test] fn cell_colors() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; - screen.process(input); + parser.process(input); - assert_eq!(screen.cell(0, 0).unwrap().fgcolor(), vt100::Color::Default); - assert_eq!(screen.cell(0, 3).unwrap().fgcolor(), vt100::Color::Idx(2)); - assert_eq!(screen.cell(0, 4).unwrap().fgcolor(), vt100::Color::Idx(2)); - assert_eq!(screen.cell(0, 4).unwrap().bgcolor(), vt100::Color::Idx(2)); + assert_eq!( + parser.screen().cell(0, 0).unwrap().fgcolor(), + vt100::Color::Default + ); + assert_eq!( + parser.screen().cell(0, 3).unwrap().fgcolor(), + vt100::Color::Idx(2) + ); + assert_eq!( + parser.screen().cell(0, 4).unwrap().fgcolor(), + vt100::Color::Idx(2) + ); + assert_eq!( + parser.screen().cell(0, 4).unwrap().bgcolor(), + vt100::Color::Idx(2) + ); } #[test] fn cell_attrs() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); let input = b"foo\x1b[31m\x1b[32mb\x1b[3;7;42ma\x1b[23mr"; - screen.process(input); + parser.process(input); - assert!(screen.cell(0, 4).unwrap().italic()); + assert!(parser.screen().cell(0, 4).unwrap().italic()); } diff --git a/tests/control.rs b/tests/control.rs index b1e8ea2..03352b7 100644 --- a/tests/control.rs +++ b/tests/control.rs @@ -1,74 +1,74 @@ #[test] fn bel() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - assert!(!screen.check_audible_bell()); + assert!(!parser.screen_mut().check_audible_bell()); - screen.process(b"\x07"); - assert!(screen.check_audible_bell()); - assert!(!screen.check_audible_bell()); + parser.process(b"\x07"); + assert!(parser.screen_mut().check_audible_bell()); + assert!(!parser.screen_mut().check_audible_bell()); } #[test] fn bs() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo\x08\x08aa"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "faa"); + parser.process(b"foo\x08\x08aa"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "faa"); - screen.process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar"); - assert_eq!(screen.cell(1, 0).unwrap().contents(), "b"); - assert_eq!(screen.cell(1, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 2).unwrap().contents(), "r"); - assert_eq!(screen.cell(1, 3).unwrap().contents(), "x"); - assert_eq!(screen.cell(1, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(2, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "faa\nbarx"); + parser.process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar"); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "x"); + assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(2, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "faa\nbarx"); } #[test] fn tab() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo\tbar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 5).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 6).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 7).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 8).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 9).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 10).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 11).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "foo bar"); + parser.process(b"foo\tbar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 7).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 8).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 9).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 10).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 11).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo bar"); } fn lf_with(b: u8) { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"foo"); - screen.process(&[b]); - screen.process(b"bar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 1).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 2).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(1, 4).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 5).unwrap().contents(), "r"); - assert_eq!(screen.cell(1, 6).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n bar"); + parser.process(b"foo"); + parser.process(&[b]); + parser.process(b"bar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 5).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(1, 6).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n bar"); } #[test] @@ -88,14 +88,14 @@ fn ff() { #[test] fn cr() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"fooo\rbar"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "baro"); + parser.process(b"fooo\rbar"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "baro"); } diff --git a/tests/csi.rs b/tests/csi.rs index 6878363..85bbcab 100644 --- a/tests/csi.rs +++ b/tests/csi.rs @@ -1,386 +1,389 @@ #[test] fn absolute_movement() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[10;10H"); - assert_eq!(screen.cursor_position(), (9, 9)); + parser.process(b"\x1b[10;10H"); + assert_eq!(parser.screen().cursor_position(), (9, 9)); - screen.process(b"\x1b[d"); - assert_eq!(screen.cursor_position(), (0, 9)); + parser.process(b"\x1b[d"); + assert_eq!(parser.screen().cursor_position(), (0, 9)); - screen.process(b"\x1b[15d"); - assert_eq!(screen.cursor_position(), (14, 9)); + parser.process(b"\x1b[15d"); + assert_eq!(parser.screen().cursor_position(), (14, 9)); - screen.process(b"\x1b[H"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[H"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[8H"); - assert_eq!(screen.cursor_position(), (7, 0)); + parser.process(b"\x1b[8H"); + assert_eq!(parser.screen().cursor_position(), (7, 0)); - screen.process(b"\x1b[15G"); - assert_eq!(screen.cursor_position(), (7, 14)); + parser.process(b"\x1b[15G"); + assert_eq!(parser.screen().cursor_position(), (7, 14)); - screen.process(b"\x1b[G"); - assert_eq!(screen.cursor_position(), (7, 0)); + parser.process(b"\x1b[G"); + assert_eq!(parser.screen().cursor_position(), (7, 0)); - screen.process(b"\x1b[0;0H"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[0;0H"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[1;1H"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[1;1H"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[500;500H"); - assert_eq!(screen.cursor_position(), (23, 79)); + parser.process(b"\x1b[500;500H"); + assert_eq!(parser.screen().cursor_position(), (23, 79)); } #[test] fn relative_movement() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[C"); - assert_eq!(screen.cursor_position(), (0, 1)); + parser.process(b"\x1b[C"); + assert_eq!(parser.screen().cursor_position(), (0, 1)); - screen.process(b"\x1b[C"); - assert_eq!(screen.cursor_position(), (0, 2)); + parser.process(b"\x1b[C"); + assert_eq!(parser.screen().cursor_position(), (0, 2)); - screen.process(b"\x1b[20C"); - assert_eq!(screen.cursor_position(), (0, 22)); + parser.process(b"\x1b[20C"); + assert_eq!(parser.screen().cursor_position(), (0, 22)); - screen.process(b"\x1b[D"); - assert_eq!(screen.cursor_position(), (0, 21)); + parser.process(b"\x1b[D"); + assert_eq!(parser.screen().cursor_position(), (0, 21)); - screen.process(b"\x1b[D"); - assert_eq!(screen.cursor_position(), (0, 20)); + parser.process(b"\x1b[D"); + assert_eq!(parser.screen().cursor_position(), (0, 20)); - screen.process(b"\x1b[9D"); - assert_eq!(screen.cursor_position(), (0, 11)); + parser.process(b"\x1b[9D"); + assert_eq!(parser.screen().cursor_position(), (0, 11)); - screen.process(b"\x1b[500C"); - assert_eq!(screen.cursor_position(), (0, 79)); + parser.process(b"\x1b[500C"); + assert_eq!(parser.screen().cursor_position(), (0, 79)); - screen.process(b"\x1b[500D"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[500D"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[B"); - assert_eq!(screen.cursor_position(), (1, 0)); + parser.process(b"\x1b[B"); + assert_eq!(parser.screen().cursor_position(), (1, 0)); - screen.process(b"\x1b[B"); - assert_eq!(screen.cursor_position(), (2, 0)); + parser.process(b"\x1b[B"); + assert_eq!(parser.screen().cursor_position(), (2, 0)); - screen.process(b"\x1b[20B"); - assert_eq!(screen.cursor_position(), (22, 0)); + parser.process(b"\x1b[20B"); + assert_eq!(parser.screen().cursor_position(), (22, 0)); - screen.process(b"\x1b[A"); - assert_eq!(screen.cursor_position(), (21, 0)); + parser.process(b"\x1b[A"); + assert_eq!(parser.screen().cursor_position(), (21, 0)); - screen.process(b"\x1b[A"); - assert_eq!(screen.cursor_position(), (20, 0)); + parser.process(b"\x1b[A"); + assert_eq!(parser.screen().cursor_position(), (20, 0)); - screen.process(b"\x1b[9A"); - assert_eq!(screen.cursor_position(), (11, 0)); + parser.process(b"\x1b[9A"); + assert_eq!(parser.screen().cursor_position(), (11, 0)); - screen.process(b"\x1b[500B"); - assert_eq!(screen.cursor_position(), (23, 0)); + parser.process(b"\x1b[500B"); + assert_eq!(parser.screen().cursor_position(), (23, 0)); - screen.process(b"\x1b[500A"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[500A"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); } #[test] fn ed() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[0J"); + parser.process(b"\x1b[10;12H\x1b[0J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba" ); - screen.process(b"\x1b[5;6H\x1b[1J"); + parser.process(b"\x1b[5;6H\x1b[1J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n r\n\n\n\n\n ba" ); - screen.process(b"\x1b[7;7H\x1b[2J"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[7;7H\x1b[2J"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[2J\x1b[H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[J"); + parser.process(b"\x1b[10;12H\x1b[J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba" ); - screen.process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[2J\x1b[H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[?0J"); + parser.process(b"\x1b[10;12H\x1b[?0J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba" ); - screen.process(b"\x1b[5;6H\x1b[?1J"); + parser.process(b"\x1b[5;6H\x1b[?1J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n r\n\n\n\n\n ba" ); - screen.process(b"\x1b[7;7H\x1b[?2J"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[7;7H\x1b[?2J"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[2J\x1b[H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbar\x1b[10;10Hbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[?J"); + parser.process(b"\x1b[10;12H\x1b[?J"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n ba" ); } #[test] fn el() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[5;8H\x1b[0K"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"\x1b[5;8H\x1b[0K"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[1K"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"\x1b[10;12H\x1b[1K"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[20;22H\x1b[2K"); + parser.process(b"\x1b[20;22H\x1b[2K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz" ); - screen.process(b"\x1b[1;2H\x1b[K"); + parser.process(b"\x1b[1;2H\x1b[K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "f\n\n\n\n bar\n\n\n\n\n baz" ); - screen.process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[2J\x1b[H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"foo\x1b[5;5Hbarbar\x1b[10;10Hbazbaz\x1b[20;20Hquux"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n barbar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[5;8H\x1b[?0K"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"\x1b[5;8H\x1b[?0K"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n bazbaz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[10;12H\x1b[?1K"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); + parser.process(b"\x1b[10;12H\x1b[?1K"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz\n\n\n\n\n\n\n\n\n\n quux"); - screen.process(b"\x1b[20;22H\x1b[?2K"); + parser.process(b"\x1b[20;22H\x1b[?2K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "foo\n\n\n\n bar\n\n\n\n\n baz" ); - screen.process(b"\x1b[1;2H\x1b[?K"); + parser.process(b"\x1b[1;2H\x1b[?K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "f\n\n\n\n bar\n\n\n\n\n baz" ); - screen.process(b"\x1b[2J\x1b[H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + parser.process(b"\x1b[2J\x1b[H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); + parser.process(b"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" ); - screen.process(b"\x1b[1;21H\x1b[K"); + parser.process(b"\x1b[1;21H\x1b[K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "12345678901234567890\n12345678901234567890" ); - screen.process(b"\x1b[1;10H\x1b[1K"); + parser.process(b"\x1b[1;10H\x1b[1K"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), " 1234567890\n12345678901234567890" ); } #[test] fn ich_dch_ech() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"\x1b[10;10Hfoobar"); + parser.process(b"\x1b[10;10Hfoobar"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar" ); - screen.process(b"\x1b[10;12H\x1b[3@"); + parser.process(b"\x1b[10;12H\x1b[3@"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo obar" ); - assert_eq!(screen.cursor_position(), (9, 11)); + assert_eq!(parser.screen().cursor_position(), (9, 11)); - screen.process(b"\x1b[4P"); + parser.process(b"\x1b[4P"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fobar" ); - assert_eq!(screen.cursor_position(), (9, 11)); + assert_eq!(parser.screen().cursor_position(), (9, 11)); - screen.process(b"\x1b[100@"); + parser.process(b"\x1b[100@"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo" ); - assert_eq!(screen.cursor_position(), (9, 11)); + assert_eq!(parser.screen().cursor_position(), (9, 11)); - screen.process(b"obar"); + parser.process(b"obar"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (9, 15)); + assert_eq!(parser.screen().cursor_position(), (9, 15)); - screen.process(b"\x1b[10;12H\x1b[100P"); + parser.process(b"\x1b[10;12H\x1b[100P"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n fo" ); - assert_eq!(screen.cursor_position(), (9, 11)); + assert_eq!(parser.screen().cursor_position(), (9, 11)); - screen.process(b"obar"); + parser.process(b"obar"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (9, 15)); + assert_eq!(parser.screen().cursor_position(), (9, 15)); - screen.process(b"\x1b[10;13H\x1b[X"); + parser.process(b"\x1b[10;13H\x1b[X"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foo ar" ); - assert_eq!(screen.cursor_position(), (9, 12)); + assert_eq!(parser.screen().cursor_position(), (9, 12)); - screen.process(b"\x1b[10;11H\x1b[4X"); + parser.process(b"\x1b[10;11H\x1b[4X"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n f r" ); - assert_eq!(screen.cursor_position(), (9, 10)); + assert_eq!(parser.screen().cursor_position(), (9, 10)); - screen.process(b"\x1b[10;11H\x1b[400X"); + parser.process(b"\x1b[10;11H\x1b[400X"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n f" ); - assert_eq!(screen.cursor_position(), (9, 10)); + assert_eq!(parser.screen().cursor_position(), (9, 10)); } #[test] fn il_dl() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"\x1b[10;10Hfoobar\x1b[3D"); + parser.process(b"\x1b[10;10Hfoobar\x1b[3D"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (9, 12)); + assert_eq!(parser.screen().cursor_position(), (9, 12)); - screen.process(b"\x1b[L"); + parser.process(b"\x1b[L"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (9, 12)); + assert_eq!(parser.screen().cursor_position(), (9, 12)); - screen.process(b"\x1b[3L"); + parser.process(b"\x1b[3L"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (9, 12)); + assert_eq!(parser.screen().cursor_position(), (9, 12)); - screen.process(b"\x1b[500L"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (9, 12)); + parser.process(b"\x1b[500L"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (9, 12)); - screen.process(b"\x1b[10;10Hfoobar\x1b[3D\x1b[6A"); + parser.process(b"\x1b[10;10Hfoobar\x1b[3D\x1b[6A"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (3, 12)); + assert_eq!(parser.screen().cursor_position(), (3, 12)); - screen.process(b"\x1b[M"); + parser.process(b"\x1b[M"); assert_eq!( - screen.contents(0, 0, 23, 79), + parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n\n\n foobar" ); - assert_eq!(screen.cursor_position(), (3, 12)); + assert_eq!(parser.screen().cursor_position(), (3, 12)); - screen.process(b"\x1b[3M"); - assert_eq!(screen.contents(0, 0, 23, 79), "\n\n\n\n\n foobar"); - assert_eq!(screen.cursor_position(), (3, 12)); + parser.process(b"\x1b[3M"); + assert_eq!( + parser.screen().contents(0, 0, 23, 79), + "\n\n\n\n\n foobar" + ); + assert_eq!(parser.screen().cursor_position(), (3, 12)); - screen.process(b"\x1b[500M"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (3, 12)); + parser.process(b"\x1b[500M"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (3, 12)); } #[test] fn scroll() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.contents(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); - screen.process(b"1\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.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"); + parser.process(b"1\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(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"); - screen.process(b"\x1b[15;15H"); - assert_eq!(screen.cursor_position(), (14, 14)); + parser.process(b"\x1b[15;15H"); + assert_eq!(parser.screen().cursor_position(), (14, 14)); - screen.process(b"\x1b[S"); - assert_eq!(screen.contents(0, 0, 23, 79), "2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); - assert_eq!(screen.cursor_position(), (14, 14)); + parser.process(b"\x1b[S"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); + assert_eq!(parser.screen().cursor_position(), (14, 14)); - screen.process(b"\x1b[3S"); - assert_eq!(screen.contents(0, 0, 23, 79), "5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); - assert_eq!(screen.cursor_position(), (14, 14)); + parser.process(b"\x1b[3S"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); + assert_eq!(parser.screen().cursor_position(), (14, 14)); - screen.process(b"\x1b[T"); - assert_eq!(screen.contents(0, 0, 23, 79), "\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); - assert_eq!(screen.cursor_position(), (14, 14)); + parser.process(b"\x1b[T"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); + assert_eq!(parser.screen().cursor_position(), (14, 14)); - screen.process(b"\x1b[5T"); - assert_eq!(screen.contents(0, 0, 23, 79), "\n\n\n\n\n\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22"); - assert_eq!(screen.cursor_position(), (14, 14)); + parser.process(b"\x1b[5T"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "\n\n\n\n\n\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22"); + assert_eq!(parser.screen().cursor_position(), (14, 14)); } diff --git a/tests/escape.rs b/tests/escape.rs index 2385704..d2dd5b1 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -2,177 +2,186 @@ #[test] fn deckpam() { - let mut screen = vt100::Screen::new(24, 80); - assert!(!screen.application_keypad()); - screen.process(b"\x1b="); - assert!(screen.application_keypad()); - screen.process(b"\x1b>"); - assert!(!screen.application_keypad()); + let mut parser = vt100::Parser::new(24, 80); + assert!(!parser.screen().application_keypad()); + parser.process(b"\x1b="); + assert!(parser.screen().application_keypad()); + parser.process(b"\x1b>"); + assert!(!parser.screen().application_keypad()); } #[test] fn ri() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"foo\nbar\x1bMbaz"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo baz\n bar"); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"foo\nbar\x1bMbaz"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo baz\n bar"); } #[test] fn ris() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - let cell = screen.cell(0, 0).unwrap(); + let cell = parser.screen().cell(0, 0).unwrap(); assert_eq!(cell.contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.contents_formatted(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), ""); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); - assert!(!screen.check_visual_bell()); - assert!(!screen.check_audible_bell()); - assert!(!screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(!parser.screen_mut().check_visual_bell()); + assert!(!parser.screen_mut().check_audible_bell()); + assert!(!parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.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"); + parser.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"); - assert_eq!(screen.cursor_position(), (20, 20)); + assert_eq!(parser.screen().cursor_position(), (20, 20)); - let cell = screen.cell(0, 0).unwrap(); + let cell = parser.screen().cell(0, 0).unwrap(); assert_eq!(cell.contents(), "f"); - assert_eq!(screen.contents(0, 0, 23, 79), "foo"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo"); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "f\x1b[31;47;1;3;4moo" ); - assert_eq!(screen.title(), "window title"); - assert_eq!(screen.icon_name(), "window icon name"); + assert_eq!(parser.screen().title(), "window title"); + assert_eq!(parser.screen().icon_name(), "window icon name"); - assert_eq!(screen.fgcolor(), vt100::Color::Idx(1)); - assert_eq!(screen.bgcolor(), vt100::Color::Idx(7)); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Idx(1)); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Idx(7)); - assert!(screen.bold()); - assert!(screen.italic()); - assert!(screen.underline()); - assert!(screen.inverse()); + assert!(parser.screen().bold()); + assert!(parser.screen().italic()); + assert!(parser.screen().underline()); + assert!(parser.screen().inverse()); - assert!(screen.check_visual_bell()); - assert!(screen.check_audible_bell()); - assert!(screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen_mut().check_visual_bell()); + assert!(parser.screen_mut().check_audible_bell()); + assert!(parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x07\x1bg\x1bc"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x07\x1bg\x1bc"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - let cell = screen.cell(0, 0).unwrap(); + let cell = parser.screen().cell(0, 0).unwrap(); assert_eq!(cell.contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.contents_formatted(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), ""); // title and icon name don't change with reset - assert_eq!(screen.title(), "window title"); - assert_eq!(screen.icon_name(), "window icon name"); + assert_eq!(parser.screen().title(), "window title"); + assert_eq!(parser.screen().icon_name(), "window icon name"); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); // bell states don't change with reset - assert!(screen.check_visual_bell()); - assert!(screen.check_audible_bell()); - - assert!(!screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(parser.screen_mut().check_visual_bell()); + assert!(parser.screen_mut().check_audible_bell()); + + assert!(!parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); } #[test] fn vb() { - let mut screen = vt100::Screen::new(24, 80); - assert!(!screen.check_visual_bell()); - screen.process(b"\x1bg"); - assert!(screen.check_visual_bell()); - assert!(!screen.check_visual_bell()); + let mut parser = vt100::Parser::new(24, 80); + assert!(!parser.screen_mut().check_visual_bell()); + parser.process(b"\x1bg"); + assert!(parser.screen_mut().check_visual_bell()); + assert!(!parser.screen_mut().check_visual_bell()); } #[test] fn decsc() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"foo\x1b7\r\n\r\n\r\n bar\x1b8baz"); - assert_eq!(screen.contents(0, 0, 23, 79), "foobaz\n\n\n bar"); - assert_eq!(screen.cursor_position(), (0, 6)); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"foo\x1b7\r\n\r\n\r\n bar\x1b8baz"); + assert_eq!( + parser.screen().contents(0, 0, 23, 79), + "foobaz\n\n\n bar" + ); + assert_eq!(parser.screen().cursor_position(), (0, 6)); - screen.process(b"\x1b[?47h\x1b[20;20H"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (19, 19)); + parser.process(b"\x1b[?47h\x1b[20;20H"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (19, 19)); - screen.process(b"\x1b8"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b8"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[?47l\x1b[20;20H"); - assert_eq!(screen.cursor_position(), (19, 19)); + parser.process(b"\x1b[?47l\x1b[20;20H"); + assert_eq!(parser.screen().cursor_position(), (19, 19)); - screen.process(b"\x1b8"); - assert_eq!(screen.cursor_position(), (0, 3)); + parser.process(b"\x1b8"); + assert_eq!(parser.screen().cursor_position(), (0, 3)); - screen.process(b"\x1bc\x1b[31m\x1b[5;15r\x1b[?6hfoo\x1b7"); - assert_eq!(screen.cursor_position(), (4, 3)); + parser.process(b"\x1bc\x1b[31m\x1b[5;15r\x1b[?6hfoo\x1b7"); + assert_eq!(parser.screen().cursor_position(), (4, 3)); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "\r\n\r\n\r\n\r\n\x1b[31mfoo" ); - screen.process(b"\x1b[32m\x1b[?6lbar"); - assert_eq!(screen.cursor_position(), (0, 3)); + parser.process(b"\x1b[32m\x1b[?6lbar"); + assert_eq!(parser.screen().cursor_position(), (0, 3)); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mfoo" ); - screen.process(b"\x1b8\x1b[Hz"); - assert_eq!(screen.cursor_position(), (4, 1)); + parser.process(b"\x1b8\x1b[Hz"); + assert_eq!(parser.screen().cursor_position(), (4, 1)); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mzoo" ); } diff --git a/tests/init.rs b/tests/init.rs index 7617fe7..cf9d146 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -2,42 +2,45 @@ #[test] fn init() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.size(), (24, 80)); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().size(), (24, 80)); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - let cell = screen.cell(0, 0); + let cell = parser.screen().cell(0, 0); assert_eq!(cell.unwrap().contents(), ""); - let cell = screen.cell(23, 79); + let cell = parser.screen().cell(23, 79); assert_eq!(cell.unwrap().contents(), ""); - let cell = screen.cell(24, 0); + let cell = parser.screen().cell(24, 0); assert!(cell.is_none()); - let cell = screen.cell(0, 80); + let cell = parser.screen().cell(0, 80); assert!(cell.is_none()); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.contents_formatted(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), ""); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); - assert_eq!(screen.fgcolor(), vt100::Color::Default); - assert_eq!(screen.bgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().fgcolor(), vt100::Color::Default); + assert_eq!(parser.screen().bgcolor(), vt100::Color::Default); - assert!(!screen.bold()); - assert!(!screen.italic()); - assert!(!screen.underline()); - assert!(!screen.inverse()); + assert!(!parser.screen().bold()); + assert!(!parser.screen().italic()); + assert!(!parser.screen().underline()); + assert!(!parser.screen().inverse()); - assert!(!screen.check_visual_bell()); - assert!(!screen.check_audible_bell()); - assert!(!screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(!parser.screen_mut().check_visual_bell()); + assert!(!parser.screen_mut().check_audible_bell()); + assert!(!parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); } diff --git a/tests/mode.rs b/tests/mode.rs index 0cca4b7..277cdad 100644 --- a/tests/mode.rs +++ b/tests/mode.rs @@ -2,375 +2,396 @@ #[test] fn modes() { - let mut screen = vt100::Screen::new(24, 80); - assert!(!screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!( - screen.mouse_protocol_encoding(), + let mut parser = vt100::Parser::new(24, 80); + assert!(!parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?1h"); + parser.process(b"\x1b[?1h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?9h"); + parser.process(b"\x1b[?9h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::Press ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?25l"); + parser.process(b"\x1b[?25l"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::Press ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?1000h"); + parser.process(b"\x1b[?1000h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?1002h"); + parser.process(b"\x1b[?1002h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::ButtonMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?1003h"); + parser.process(b"\x1b[?1003h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?1005h"); + parser.process(b"\x1b[?1005h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Utf8 ); - screen.process(b"\x1b[?1006h"); + parser.process(b"\x1b[?1006h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(!screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?2004h"); + parser.process(b"\x1b[?2004h"); - assert!(!screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(!parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b="); + parser.process(b"\x1b="); - assert!(screen.application_keypad()); - assert!(screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1l"); + parser.process(b"\x1b[?1l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?9l"); + parser.process(b"\x1b[?9l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?25h"); + parser.process(b"\x1b[?25h"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1000l"); + parser.process(b"\x1b[?1000l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1002l"); + parser.process(b"\x1b[?1002l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::AnyMotion ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1003l"); + parser.process(b"\x1b[?1003l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1005l"); + parser.process(b"\x1b[?1005l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Sgr ); - screen.process(b"\x1b[?1006l"); + parser.process(b"\x1b[?1006l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(parser.screen().bracketed_paste()); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b[?2004l"); + parser.process(b"\x1b[?2004l"); - assert!(screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!( + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); - screen.process(b"\x1b>"); + parser.process(b"\x1b>"); - assert!(!screen.application_keypad()); - assert!(!screen.application_cursor()); - assert!(!screen.hide_cursor()); - assert!(!screen.bracketed_paste()); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); + assert!(!parser.screen().application_keypad()); + assert!(!parser.screen().application_cursor()); + assert!(!parser.screen().hide_cursor()); + assert!(!parser.screen().bracketed_paste()); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); assert_eq!( - screen.mouse_protocol_encoding(), + parser.screen().mouse_protocol_encoding(), vt100::MouseProtocolEncoding::Default ); } #[test] fn alternate_buffer() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); // 47 - screen.process(b"\x1bc"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (0, 0)); - 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.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); - - screen.process(b"\x1b[?47h"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_screen()); - - screen.process(b"foobar"); - assert_eq!(screen.contents(0, 0, 23, 79), "foobar"); - assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_screen()); - - screen.process(b"\x1b[?47l"); - assert_eq!(screen.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); - - screen.process(b"\x1b[?47h"); - assert_eq!(screen.contents(0, 0, 23, 79), "foobar"); - assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_screen()); - - screen.process(b"\x1b[?47l"); - assert_eq!(screen.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); + parser.process(b"\x1bc"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (0, 0)); + assert!(!parser.screen().alternate_screen()); + + parser.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!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); + + parser.process(b"\x1b[?47h"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (0, 0)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"foobar"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foobar"); + assert_eq!(parser.screen().cursor_position(), (0, 6)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"\x1b[?47l"); + assert_eq!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); + + parser.process(b"\x1b[?47h"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foobar"); + assert_eq!(parser.screen().cursor_position(), (0, 6)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"\x1b[?47l"); + assert_eq!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); // 1049 - screen.process(b"\x1bc"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (0, 0)); - 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.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); - - screen.process(b"\x1b[?1049h"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_screen()); - - screen.process(b"foobar"); - assert_eq!(screen.contents(0, 0, 23, 79), "foobar"); - assert_eq!(screen.cursor_position(), (0, 6)); - assert!(screen.alternate_screen()); - - screen.process(b"\x1b[?1049l"); - assert_eq!(screen.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); - - screen.process(b"\x1b[?1049h"); - assert_eq!(screen.contents(0, 0, 23, 79), ""); - assert_eq!(screen.cursor_position(), (0, 0)); - assert!(screen.alternate_screen()); - - screen.process(b"\x1b[?1049l"); - assert_eq!(screen.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"); - assert_eq!(screen.cursor_position(), (23, 2)); - assert!(!screen.alternate_screen()); + parser.process(b"\x1bc"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (0, 0)); + assert!(!parser.screen().alternate_screen()); + + parser.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!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); + + parser.process(b"\x1b[?1049h"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (0, 0)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"foobar"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foobar"); + assert_eq!(parser.screen().cursor_position(), (0, 6)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"\x1b[?1049l"); + assert_eq!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); + + parser.process(b"\x1b[?1049h"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), ""); + assert_eq!(parser.screen().cursor_position(), (0, 0)); + assert!(parser.screen().alternate_screen()); + + parser.process(b"\x1b[?1049l"); + assert_eq!(parser.screen().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"); + assert_eq!(parser.screen().cursor_position(), (23, 2)); + assert!(!parser.screen().alternate_screen()); } diff --git a/tests/osc.rs b/tests/osc.rs index 4a02592..8cf90dd 100644 --- a/tests/osc.rs +++ b/tests/osc.rs @@ -1,46 +1,46 @@ #[test] fn title() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); - screen.process(b"\x1b]2;it's a title\x07"); - assert_eq!(screen.title(), "it's a title"); - assert_eq!(screen.icon_name(), ""); - screen.process(b"\x1b]2;\x07"); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); + parser.process(b"\x1b]2;it's a title\x07"); + assert_eq!(parser.screen().title(), "it's a title"); + assert_eq!(parser.screen().icon_name(), ""); + parser.process(b"\x1b]2;\x07"); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); } #[test] fn icon_name() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); - screen.process(b"\x1b]1;it's an icon name\x07"); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), "it's an icon name"); - screen.process(b"\x1b]1;\x07"); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); + parser.process(b"\x1b]1;it's an icon name\x07"); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), "it's an icon name"); + parser.process(b"\x1b]1;\x07"); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); } #[test] fn title_icon_name() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); - screen.process(b"\x1b]0;it's both\x07"); - assert_eq!(screen.title(), "it's both"); - assert_eq!(screen.icon_name(), "it's both"); - screen.process(b"\x1b]0;\x07"); - assert_eq!(screen.title(), ""); - assert_eq!(screen.icon_name(), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); + parser.process(b"\x1b]0;it's both\x07"); + assert_eq!(parser.screen().title(), "it's both"); + assert_eq!(parser.screen().icon_name(), "it's both"); + parser.process(b"\x1b]0;\x07"); + assert_eq!(parser.screen().title(), ""); + assert_eq!(parser.screen().icon_name(), ""); } #[test] fn unknown_sequence() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.cell(0, 0).unwrap().contents(), ""); - screen.process(b"\x1b]499;some long, long string?\x07"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), ""); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), ""); + parser.process(b"\x1b]499;some long, long string?\x07"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), ""); } diff --git a/tests/processing.rs b/tests/processing.rs index f390493..282ab65 100644 --- a/tests/processing.rs +++ b/tests/processing.rs @@ -2,199 +2,223 @@ #[test] fn split_escape_sequences() { - let mut screen = vt100::Screen::new(24, 80); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"abc"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"abc\x1b[12;24Hdef"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + let mut parser = vt100::Parser::new(24, 80); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"abc"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"abc\x1b[12;24Hdef"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); assert!(contents.contains("abc")); assert!(contents.contains("def")); - assert_eq!(screen.cursor_position(), (11, 26)); + assert_eq!(parser.screen().cursor_position(), (11, 26)); - screen.process(b"\x1b"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"1"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"2"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b";"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"2"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"4"); - assert_eq!(screen.cursor_position(), (11, 26)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"H"); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + parser.process(b"\x1b"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"1"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"2"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b";"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"2"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"4"); + assert_eq!(parser.screen().cursor_position(), (11, 26)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"H"); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - screen.process(b"\x1b"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"?"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"1"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.mouse_protocol_mode(), vt100::MouseProtocolMode::None); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"h"); - assert_eq!( - screen.mouse_protocol_mode(), + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + parser.process(b"\x1b"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"?"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"1"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!( + parser.screen().mouse_protocol_mode(), + vt100::MouseProtocolMode::None + ); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"h"); + assert_eq!( + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); - assert_eq!(screen.title(), ""); - screen.process(b"\x1b"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().title(), ""); + parser.process(b"\x1b"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"]"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"]"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"0"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"0"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b";"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b";"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"a"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"a"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b" "); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b" "); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"'"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"'"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"["); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"["); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"]"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"]"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"_"); - assert_eq!(screen.title(), ""); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"_"); + assert_eq!(parser.screen().title(), ""); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x07"); - assert_eq!(screen.title(), "a '[]_"); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x07"); + assert_eq!(parser.screen().title(), "a '[]_"); assert_eq!( - screen.mouse_protocol_mode(), + parser.screen().mouse_protocol_mode(), vt100::MouseProtocolMode::PressRelease ); - assert_eq!(screen.cursor_position(), (11, 23)); - assert_eq!(screen.contents(0, 0, 23, 79), contents); + assert_eq!(parser.screen().cursor_position(), (11, 23)); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); } #[test] fn split_utf8() { - let mut screen = vt100::Screen::new(24, 80); - let contents = screen.contents(0, 0, 23, 79); - screen.process(b"a"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + let mut parser = vt100::Parser::new(24, 80); + let contents = parser.screen().contents(0, 0, 23, 79); + parser.process(b"a"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xc3"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xa1"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + parser.process(b"\xc3"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xa1"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xe3"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x82"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xad"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); - let contents = screen.contents(0, 0, 23, 79); + parser.process(b"\xe3"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x82"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xad"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); + let contents = parser.screen().contents(0, 0, 23, 79); - screen.process(b"\xf0"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x9f"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\x92"); - assert_eq!(screen.contents(0, 0, 23, 79), contents); - screen.process(b"\xa9"); - assert_ne!(screen.contents(0, 0, 23, 79), contents); + parser.process(b"\xf0"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x9f"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\x92"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), contents); + parser.process(b"\xa9"); + assert_ne!(parser.screen().contents(0, 0, 23, 79), contents); } diff --git a/tests/scroll.rs b/tests/scroll.rs index b75a54d..a8bfb05 100644 --- a/tests/scroll.rs +++ b/tests/scroll.rs @@ -1,64 +1,64 @@ #[test] fn scroll_regions() { - let mut screen = vt100::Screen::new(24, 80); - 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.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"); + let mut parser = vt100::Parser::new(24, 80); + parser.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!(parser.screen().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"); - screen.process(b"\x1b[24;50H\n"); - assert_eq!(screen.contents(0, 0, 23, 79), "2\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[24;50H\n"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24"); - 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"); + parser.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"); - screen.process(b"\x1b[10;20r"); - assert_eq!(screen.cursor_position(), (9, 0)); + parser.process(b"\x1b[10;20r"); + assert_eq!(parser.screen().cursor_position(), (9, 0)); - screen.process(b"\x1b[20;50H"); - assert_eq!(screen.cursor_position(), (19, 49)); + parser.process(b"\x1b[20;50H"); + assert_eq!(parser.screen().cursor_position(), (19, 49)); - screen.process(b"\n"); - assert_eq!(screen.contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n\n21\n22\n23\n24"); - assert_eq!(screen.cursor_position(), (19, 49)); + parser.process(b"\n"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n\n21\n22\n23\n24"); + assert_eq!(parser.screen().cursor_position(), (19, 49)); - screen.process(b"\x1b[B"); - assert_eq!(screen.cursor_position(), (19, 49)); + parser.process(b"\x1b[B"); + assert_eq!(parser.screen().cursor_position(), (19, 49)); - screen.process(b"\x1b[20A"); - assert_eq!(screen.cursor_position(), (9, 49)); - screen.process(b"\x1b[1;24r\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"); - screen.process(b"\x1b[10;20r\x1b[15;50H\x1b[2L"); - assert_eq!(screen.contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n\n\n15\n16\n17\n18\n21\n22\n23\n24"); - screen.process(b"\x1b[10;50H\x1bM"); - assert_eq!(screen.contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n\n10\n11\n12\n13\n14\n\n\n15\n16\n17\n21\n22\n23\n24"); + parser.process(b"\x1b[20A"); + assert_eq!(parser.screen().cursor_position(), (9, 49)); + parser.process(b"\x1b[1;24r\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"); + parser.process(b"\x1b[10;20r\x1b[15;50H\x1b[2L"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n\n\n15\n16\n17\n18\n21\n22\n23\n24"); + parser.process(b"\x1b[10;50H\x1bM"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n\n10\n11\n12\n13\n14\n\n\n15\n16\n17\n21\n22\n23\n24"); } #[test] fn origin_mode() { - let mut screen = vt100::Screen::new(24, 80); + let mut parser = vt100::Parser::new(24, 80); - screen.process(b"\x1b[5;15r"); - assert_eq!(screen.cursor_position(), (4, 0)); + parser.process(b"\x1b[5;15r"); + assert_eq!(parser.screen().cursor_position(), (4, 0)); - screen.process(b"\x1b[10;50H"); - assert_eq!(screen.cursor_position(), (9, 49)); + parser.process(b"\x1b[10;50H"); + assert_eq!(parser.screen().cursor_position(), (9, 49)); - screen.process(b"\x1b[?6h"); - assert_eq!(screen.cursor_position(), (4, 0)); + parser.process(b"\x1b[?6h"); + assert_eq!(parser.screen().cursor_position(), (4, 0)); - screen.process(b"\x1b[10;50H"); - assert_eq!(screen.cursor_position(), (13, 49)); + parser.process(b"\x1b[10;50H"); + assert_eq!(parser.screen().cursor_position(), (13, 49)); - screen.process(b"\x1b[?6l"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[?6l"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[10;50H"); - assert_eq!(screen.cursor_position(), (9, 49)); + parser.process(b"\x1b[10;50H"); + assert_eq!(parser.screen().cursor_position(), (9, 49)); - screen.process(b"\x1b[?6h\x1b[?47h\x1b[6;16r\x1b[H"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b[?6h\x1b[?47h\x1b[6;16r\x1b[H"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b[?6h"); - assert_eq!(screen.cursor_position(), (5, 0)); + parser.process(b"\x1b[?6h"); + assert_eq!(parser.screen().cursor_position(), (5, 0)); - screen.process(b"\x1b[?47l\x1b[H"); - assert_eq!(screen.cursor_position(), (4, 0)); + parser.process(b"\x1b[?47l\x1b[H"); + assert_eq!(parser.screen().cursor_position(), (4, 0)); } diff --git a/tests/split-escapes.rs b/tests/split-escapes.rs index b9f4cd9..36a9eaa 100644 --- a/tests/split-escapes.rs +++ b/tests/split-escapes.rs @@ -7,26 +7,26 @@ fn get_file_contents(name: &str) -> Vec<u8> { buf } -fn write_to_screen(chunks: &mut Vec<Vec<u8>>) -> (String, String) { - let mut screen = vt100::Screen::new(37, 193); +fn write_to_parser(chunks: &mut Vec<Vec<u8>>) -> (String, String) { + let mut parser = vt100::Parser::new(37, 193); for chunk in chunks.iter_mut() { - screen.process(&chunk); + parser.process(&chunk); } ( - screen.contents(0, 0, 36, 192), - screen.contents_formatted(0, 0, 36, 192), + parser.screen().contents(0, 0, 36, 192), + parser.screen().contents_formatted(0, 0, 36, 192), ) } fn test_splits(filename: &str) { let bytes = get_file_contents(filename); let len = bytes.len(); - let expected = write_to_screen(&mut vec![bytes.clone()]); + let expected = write_to_parser(&mut vec![bytes.clone()]); for i in 0..(len - 1) { let bytes_copy = bytes.clone(); let (start, end) = bytes_copy.split_at(i); let mut chunks = vec![start.to_vec(), end.to_vec()]; - let got = write_to_screen(&mut chunks); + let got = write_to_parser(&mut chunks); assert!( got == expected, "failed to render {} when split at byte {}", diff --git a/tests/text.rs b/tests/text.rs index f741100..b3f3520 100644 --- a/tests/text.rs +++ b/tests/text.rs @@ -2,237 +2,237 @@ #[test] fn ascii() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"foo"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "foo"); - assert_eq!(screen.contents(0, 0, 500, 500), "foo"); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"foo"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo"); + assert_eq!(parser.screen().contents(0, 0, 500, 500), "foo"); } #[test] fn utf8() { - let mut screen = vt100::Screen::new(24, 80); - screen.process("café".as_bytes()); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "c"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "é"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "café"); - assert_eq!(screen.contents(0, 0, 500, 500), "café"); + let mut parser = vt100::Parser::new(24, 80); + parser.process("café".as_bytes()); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "c"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "é"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "café"); + assert_eq!(parser.screen().contents(0, 0, 500, 500), "café"); } #[test] fn newlines() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"f\r\noo\r\nood"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 2).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), "o"); - assert_eq!(screen.cell(1, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(1, 2).unwrap().contents(), ""); - assert_eq!(screen.cell(2, 0).unwrap().contents(), "o"); - assert_eq!(screen.cell(2, 1).unwrap().contents(), "o"); - assert_eq!(screen.cell(2, 2).unwrap().contents(), "d"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), ""); - assert_eq!(screen.cell(3, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "f\noo\nood"); - assert_eq!(screen.contents(0, 0, 500, 500), "f\noo\nood"); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"f\r\noo\r\nood"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(2, 0).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(2, 1).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(2, 2).unwrap().contents(), "d"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(3, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "f\noo\nood"); + assert_eq!(parser.screen().contents(0, 0, 500, 500), "f\noo\nood"); } #[test] fn wide() { - let mut screen = vt100::Screen::new(24, 80); - screen.process("aデbネ".as_bytes()); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "デ"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "b"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), "ネ"); - assert_eq!(screen.cell(0, 5).unwrap().contents(), ""); - assert_eq!(screen.cell(0, 6).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), ""); - assert_eq!(screen.contents(0, 0, 23, 79), "aデbネ"); - assert_eq!(screen.contents(0, 0, 500, 500), "aデbネ"); + let mut parser = vt100::Parser::new(24, 80); + parser.process("aデbネ".as_bytes()); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "デ"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "b"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "ネ"); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), ""); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "aデbネ"); + assert_eq!(parser.screen().contents(0, 0, 500, 500), "aデbネ"); } #[test] fn combining() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"a"); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "a"); - screen.process("\u{0301}".as_bytes()); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "á"); - screen.process(b"\x1b[20;20Habcdefg"); - assert_eq!(screen.contents(19, 19, 19, 26), "abcdefg"); - screen.process("\x1b[20;25H\u{0301}".as_bytes()); - assert_eq!(screen.contents(19, 19, 19, 26), "abcdéfg"); - screen.process(b"\x1b[10;78Haaa"); - assert_eq!(screen.cell(9, 79).unwrap().contents(), "a"); - screen.process("\r\n\u{0301}".as_bytes()); - assert_eq!(screen.cell(9, 79).unwrap().contents(), "a"); - assert_eq!(screen.cell(10, 0).unwrap().contents(), ""); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"a"); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "a"); + parser.process("\u{0301}".as_bytes()); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "á"); + parser.process(b"\x1b[20;20Habcdefg"); + assert_eq!(parser.screen().contents(19, 19, 19, 26), "abcdefg"); + parser.process("\x1b[20;25H\u{0301}".as_bytes()); + assert_eq!(parser.screen().contents(19, 19, 19, 26), "abcdéfg"); + parser.process(b"\x1b[10;78Haaa"); + assert_eq!(parser.screen().cell(9, 79).unwrap().contents(), "a"); + parser.process("\r\n\u{0301}".as_bytes()); + assert_eq!(parser.screen().cell(9, 79).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(10, 0).unwrap().contents(), ""); } #[test] fn wrap() { - let mut screen = vt100::Screen::new(24, 80); - screen.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); - screen.process(b"\x1b[5H01234567890123456789012345678901234567890123456789012345678901234567890123456789"); - screen.process(b"\x1b[6H01234567890123456789012345678901234567890123456789012345678901234567890123456789"); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\n\n\n01234567890123456789012345678901234567890123456789012345678901234567890123456789\n01234567890123456789012345678901234567890123456789012345678901234567890123456789"); + let mut parser = vt100::Parser::new(24, 80); + parser.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); + parser.process(b"\x1b[5H01234567890123456789012345678901234567890123456789012345678901234567890123456789"); + parser.process(b"\x1b[6H01234567890123456789012345678901234567890123456789012345678901234567890123456789"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\n\n\n01234567890123456789012345678901234567890123456789012345678901234567890123456789\n01234567890123456789012345678901234567890123456789012345678901234567890123456789"); - screen.process(b"\x1b[H\x1b[J"); - screen.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678"); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678"); - assert_eq!(screen.cursor_position(), (0, 79)); - screen.process(b"9"); - assert_eq!(screen.contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789"); - assert_eq!(screen.cursor_position(), (0, 80)); - screen.process(b"a"); - assert_eq!(screen.contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789a"); - assert_eq!(screen.cursor_position(), (1, 1)); - screen.process(b"b"); - assert_eq!(screen.contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789ab"); - assert_eq!(screen.cursor_position(), (1, 2)); + parser.process(b"\x1b[H\x1b[J"); + parser.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678"); + assert_eq!(parser.screen().cursor_position(), (0, 79)); + parser.process(b"9"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789"); + assert_eq!(parser.screen().cursor_position(), (0, 80)); + parser.process(b"a"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789a"); + assert_eq!(parser.screen().cursor_position(), (1, 1)); + parser.process(b"b"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "01234567890123456789012345678901234567890123456789012345678901234567890123456789ab"); + assert_eq!(parser.screen().cursor_position(), (1, 2)); - screen.process(b"\x1b[H\x1b[J"); - screen.process(b"012345678901234567890123456789012345678901234567890123456789012345678901234567"); - assert_eq!(screen.contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567"); - assert_eq!(screen.cursor_position(), (0, 78)); - screen.process("ネ".as_bytes()); - assert_eq!(screen.contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567ネ"); - assert_eq!(screen.cursor_position(), (0, 80)); - screen.process(b"a"); - assert_eq!(screen.contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567ネa"); - assert_eq!(screen.cursor_position(), (1, 1)); - assert_eq!(screen.cell(0, 77).unwrap().contents(), "7"); - assert_eq!(screen.cell(0, 78).unwrap().contents(), "ネ"); - assert_eq!(screen.cell(0, 79).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 1).unwrap().contents(), ""); + parser.process(b"\x1b[H\x1b[J"); + parser.process(b"012345678901234567890123456789012345678901234567890123456789012345678901234567"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567"); + assert_eq!(parser.screen().cursor_position(), (0, 78)); + parser.process("ネ".as_bytes()); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567ネ"); + assert_eq!(parser.screen().cursor_position(), (0, 80)); + parser.process(b"a"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "012345678901234567890123456789012345678901234567890123456789012345678901234567ネa"); + assert_eq!(parser.screen().cursor_position(), (1, 1)); + assert_eq!(parser.screen().cell(0, 77).unwrap().contents(), "7"); + assert_eq!(parser.screen().cell(0, 78).unwrap().contents(), "ネ"); + assert_eq!(parser.screen().cell(0, 79).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), ""); - screen.process(b"\x1b[H\x1b[J"); - screen.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678"); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678"); - assert_eq!(screen.cursor_position(), (0, 79)); - screen.process("ネ".as_bytes()); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678ネ"); - assert_eq!(screen.cursor_position(), (1, 2)); - screen.process(b"a"); - assert_eq!(screen.contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678ネa"); - assert_eq!(screen.cursor_position(), (1, 3)); - assert_eq!(screen.cell(0, 77).unwrap().contents(), "7"); - assert_eq!(screen.cell(0, 78).unwrap().contents(), "8"); - assert_eq!(screen.cell(0, 79).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 0).unwrap().contents(), "ネ"); - assert_eq!(screen.cell(1, 1).unwrap().contents(), ""); - assert_eq!(screen.cell(1, 2).unwrap().contents(), "a"); - assert_eq!(screen.cell(1, 3).unwrap().contents(), ""); + parser.process(b"\x1b[H\x1b[J"); + parser.process(b"0123456789012345678901234567890123456789012345678901234567890123456789012345678"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678"); + assert_eq!(parser.screen().cursor_position(), (0, 79)); + parser.process("ネ".as_bytes()); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678ネ"); + assert_eq!(parser.screen().cursor_position(), (1, 2)); + parser.process(b"a"); + assert_eq!(parser.screen().contents(0, 0, 23, 79), "0123456789012345678901234567890123456789012345678901234567890123456789012345678ネa"); + assert_eq!(parser.screen().cursor_position(), (1, 3)); + assert_eq!(parser.screen().cell(0, 77).unwrap().contents(), "7"); + assert_eq!(parser.screen().cell(0, 78).unwrap().contents(), "8"); + assert_eq!(parser.screen().cell(0, 79).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "ネ"); + assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), ""); + assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), ""); } #[test] fn soft_hyphen() { - let mut screen = vt100::Screen::new(24, 140); - screen.process(b"Free En\xc2\xadter\xc2\xadprise is gonna ru\xc2\xadin ev\xc2\xadery\xc2\xadthing good un\xc2\xadless we take a knife to its tes\xc2\xadti\xc2\xadcles first."); - assert_eq!(screen.contents(0, 0, 0, 139), "Free En\u{00ad}ter\u{00ad}prise is gonna ru\u{00ad}in ev\u{00ad}ery\u{00ad}thing good un\u{00ad}less we take a knife to its tes\u{00ad}ti\u{00ad}cles first."); - assert_eq!(screen.cell(0, 0).unwrap().contents(), "F"); - assert_eq!(screen.cell(0, 1).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 2).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 3).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 4).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 5).unwrap().contents(), "E"); - assert_eq!(screen.cell(0, 6).unwrap().contents(), "n\u{00ad}"); - assert_eq!(screen.cell(0, 7).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 8).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 9).unwrap().contents(), "r\u{00ad}"); - assert_eq!(screen.cell(0, 10).unwrap().contents(), "p"); - assert_eq!(screen.cell(0, 11).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 12).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 13).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 14).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 15).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 16).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 17).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 18).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 19).unwrap().contents(), "g"); - assert_eq!(screen.cell(0, 20).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 21).unwrap().contents(), "n"); - assert_eq!(screen.cell(0, 22).unwrap().contents(), "n"); - assert_eq!(screen.cell(0, 23).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 24).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 25).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 26).unwrap().contents(), "u\u{00ad}"); - assert_eq!(screen.cell(0, 27).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 28).unwrap().contents(), "n"); - assert_eq!(screen.cell(0, 29).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 30).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 31).unwrap().contents(), "v\u{00ad}"); - assert_eq!(screen.cell(0, 32).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 33).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 34).unwrap().contents(), "y\u{00ad}"); - assert_eq!(screen.cell(0, 35).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 36).unwrap().contents(), "h"); - assert_eq!(screen.cell(0, 37).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 38).unwrap().contents(), "n"); - assert_eq!(screen.cell(0, 39).unwrap().contents(), "g"); - assert_eq!(screen.cell(0, 40).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 41).unwrap().contents(), "g"); - assert_eq!(screen.cell(0, 42).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 43).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 44).unwrap().contents(), "d"); - assert_eq!(screen.cell(0, 45).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 46).unwrap().contents(), "u"); - assert_eq!(screen.cell(0, 47).unwrap().contents(), "n\u{00ad}"); - assert_eq!(screen.cell(0, 48).unwrap().contents(), "l"); - assert_eq!(screen.cell(0, 49).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 50).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 51).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 52).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 53).unwrap().contents(), "w"); - assert_eq!(screen.cell(0, 54).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 55).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 56).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 57).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 58).unwrap().contents(), "k"); - assert_eq!(screen.cell(0, 59).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 60).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 61).unwrap().contents(), "a"); - assert_eq!(screen.cell(0, 62).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 63).unwrap().contents(), "k"); - assert_eq!(screen.cell(0, 64).unwrap().contents(), "n"); - assert_eq!(screen.cell(0, 65).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 66).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 67).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 68).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 69).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 70).unwrap().contents(), "o"); - assert_eq!(screen.cell(0, 71).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 72).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 73).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 74).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 75).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 76).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 77).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 78).unwrap().contents(), "s\u{00ad}"); - assert_eq!(screen.cell(0, 79).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 80).unwrap().contents(), "i\u{00ad}"); - assert_eq!(screen.cell(0, 81).unwrap().contents(), "c"); - assert_eq!(screen.cell(0, 82).unwrap().contents(), "l"); - assert_eq!(screen.cell(0, 83).unwrap().contents(), "e"); - assert_eq!(screen.cell(0, 84).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 85).unwrap().contents(), " "); - assert_eq!(screen.cell(0, 86).unwrap().contents(), "f"); - assert_eq!(screen.cell(0, 87).unwrap().contents(), "i"); - assert_eq!(screen.cell(0, 88).unwrap().contents(), "r"); - assert_eq!(screen.cell(0, 89).unwrap().contents(), "s"); - assert_eq!(screen.cell(0, 90).unwrap().contents(), "t"); - assert_eq!(screen.cell(0, 91).unwrap().contents(), "."); + let mut parser = vt100::Parser::new(24, 140); + parser.process(b"Free En\xc2\xadter\xc2\xadprise is gonna ru\xc2\xadin ev\xc2\xadery\xc2\xadthing good un\xc2\xadless we take a knife to its tes\xc2\xadti\xc2\xadcles first."); + assert_eq!(parser.screen().contents(0, 0, 0, 139), "Free En\u{00ad}ter\u{00ad}prise is gonna ru\u{00ad}in ev\u{00ad}ery\u{00ad}thing good un\u{00ad}less we take a knife to its tes\u{00ad}ti\u{00ad}cles first."); + assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "F"); + assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "E"); + assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), "n\u{00ad}"); + assert_eq!(parser.screen().cell(0, 7).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 8).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 9).unwrap().contents(), "r\u{00ad}"); + assert_eq!(parser.screen().cell(0, 10).unwrap().contents(), "p"); + assert_eq!(parser.screen().cell(0, 11).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 12).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 13).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 14).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 15).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 16).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 17).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 18).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 19).unwrap().contents(), "g"); + assert_eq!(parser.screen().cell(0, 20).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 21).unwrap().contents(), "n"); + assert_eq!(parser.screen().cell(0, 22).unwrap().contents(), "n"); + assert_eq!(parser.screen().cell(0, 23).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 24).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 25).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 26).unwrap().contents(), "u\u{00ad}"); + assert_eq!(parser.screen().cell(0, 27).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 28).unwrap().contents(), "n"); + assert_eq!(parser.screen().cell(0, 29).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 30).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 31).unwrap().contents(), "v\u{00ad}"); + assert_eq!(parser.screen().cell(0, 32).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 33).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 34).unwrap().contents(), "y\u{00ad}"); + assert_eq!(parser.screen().cell(0, 35).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 36).unwrap().contents(), "h"); + assert_eq!(parser.screen().cell(0, 37).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 38).unwrap().contents(), "n"); + assert_eq!(parser.screen().cell(0, 39).unwrap().contents(), "g"); + assert_eq!(parser.screen().cell(0, 40).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 41).unwrap().contents(), "g"); + assert_eq!(parser.screen().cell(0, 42).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 43).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 44).unwrap().contents(), "d"); + assert_eq!(parser.screen().cell(0, 45).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 46).unwrap().contents(), "u"); + assert_eq!(parser.screen().cell(0, 47).unwrap().contents(), "n\u{00ad}"); + assert_eq!(parser.screen().cell(0, 48).unwrap().contents(), "l"); + assert_eq!(parser.screen().cell(0, 49).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 50).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 51).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 52).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 53).unwrap().contents(), "w"); + assert_eq!(parser.screen().cell(0, 54).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 55).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 56).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 57).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 58).unwrap().contents(), "k"); + assert_eq!(parser.screen().cell(0, 59).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 60).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 61).unwrap().contents(), "a"); + assert_eq!(parser.screen().cell(0, 62).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 63).unwrap().contents(), "k"); + assert_eq!(parser.screen().cell(0, 64).unwrap().contents(), "n"); + assert_eq!(parser.screen().cell(0, 65).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 66).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 67).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 68).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 69).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 70).unwrap().contents(), "o"); + assert_eq!(parser.screen().cell(0, 71).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 72).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 73).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 74).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 75).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 76).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 77).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 78).unwrap().contents(), "s\u{00ad}"); + assert_eq!(parser.screen().cell(0, 79).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 80).unwrap().contents(), "i\u{00ad}"); + assert_eq!(parser.screen().cell(0, 81).unwrap().contents(), "c"); + assert_eq!(parser.screen().cell(0, 82).unwrap().contents(), "l"); + assert_eq!(parser.screen().cell(0, 83).unwrap().contents(), "e"); + assert_eq!(parser.screen().cell(0, 84).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 85).unwrap().contents(), " "); + assert_eq!(parser.screen().cell(0, 86).unwrap().contents(), "f"); + assert_eq!(parser.screen().cell(0, 87).unwrap().contents(), "i"); + assert_eq!(parser.screen().cell(0, 88).unwrap().contents(), "r"); + assert_eq!(parser.screen().cell(0, 89).unwrap().contents(), "s"); + assert_eq!(parser.screen().cell(0, 90).unwrap().contents(), "t"); + assert_eq!(parser.screen().cell(0, 91).unwrap().contents(), "."); } diff --git a/tests/weird.rs b/tests/weird.rs index 20cc571..6719644 100644 --- a/tests/weird.rs +++ b/tests/weird.rs @@ -1,17 +1,17 @@ #[test] fn intermediate_control() { - let mut screen = vt100::Screen::new(24, 80); - assert_eq!(screen.cursor_position(), (0, 0)); + let mut parser = vt100::Parser::new(24, 80); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\x1b"); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"\x1b"); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"["); - assert_eq!(screen.cursor_position(), (0, 0)); + parser.process(b"["); + assert_eq!(parser.screen().cursor_position(), (0, 0)); - screen.process(b"\n"); - assert_eq!(screen.cursor_position(), (1, 0)); + parser.process(b"\n"); + assert_eq!(parser.screen().cursor_position(), (1, 0)); - screen.process(b"C"); - assert_eq!(screen.cursor_position(), (1, 1)); + parser.process(b"C"); + assert_eq!(parser.screen().cursor_position(), (1, 1)); } diff --git a/tests/window_contents.rs b/tests/window_contents.rs index 9d7553e..898351e 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -1,75 +1,76 @@ #[test] fn formatted() { - let mut screen = vt100::Screen::new(24, 80); - compare_formatted(&screen); - assert_eq!(screen.contents_formatted(0, 0, 23, 79), ""); + let mut parser = vt100::Parser::new(24, 80); + compare_formatted(&parser); + assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), ""); - screen.process(b"foobar"); - compare_formatted(&screen); - assert!(!screen.cell(0, 2).unwrap().bold()); - assert!(!screen.cell(0, 3).unwrap().bold()); - assert!(!screen.cell(0, 4).unwrap().bold()); - assert!(!screen.cell(0, 5).unwrap().bold()); - assert_eq!(screen.contents_formatted(0, 0, 23, 79), "foobar"); + parser.process(b"foobar"); + compare_formatted(&parser); + assert!(!parser.screen().cell(0, 2).unwrap().bold()); + assert!(!parser.screen().cell(0, 3).unwrap().bold()); + assert!(!parser.screen().cell(0, 4).unwrap().bold()); + assert!(!parser.screen().cell(0, 5).unwrap().bold()); + assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), "foobar"); - screen.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb"); - compare_formatted(&screen); - assert!(!screen.cell(0, 2).unwrap().bold()); - assert!(screen.cell(0, 3).unwrap().bold()); - assert!(!screen.cell(0, 4).unwrap().bold()); - assert!(!screen.cell(0, 5).unwrap().bold()); + parser.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb"); + compare_formatted(&parser); + assert!(!parser.screen().cell(0, 2).unwrap().bold()); + assert!(parser.screen().cell(0, 3).unwrap().bold()); + assert!(!parser.screen().cell(0, 4).unwrap().bold()); + assert!(!parser.screen().cell(0, 5).unwrap().bold()); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "foo\x1b[33;1;7mb\x1b[mar" ); - screen.process(b"\x1b[1;5H\x1b[22;42ma"); - compare_formatted(&screen); - assert!(!screen.cell(0, 2).unwrap().bold()); - assert!(screen.cell(0, 3).unwrap().bold()); - assert!(!screen.cell(0, 4).unwrap().bold()); - assert!(!screen.cell(0, 5).unwrap().bold()); + parser.process(b"\x1b[1;5H\x1b[22;42ma"); + compare_formatted(&parser); + assert!(!parser.screen().cell(0, 2).unwrap().bold()); + assert!(parser.screen().cell(0, 3).unwrap().bold()); + assert!(!parser.screen().cell(0, 4).unwrap().bold()); + assert!(!parser.screen().cell(0, 5).unwrap().bold()); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr" ); - screen.process(b"\x1b[1;6H\x1b[35mr\r\nquux"); - compare_formatted(&screen); + parser.process(b"\x1b[1;6H\x1b[35mr\r\nquux"); + compare_formatted(&parser); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux" ); - screen.process(b"\x1b[2;1H\x1b[45mquux"); - compare_formatted(&screen); + parser.process(b"\x1b[2;1H\x1b[45mquux"); + compare_formatted(&parser); assert_eq!( - screen.contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(0, 0, 23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux" ); - screen + parser .process(b"\x1b[2;2H\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx"); - compare_formatted(&screen); - assert_eq!(screen.contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mq\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx"); + compare_formatted(&parser); + assert_eq!(parser.screen().contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mq\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx"); } -fn compare_formatted(screen: &vt100::Screen) { - let (rows, cols) = screen.size(); - let contents = screen.contents_formatted(0, 0, rows - 1, cols - 1); - let mut screen2 = vt100::Screen::new(rows, cols); - screen2.process(contents.as_bytes()); - compare_cells(screen, &screen2); +fn compare_formatted(parser: &vt100::Parser) { + let (rows, cols) = parser.screen().size(); + let contents = + parser.screen().contents_formatted(0, 0, rows - 1, cols - 1); + let mut parser2 = vt100::Parser::new(rows, cols); + parser2.process(contents.as_bytes()); + compare_cells(parser, &parser2); } -fn compare_cells(screen1: &vt100::Screen, screen2: &vt100::Screen) { - assert_eq!(screen1.size(), screen2.size()); - let (rows, cols) = screen1.size(); +fn compare_cells(parser1: &vt100::Parser, parser2: &vt100::Parser) { + assert_eq!(parser1.screen().size(), parser2.screen().size()); + let (rows, cols) = parser1.screen().size(); for row in 0..rows { for col in 0..cols { - let cell1 = screen1.cell(row, col).unwrap(); - let cell2 = screen2.cell(row, col).unwrap(); + let cell1 = parser1.screen().cell(row, col).unwrap(); + let cell2 = parser2.screen().cell(row, col).unwrap(); assert_eq!(cell1.contents(), cell2.contents()); assert_eq!(cell1.fgcolor(), cell2.fgcolor()); |