diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-03 11:03:09 +0000 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-03 11:03:09 +0000 |
commit | ff65c812fcf3e46803bb3fbdc820d0006ea004c3 (patch) | |
tree | 2272aa538b11dfdc9348cb068a43d28b0bf32257 | |
parent | 6d8463ea1830acf98467e11a4bb676bd01fd4372 (diff) | |
download | vt100-rust-ff65c812fcf3e46803bb3fbdc820d0006ea004c3.tar.gz vt100-rust-ff65c812fcf3e46803bb3fbdc820d0006ea004c3.zip |
improve formatted output a bit
-rw-r--r-- | src/attrs.rs | 6 | ||||
-rw-r--r-- | tests/window_contents.rs | 26 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/attrs.rs b/src/attrs.rs index 7e27f5a..ef7bf38 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -78,6 +78,10 @@ impl Attrs { pub fn escape_code_diff(&self, other: &Self) -> String { let mut opts = vec![]; + if self != other && self == &Self::default() { + return "\x1b[m".to_string(); + } + if self.fgcolor != other.fgcolor { match self.fgcolor { Color::Default => { @@ -131,7 +135,7 @@ impl Attrs { } if self.bold() != other.bold() { - opts.push(if self.bold() { 1 } else { 21 }); + opts.push(if self.bold() { 1 } else { 22 }); } if self.italic() != other.italic() { opts.push(if self.italic() { 3 } else { 23 }); diff --git a/tests/window_contents.rs b/tests/window_contents.rs new file mode 100644 index 0000000..057cfb1 --- /dev/null +++ b/tests/window_contents.rs @@ -0,0 +1,26 @@ +#[test] +fn formatted() { + let mut screen = vt100::Screen::new(24, 80); + assert_eq!(screen.window_contents_formatted(0, 0 ,23, 79), "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + + screen.process(b"foobar"); + 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.window_contents_formatted(0, 0 ,23, 79), "foobar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + + screen.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb"); + 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.window_contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[mar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + + screen.process(b"\x1b[1;5H\x1b[22;42ma"); + 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.window_contents_formatted(0, 0 ,23, 79), "foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); +} |