1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#![allow(clippy::cognitive_complexity)]
#[test]
fn bel() {
let mut parser = vt100::Parser::default();
assert_eq!(parser.screen().audible_bell_count(), 0);
let screen = parser.screen().clone();
parser.process(b"\x07");
assert_eq!(parser.screen().audible_bell_count(), 1);
assert_eq!(parser.screen().audible_bell_count(), 1);
assert_eq!(parser.screen().contents_diff(&screen), b"");
assert_eq!(parser.screen().bells_diff(&screen), b"\x07");
let screen = parser.screen().clone();
parser.process(b"\x07");
assert_eq!(parser.screen().audible_bell_count(), 2);
assert_eq!(parser.screen().contents_diff(&screen), b"");
assert_eq!(parser.screen().bells_diff(&screen), b"\x07");
let screen = parser.screen().clone();
parser.process(b"\x07\x07\x07");
assert_eq!(parser.screen().audible_bell_count(), 5);
assert_eq!(parser.screen().contents_diff(&screen), b"");
assert_eq!(parser.screen().bells_diff(&screen), b"\x07");
let screen = parser.screen().clone();
parser.process(b"foo");
assert_eq!(parser.screen().audible_bell_count(), 5);
assert_eq!(parser.screen().contents_diff(&screen), b"foo");
assert_eq!(parser.screen().bells_diff(&screen), b"");
let screen = parser.screen().clone();
parser.process(b"ba\x07r");
assert_eq!(parser.screen().audible_bell_count(), 6);
assert_eq!(parser.screen().contents_diff(&screen), b"bar");
assert_eq!(parser.screen().bells_diff(&screen), b"\x07");
}
#[test]
fn bs() {
let mut parser = vt100::Parser::default();
parser.process(b"foo\x08\x08aa");
assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f");
assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "");
assert_eq!(parser.screen().contents(), "faa");
parser.process(b"\r\nquux\x08\x08\x08\x08\x08\x08bar");
assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "b");
assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "r");
assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "x");
assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), "");
assert_eq!(parser.screen().cell(2, 0).unwrap().contents(), "");
assert_eq!(parser.screen().contents(), "faa\nbarx");
}
#[test]
fn tab() {
let mut parser = vt100::Parser::default();
parser.process(b"foo\tbar");
assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f");
assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o");
assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o");
assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "");
assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "");
assert_eq!(parser.screen().cell(0, 5).unwrap().contents(), "");
assert_eq!(parser.screen().cell(0, 6).unwrap().contents(), "");
assert_eq!(parser.screen().cell(0, 7).unwrap().contents(), "");
assert_eq!(parser.screen().cell(0, 8).unwrap().contents(), "b");
assert_eq!(parser.screen().cell(0, 9).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(0, 10).unwrap().contents(), "r");
assert_eq!(parser.screen().cell(0, 11).unwrap().contents(), "");
assert_eq!(parser.screen().contents(), "foo bar");
}
fn lf_with(b: u8) {
let mut parser = vt100::Parser::default();
parser.process(b"foo");
parser.process(&[b]);
parser.process(b"bar");
assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "f");
assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "o");
assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "o");
assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 1).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 2).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 3).unwrap().contents(), "b");
assert_eq!(parser.screen().cell(1, 4).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(1, 5).unwrap().contents(), "r");
assert_eq!(parser.screen().cell(1, 6).unwrap().contents(), "");
assert_eq!(parser.screen().contents(), "foo\n bar");
parser.process(b"\x1b[H\x1b[J\x1b[4;80H");
assert_eq!(parser.screen().cursor_position(), (3, 79));
parser.process(b"a");
assert_eq!(parser.screen().cursor_position(), (3, 80));
// note: this is a behavior that terminals disagree on - xterm and urxvt
// would leave the cursor at (4, 79) here, but alacritty, tmux, and screen
// put it at (4, 80). in general, i'm aiming for roughly tmux/screen
// compat where possible, so that's what i'm going with here.
parser.process(&[b]);
assert_eq!(parser.screen().cursor_position(), (4, 80));
parser.process(b"b");
assert_eq!(parser.screen().cursor_position(), (5, 1));
}
#[test]
fn lf() {
lf_with(b'\x0a');
}
#[test]
fn vt() {
lf_with(b'\x0b');
}
#[test]
fn ff() {
lf_with(b'\x0c');
}
#[test]
fn cr() {
let mut parser = vt100::Parser::default();
parser.process(b"fooo\rbar");
assert_eq!(parser.screen().cell(0, 0).unwrap().contents(), "b");
assert_eq!(parser.screen().cell(0, 1).unwrap().contents(), "a");
assert_eq!(parser.screen().cell(0, 2).unwrap().contents(), "r");
assert_eq!(parser.screen().cell(0, 3).unwrap().contents(), "o");
assert_eq!(parser.screen().cell(0, 4).unwrap().contents(), "");
assert_eq!(parser.screen().cell(1, 0).unwrap().contents(), "");
assert_eq!(parser.screen().contents(), "baro");
}
|