aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-06 03:03:15 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-06 03:03:15 -0500
commitbf8c3de0e5d945167645ecfd4f6de18e048f356c (patch)
treec22fbf031cda06c1169a5be790cd87f04e0b9797
parent7e7f4a10930498c2d576c7103054408a0915370e (diff)
downloadvt100-rust-bf8c3de0e5d945167645ecfd4f6de18e048f356c.tar.gz
vt100-rust-bf8c3de0e5d945167645ecfd4f6de18e048f356c.zip
contents_formatted should additionally clear the screen
-rw-r--r--src/grid.rs2
-rw-r--r--tests/escape.rs12
-rw-r--r--tests/init.rs2
-rw-r--r--tests/window_contents.rs17
4 files changed, 17 insertions, 16 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 218247e..1f1100d 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -137,7 +137,7 @@ impl Grid {
}
pub fn contents_formatted(&self) -> Vec<u8> {
- let mut contents = vec![];
+ let mut contents = b"\x1b[H\x1b[J".to_vec();
let mut prev_attrs = crate::attrs::Attrs::default();
let mut final_col = 0;
for row in self.rows() {
diff --git a/tests/escape.rs b/tests/escape.rs
index fcd4e6b..94fca09 100644
--- a/tests/escape.rs
+++ b/tests/escape.rs
@@ -26,7 +26,7 @@ fn ris() {
assert_eq!(cell.contents(), "");
assert_eq!(parser.screen().contents(), "");
- assert_eq!(parser.screen().contents_formatted(), b"");
+ assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J");
assert_eq!(parser.screen().title(), "");
assert_eq!(parser.screen().icon_name(), "");
@@ -64,7 +64,7 @@ fn ris() {
assert_eq!(parser.screen().contents(), "foo");
assert_eq!(
parser.screen().contents_formatted(),
- b"\x1b[?25lf\x1b[31;47;1;3;4moo\x1b[21;21H"
+ &b"\x1b[?25l\x1b[H\x1b[Jf\x1b[31;47;1;3;4moo\x1b[21;21H"[..]
);
assert_eq!(parser.screen().title(), "window title");
@@ -100,7 +100,7 @@ fn ris() {
assert_eq!(cell.contents(), "");
assert_eq!(parser.screen().contents(), "");
- assert_eq!(parser.screen().contents_formatted(), b"");
+ assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J");
// title and icon name don't change with reset
assert_eq!(parser.screen().title(), "window title");
@@ -165,20 +165,20 @@ fn decsc() {
assert_eq!(parser.screen().cursor_position(), (4, 3));
assert_eq!(
parser.screen().contents_formatted(),
- b"\r\n\r\n\r\n\r\n\x1b[31mfoo"
+ b"\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[32mbar\r\n\r\n\r\n\r\n\x1b[31mfoo\x1b[1;4H"
+ &b"\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[32mbar\r\n\r\n\r\n\r\n\x1b[31mzoo\x1b[5;2H"
+ &b"\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 9647765..5623cd8 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -16,7 +16,7 @@ fn init() {
assert!(cell.is_none());
assert_eq!(parser.screen().contents(), "");
- assert_eq!(parser.screen().contents_formatted(), b"");
+ assert_eq!(parser.screen().contents_formatted(), b"\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 ed15517..c836f02 100644
--- a/tests/window_contents.rs
+++ b/tests/window_contents.rs
@@ -4,7 +4,7 @@ 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"");
+ assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[J");
parser.process(b"foobar");
compare_formatted(parser.screen());
@@ -12,7 +12,7 @@ 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"foobar");
+ assert_eq!(parser.screen().contents_formatted(), b"\x1b[H\x1b[Jfoobar");
parser.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb");
compare_formatted(parser.screen());
@@ -22,7 +22,7 @@ fn formatted() {
assert!(!parser.screen().cell(0, 5).unwrap().bold());
assert_eq!(
parser.screen().contents_formatted(),
- b"foo\x1b[33;1;7mb\x1b[mar\x1b[1;5H"
+ b"\x1b[H\x1b[Jfoo\x1b[33;1;7mb\x1b[mar\x1b[1;5H"
);
parser.process(b"\x1b[1;5H\x1b[22;42ma");
@@ -33,27 +33,28 @@ fn formatted() {
assert!(!parser.screen().cell(0, 5).unwrap().bold());
assert_eq!(
parser.screen().contents_formatted(),
- b"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr\x1b[1;6H"
+ &b"\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"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux"[..]
+ &b"\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"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\n\x1b[45mquux"[..]
+ &b"\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"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"[..]);
+ 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"[..]);
}
#[test]
@@ -64,7 +65,7 @@ fn empty_cells() {
assert_eq!(parser.screen().contents(), "foo bar");
assert_eq!(
parser.screen().contents_formatted(),
- b"\x1b[31mfoo\x1b[m\x1b[C\x1b[C\x1b[32m bar\x1b[1;4H"
+ &b"\x1b[H\x1b[J\x1b[31mfoo\x1b[m\x1b[C\x1b[C\x1b[32m bar\x1b[1;4H"[..]
);
}