diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-06 14:11:09 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-06 14:13:03 -0500 |
commit | 365d14de0ffe39aa7991bcb791c97c3aa97698b8 (patch) | |
tree | 4214ecb794bd2377adbe862a1d32e2b08674f5cd | |
parent | 35cb222004ad95a4acb6d1d24d5210b5267e3835 (diff) | |
download | vt100-rust-365d14de0ffe39aa7991bcb791c97c3aa97698b8.tar.gz vt100-rust-365d14de0ffe39aa7991bcb791c97c3aa97698b8.zip |
actually, we do need to always reset the hide cursor state
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | src/screen.rs | 8 | ||||
-rw-r--r-- | tests/escape.rs | 16 | ||||
-rw-r--r-- | tests/init.rs | 5 | ||||
-rw-r--r-- | tests/window_contents.rs | 24 |
5 files changed, 42 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ca03027..8d4f319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Fixed + +* Make `contents_formatted` explicitly show the cursor when necessary, in case + the cursor was previously hidden. + ## [0.3.0] - 2019-11-06 ### Added diff --git a/src/screen.rs b/src/screen.rs index 873eeb3..6ff11ad 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -156,10 +156,12 @@ impl Screen { /// mode) will not be included here, but modes that affect the visible /// output (such as hidden cursor mode) will. pub fn contents_formatted(&self) -> Vec<u8> { - let mut grid_contents = vec![]; - if self.hide_cursor() { - grid_contents.extend(b"\x1b[?25l"); + let mut grid_contents = if self.hide_cursor() { + b"\x1b[?25l" + } else { + b"\x1b[?25h" } + .to_vec(); grid_contents.append(&mut self.grid().contents_formatted()); grid_contents } diff --git a/tests/escape.rs b/tests/escape.rs index 94fca09..0ad92ed 100644 --- a/tests/escape.rs +++ b/tests/escape.rs @@ -26,7 +26,10 @@ fn ris() { assert_eq!(cell.contents(), ""); assert_eq!(parser.screen().contents(), ""); - assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J"); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[H\x1b[J" + ); assert_eq!(parser.screen().title(), ""); assert_eq!(parser.screen().icon_name(), ""); @@ -100,7 +103,10 @@ fn ris() { assert_eq!(cell.contents(), ""); assert_eq!(parser.screen().contents(), ""); - assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J"); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[H\x1b[J" + ); // title and icon name don't change with reset assert_eq!(parser.screen().title(), "window title"); @@ -165,20 +171,20 @@ fn decsc() { assert_eq!(parser.screen().cursor_position(), (4, 3)); assert_eq!( parser.screen().contents_formatted(), - b"\x1b[H\x1b[J\r\n\r\n\r\n\r\n\x1b[31mfoo" + b"\x1b[?25h\x1b[H\x1b[J\r\n\r\n\r\n\r\n\x1b[31mfoo" ); parser.process(b"\x1b[32m\x1b[?6lbar"); assert_eq!(parser.screen().cursor_position(), (0, 3)); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[J\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mfoo\x1b[1;4H"[..] + &b"\x1b[?25h\x1b[H\x1b[J\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mfoo\x1b[1;4H"[..] ); parser.process(b"\x1b8\x1b[Hz"); assert_eq!(parser.screen().cursor_position(), (4, 1)); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[J\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mzoo\x1b[5;2H"[..] + &b"\x1b[?25h\x1b[H\x1b[J\x1b[32mbar\r\n\r\n\r\n\r\n\x1b[31mzoo\x1b[5;2H"[..] ); } diff --git a/tests/init.rs b/tests/init.rs index 5623cd8..f76ec49 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -16,7 +16,10 @@ fn init() { assert!(cell.is_none()); assert_eq!(parser.screen().contents(), ""); - assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J"); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[H\x1b[J" + ); assert_eq!(parser.screen().title(), ""); assert_eq!(parser.screen().icon_name(), ""); diff --git a/tests/window_contents.rs b/tests/window_contents.rs index 07a656d..9b49421 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -4,7 +4,10 @@ use std::io::Read as _; fn formatted() { let mut parser = vt100::Parser::new(24, 80); compare_formatted(parser.screen()); - assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J"); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[H\x1b[J" + ); parser.process(b"foobar"); compare_formatted(parser.screen()); @@ -12,7 +15,10 @@ fn formatted() { 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(), b"\x1b[H\x1b[Jfoobar"); + assert_eq!( + parser.screen().contents_formatted(), + b"\x1b[?25h\x1b[H\x1b[Jfoobar" + ); parser.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb"); compare_formatted(parser.screen()); @@ -22,7 +28,7 @@ fn formatted() { assert!(!parser.screen().cell(0, 5).unwrap().bold()); assert_eq!( parser.screen().contents_formatted(), - b"\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[mar\x1b[1;5H" + &b"\x1b[?25h\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[mar\x1b[1;5H"[..] ); parser.process(b"\x1b[1;5H\x1b[22;42ma"); @@ -33,28 +39,28 @@ fn formatted() { assert!(!parser.screen().cell(0, 5).unwrap().bold()); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr\x1b[1;6H"[..] + &b"\x1b[?25h\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr\x1b[1;6H" + [..] ); parser.process(b"\x1b[1;6H\x1b[35mr\r\nquux"); compare_formatted(parser.screen()); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux"[..] + &b"\x1b[?25h\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux"[..] ); parser.process(b"\x1b[2;1H\x1b[45mquux"); compare_formatted(parser.screen()); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux" - [..] + &b"\x1b[?25h\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux"[..] ); parser .process(b"\x1b[2;2H\x1b[38;2;123;213;231mu\x1b[38;5;254mu\x1b[39mx"); compare_formatted(parser.screen()); - assert_eq!(parser.screen().contents_formatted(), &b"\x1b[H\x1b[Jfoo\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"[..]); + assert_eq!(parser.screen().contents_formatted(), &b"\x1b[?25h\x1b[H\x1b[Jfoo\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"[..]); } #[test] @@ -65,7 +71,7 @@ fn empty_cells() { assert_eq!(parser.screen().contents(), "foo bar"); assert_eq!( parser.screen().contents_formatted(), - &b"\x1b[H\x1b[J\x1b[31mfoo\x1b[m\x1b[C\x1b[C\x1b[32m bar\x1b[1;4H"[..] + &b"\x1b[?25h\x1b[H\x1b[J\x1b[31mfoo\x1b[m\x1b[C\x1b[C\x1b[32m bar\x1b[1;4H"[..] ); } |