aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mode.rs
blob: 19658b270050c5dd89aa899e475a391cde097a83 (plain) (blame)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
extern crate vt100;

mod support;
use support::TestHelpers;

#[test]
fn modes() {
    let mut screen = vt100::Screen::new(24, 80);
    assert!(!screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1h");

    assert!(!screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?9h");

    assert!(!screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?25l");

    assert!(screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1000h");

    assert!(screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1002h");

    assert!(screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1006h");

    assert!(screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b[?2004h");

    assert!(screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b=");

    assert!(screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1l");

    assert!(screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?9l");

    assert!(screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?25h");

    assert!(!screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1000l");

    assert!(!screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1002l");

    assert!(!screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?1006l");

    assert!(!screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(screen.bracketed_paste());

    screen.assert_process(b"\x1b[?2004l");

    assert!(!screen.hide_cursor());
    assert!(screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());

    screen.assert_process(b"\x1b>");

    assert!(!screen.hide_cursor());
    assert!(!screen.application_keypad());
    assert!(!screen.application_cursor());
    assert!(!screen.mouse_reporting_press());
    assert!(!screen.mouse_reporting_press_release());
    assert!(!screen.mouse_reporting_button_motion());
    assert!(!screen.mouse_reporting_sgr_mode());
    assert!(!screen.bracketed_paste());
}

#[test]
fn alternate_buffer() {
    let mut screen = vt100::Screen::new(24, 80);
    screen.assert_process(b"\x1b[m\x1b[2J\x1b[H1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24");
    assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n");
    assert!(!screen.alternate_buffer_active());
    screen.assert_process(b"\x1b[?1049h");
    assert_eq!(screen.window_contents(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");
    assert!(screen.alternate_buffer_active());
    screen.assert_process(b"foobar");
    assert_eq!(screen.window_contents(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.assert_process(b"\x1b[?1049l");
    assert_eq!(screen.window_contents(0, 0, 23, 79), "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n");
    assert!(!screen.alternate_buffer_active());
}