diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 12:53:25 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 13:26:49 -0500 |
commit | 2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd (patch) | |
tree | 8f31cb37faaec73bdf4a5253f0c34bceb3cc6d6f /tests/window_contents.rs | |
parent | e12f9d9ee4e6b902436d0282e4a1e47ed7d54d6c (diff) | |
download | vt100-rust-2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd.tar.gz vt100-rust-2e7f1686d719497d9b2d2d2c8ffba20e6c8214bd.zip |
adjust the way window contents are reported
contents and contents_formatted now only allow getting the entire
terminal contents, and for any other uses we now provide rows and
rows_formatted.
the reasoning here is that it wasn't particularly useful to return
newline (or crlf) separated lines when not drawing the full terminal,
since it's not like you can send those to the terminal in any meaningful
way anyway (like, if you wanted to draw a subset of the terminal state,
you'll almost certainly need to be doing explicit positioning on your
own, since crlf is only actually correct if you're drawing the screen
subset in the upper left hand corner of the screen). with this, you can
draw each (subset of a) line individually, and reposition the cursor in
whatever way makes sense in between drawing the lines.
Diffstat (limited to 'tests/window_contents.rs')
-rw-r--r-- | tests/window_contents.rs | 273 |
1 files changed, 262 insertions, 11 deletions
diff --git a/tests/window_contents.rs b/tests/window_contents.rs index d79f75a..ccf5342 100644 --- a/tests/window_contents.rs +++ b/tests/window_contents.rs @@ -2,7 +2,7 @@ fn formatted() { let mut parser = vt100::Parser::new(24, 80); compare_formatted(&parser); - assert_eq!(parser.screen().contents_formatted(0, 0, 23, 79), b""); + assert_eq!(parser.screen().contents_formatted(), b""); parser.process(b"foobar"); compare_formatted(&parser); @@ -10,7 +10,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(0, 0, 23, 79), b"foobar"); + assert_eq!(parser.screen().contents_formatted(), b"foobar"); parser.process(b"\x1b[1;4H\x1b[1;7m\x1b[33mb"); compare_formatted(&parser); @@ -19,7 +19,7 @@ fn formatted() { 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), + parser.screen().contents_formatted(), b"foo\x1b[33;1;7mb\x1b[mar" ); @@ -30,28 +30,28 @@ fn formatted() { 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), + parser.screen().contents_formatted(), b"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[mr" ); parser.process(b"\x1b[1;6H\x1b[35mr\r\nquux"); compare_formatted(&parser); assert_eq!( - parser.screen().contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(), &b"foo\x1b[33;1;7mb\x1b[42;22ma\x1b[35mr\r\nquux"[..] ); parser.process(b"\x1b[2;1H\x1b[45mquux"); compare_formatted(&parser); assert_eq!( - parser.screen().contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(), &b"foo\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); - assert_eq!(parser.screen().contents_formatted(0, 0 ,23, 79), &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"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"[..]); } #[test] @@ -59,17 +59,268 @@ fn empty_cells() { let mut parser = vt100::Parser::new(24, 80); parser.process(b"\x1b[5C\x1b[32m bar\x1b[H\x1b[31mfoo"); compare_formatted(&parser); - assert_eq!(parser.screen().contents(0, 0, 23, 79), "foo bar"); + assert_eq!(parser.screen().contents(), "foo bar"); assert_eq!( - parser.screen().contents_formatted(0, 0, 23, 79), + parser.screen().contents_formatted(), b"\x1b[31mfoo\x1b[m\x1b[C\x1b[C\x1b[32m bar" ); } +#[test] +fn rows() { + let mut parser = vt100::Parser::new(24, 80); + assert_eq!( + parser.screen().rows(0, 80).collect::<Vec<String>>(), + vec![ + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + ] + ); + assert_eq!( + parser + .screen() + .rows_formatted(0, 80) + .collect::<Vec<Vec<u8>>>(), + vec![ + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + ] + ); + assert_eq!( + parser.screen().rows(5, 15).collect::<Vec<String>>(), + vec![ + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + ] + ); + assert_eq!( + parser + .screen() + .rows_formatted(5, 15) + .collect::<Vec<Vec<u8>>>(), + vec![ + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + ] + ); + + parser + .process(b"\x1b[31mfoo\x1b[10;10H\x1b[32mbar\x1b[20;20H\x1b[33mbaz"); + assert_eq!( + parser.screen().rows(0, 80).collect::<Vec<String>>(), + vec![ + "foo".to_string(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + " bar".to_string(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + " baz".to_string(), + String::new(), + String::new(), + String::new(), + String::new(), + ] + ); + assert_eq!( + parser + .screen() + .rows_formatted(0, 80) + .collect::<Vec<Vec<u8>>>(), + vec![ + b"\x1b[31mfoo".to_vec(), + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + b"\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[32mbar".to_vec(), + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + b"\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[33mbaz".to_vec(), + vec![], + vec![], + vec![], + vec![], + ] + ); + assert_eq!( + parser.screen().rows(5, 15).collect::<Vec<String>>(), + vec![ + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + " bar".to_string(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + String::new(), + " b".to_string(), + String::new(), + String::new(), + String::new(), + String::new(), + ] + ); + assert_eq!( + parser + .screen() + .rows_formatted(5, 15) + .collect::<Vec<Vec<u8>>>(), + vec![ + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + b"\x1b[C\x1b[C\x1b[C\x1b[C\x1b[32mbar".to_vec(), + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + vec![], + b"\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[C\x1b[33mb".to_vec(), + vec![], + vec![], + vec![], + vec![], + ] + ); +} + 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 contents = parser.screen().contents_formatted(); let mut parser2 = vt100::Parser::new(rows, cols); parser2.process(&contents); compare_cells(parser, &parser2); |