From e3f1d15f5dec0bb53c350c785ef7027fd9b8fdcc Mon Sep 17 00:00:00 2001 From: Autumn Lamonte Date: Fri, 9 Jul 2021 17:56:23 -0500 Subject: [PATCH] #133 unit tests --- term/src/test/mod.rs | 20 ++++++++++++++++ termwiz/src/escape/csi.rs | 34 +++++++++++++++++++++++++++- termwiz/src/escape/esc.rs | 7 ++++++ wezterm-gui/src/termwindow/render.rs | 4 +--- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/term/src/test/mod.rs b/term/src/test/mod.rs index b1e83b135..119d74f72 100644 --- a/term/src/test/mod.rs +++ b/term/src/test/mod.rs @@ -695,6 +695,26 @@ fn test_dec_special_graphics() { ); } +/// Test double-width / double-height sequences. +#[test] +fn test_dec_double_width() { + let mut term = TestTerm::new(4, 50, 0); + + term.print("\u{1b}#3line1\r\nline2\u{1b}#4\r\nli\u{1b}#6ne3\r\n\u{1b}#5line4"); + assert_visible_contents( + &term, + file!(), + line!(), + &["line1", "line2", "line3", "line4"], + ); + + let lines = term.screen().visible_lines(); + assert!(lines[0].is_double_height_top()); + assert!(lines[1].is_double_height_bottom()); + assert!(lines[2].is_double_width()); + assert!(lines[3].is_single_width()); +} + /// Test the behavior of wrapped lines when we resize the terminal /// wider and then narrower. #[test] diff --git a/termwiz/src/escape/csi.rs b/termwiz/src/escape/csi.rs index 841d73512..8bc69477a 100644 --- a/termwiz/src/escape/csi.rs +++ b/termwiz/src/escape/csi.rs @@ -591,7 +591,7 @@ impl Display for Mode { TerminalMode::Code(mode) => mode.to_u16().ok_or_else(|| FmtError)?, TerminalMode::Unspecified(mode) => *mode, }; - write!(f, "?{}{}", value, $flag) + write!(f, "{}{}", value, $flag) }}; } match self { @@ -2443,6 +2443,22 @@ mod test { ); } + #[test] + fn blinks() { + assert_eq!( + parse('m', &[5], "\x1b[5m"), + vec![CSI::Sgr(Sgr::Blink(Blink::Slow))] + ); + assert_eq!( + parse('m', &[6], "\x1b[6m"), + vec![CSI::Sgr(Sgr::Blink(Blink::Rapid))] + ); + assert_eq!( + parse('m', &[25], "\x1b[25m"), + vec![CSI::Sgr(Sgr::Blink(Blink::None))] + ); + } + #[test] fn underlines() { assert_eq!( @@ -2603,6 +2619,22 @@ mod test { ); } + #[test] + fn ansiset() { + assert_eq!( + parse('h', &[20], "\x1b[20h"), + vec![CSI::Mode(Mode::SetMode(TerminalMode::Code( + TerminalModeCode::AutomaticNewline + )))] + ); + assert_eq!( + parse('l', &[20], "\x1b[20l"), + vec![CSI::Mode(Mode::ResetMode(TerminalMode::Code( + TerminalModeCode::AutomaticNewline + )))] + ); + } + #[test] fn mouse() { let res: Vec<_> = CSI::parse( diff --git a/termwiz/src/escape/esc.rs b/termwiz/src/escape/esc.rs index f18d31ed9..d4e98e91e 100644 --- a/termwiz/src/escape/esc.rs +++ b/termwiz/src/escape/esc.rs @@ -192,5 +192,12 @@ mod test { assert_eq!(parse("(B"), Esc::Code(EscCode::AsciiCharacterSetG0)); assert_eq!(parse(")0"), Esc::Code(EscCode::DecLineDrawingG1)); assert_eq!(parse(")B"), Esc::Code(EscCode::AsciiCharacterSetG1)); + assert_eq!(parse("#3"), Esc::Code(EscCode::DecDoubleHeightTopHalfLine)); + assert_eq!( + parse("#4"), + Esc::Code(EscCode::DecDoubleHeightBottomHalfLine) + ); + assert_eq!(parse("#5"), Esc::Code(EscCode::DecSingleWidthLine)); + assert_eq!(parse("#6"), Esc::Code(EscCode::DecDoubleWidthLine)); } } diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index 728cf47a2..ec5d6e896 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -743,9 +743,7 @@ impl super::TermWindow { let mut bg_default = bg_is_default; // Check the line reverse_video flag and flip. - if (attrs.reverse() && !params.line.is_reverse()) - || (!attrs.reverse() && params.line.is_reverse()) - { + if attrs.reverse() == !params.line.is_reverse() { std::mem::swap(&mut fg, &mut bg); bg_default = false; }