Debian Codegraph @

vt/tests/emulate_test.go

raw symbols SCIP
1 // Copyright 2026 The TCell Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package tests
16
17 import (
18 "encoding/base64"
19 "fmt"
20 "testing"
21
22 "github.com/gdamore/tcell/v3/color"
23 "github.com/gdamore/tcell/v3/vt"
24 )
25
26 // This file implements various tests of the emulator. Much of these tests
27 // are "borrowed" (ported from) the tests from Ghostty - https://ghostty.org/docs/vt
28 // Note that Ghostty's tests assume that STTY modes to expand LF to CF LF are in
29 // effect (or ANSI mode 20.) We don't assume that, and add the CR explicitly.
30
31 // TestDECSTBMv1 tests full screen scroll region
32 func TestDECSTBMv1(t *testing.T) {
33 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
34 defer MustClose(t, term)
35 MustStart(t, term)
36
37 WriteF(t, term, "\033[1;1H") // move to top-left
38 WriteF(t, term, "\033[0J") // clear screen
39 WriteF(t, term, "ABC\r\n")
40 WriteF(t, term, "DEF\r\n")
41 WriteF(t, term, "GHI\r\n")
42 WriteF(t, term, "\033[r") // scroll region top/bottom
43 WriteF(t, term, "\033[T") // scroll down one
44
45 // |c_______|
46 // |ABC_____|
47 // |DEF_____|
48 // |GHI_____|
49 CheckPos(t, term, 0, 0)
50 CheckContent(t, term, 0, 0, "")
51 CheckContent(t, term, 1, 0, "")
52 CheckContent(t, term, 2, 0, "")
53 CheckContent(t, term, 0, 1, "A")
54 CheckContent(t, term, 1, 1, "B")
55 CheckContent(t, term, 2, 1, "C")
56 CheckContent(t, term, 0, 2, "D")
57 CheckContent(t, term, 1, 2, "E")
58 CheckContent(t, term, 2, 2, "F")
59 CheckContent(t, term, 0, 3, "G")
60 CheckContent(t, term, 1, 3, "H")
61 CheckContent(t, term, 2, 3, "I")
62 }
63
64 // TestDECSTBMv2 top only
65 func TestDECSTBMv2(t *testing.T) {
66 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
67 defer MustClose(t, term)
68 MustStart(t, term)
69
70 WriteF(t, term, "\033[1;1H") // move to top-left
71 WriteF(t, term, "\033[0J") // clear screen
72 WriteF(t, term, "ABC\r\n")
73 WriteF(t, term, "DEF\r\n")
74 WriteF(t, term, "GHI\r\n")
75 WriteF(t, term, "\033[2;2r") // scroll region top/bottom
76 WriteF(t, term, "\033[T") // scroll down one
77
78 // |________|
79 // |ABC_____|
80 // |DEF_____|
81 // |GHI_____|
82 CheckPos(t, term, 0, 3) // did not move
83 CheckContent(t, term, 0, 0, "")
84 CheckContent(t, term, 1, 0, "")
85 CheckContent(t, term, 2, 0, "")
86 CheckContent(t, term, 0, 1, "A")
87 CheckContent(t, term, 1, 1, "B")
88 CheckContent(t, term, 2, 1, "C")
89 CheckContent(t, term, 0, 2, "D")
90 CheckContent(t, term, 1, 2, "E")
91 CheckContent(t, term, 2, 2, "F")
92 CheckContent(t, term, 0, 3, "G")
93 CheckContent(t, term, 1, 3, "H")
94 CheckContent(t, term, 2, 3, "I")
95 }
96
97 // TestDECSTBMv3 top and bottom
98 func TestDECSTBMv3(t *testing.T) {
99 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
100 defer MustClose(t, term)
101 MustStart(t, term)
102
103 WriteF(t, term, "\033[1;1H") // move to top-left
104 WriteF(t, term, "\033[0J") // clear screen
105 WriteF(t, term, "ABC\r\n")
106 WriteF(t, term, "DEF\r\n")
107 WriteF(t, term, "GHI\r\n")
108 WriteF(t, term, "\033[1;2r") // scroll region top/bottom
109 WriteF(t, term, "\033[T") // scroll down one
110
111 // |________|
112 // |ABC_____|
113 // |GHI_____|
114 // |________|
115 CheckPos(t, term, 0, 0)
116 CheckContent(t, term, 0, 0, "")
117 CheckContent(t, term, 1, 0, "")
118 CheckContent(t, term, 2, 0, "")
119 CheckContent(t, term, 0, 1, "A")
120 CheckContent(t, term, 1, 1, "B")
121 CheckContent(t, term, 2, 1, "C")
122 CheckContent(t, term, 0, 2, "G")
123 CheckContent(t, term, 1, 2, "H")
124 CheckContent(t, term, 2, 2, "I")
125 CheckContent(t, term, 0, 3, "")
126 CheckContent(t, term, 1, 3, "")
127 CheckContent(t, term, 2, 3, "")
128 }
129
130 // TestDECSTBMv4 top == bottom
131 func TestDECSTBMv4(t *testing.T) {
132 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
133 defer MustClose(t, term)
134 MustStart(t, term)
135
136 WriteF(t, term, "\033[1;1H")
137 WriteF(t, term, "\033[0J")
138 WriteF(t, term, "ABC\r\n")
139 WriteF(t, term, "DEF\r\n")
140 WriteF(t, term, "GHI\r\n")
141 WriteF(t, term, "\033[2;2r")
142 WriteF(t, term, "\033[T")
143
144 // |________|
145 // |ABC_____|
146 // |DEF_____|
147 // |GHI_____|
148 CheckPos(t, term, 0, 3)
149 CheckContent(t, term, 0, 0, "")
150 CheckContent(t, term, 1, 0, "")
151 CheckContent(t, term, 2, 0, "")
152 CheckContent(t, term, 0, 1, "A")
153 CheckContent(t, term, 1, 1, "B")
154 CheckContent(t, term, 2, 1, "C")
155 CheckContent(t, term, 0, 2, "D")
156 CheckContent(t, term, 1, 2, "E")
157 CheckContent(t, term, 2, 2, "F")
158 CheckContent(t, term, 0, 3, "G")
159 CheckContent(t, term, 1, 3, "H")
160 CheckContent(t, term, 2, 3, "I")
161 }
162
163 // TestDECSLRMv1 tests full screen right and left margins.
164 func TestDECSLRMv1(t *testing.T) {
165 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
166 defer MustClose(t, term)
167 MustStart(t, term)
168
169 WriteF(t, term, "\033[H")
170 WriteF(t, term, "\033[J")
171 WriteF(t, term, "ABC\n\r")
172 WriteF(t, term, "DEF\n\r")
173 WriteF(t, term, "GHI\n\r")
174 WriteF(t, term, "\033[?69h")
175 WriteF(t, term, "\033[s")
176 WriteF(t, term, "\033[X")
177
178 CheckPos(t, term, 0, 0)
179 CheckContent(t, term, 0, 0, "")
180 CheckContent(t, term, 1, 0, "B")
181 CheckContent(t, term, 2, 0, "C")
182 CheckContent(t, term, 0, 1, "D")
183 CheckContent(t, term, 1, 1, "E")
184 CheckContent(t, term, 2, 1, "F")
185 CheckContent(t, term, 0, 2, "G")
186 CheckContent(t, term, 1, 2, "H")
187 CheckContent(t, term, 2, 2, "I")
188 }
189
190 // TODO: DECSLRMv3 left and right this makes use of insert line
191 // TODO: DECSLRMv4 left and right equal
192 // TODO: add tests for actual left and right scrolling!
193
194 // TestRIv1 top of screen, no scroll
195 func TestRIv1(t *testing.T) {
196 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
197 defer MustClose(t, term)
198 MustStart(t, term)
199
200 WriteF(t, term, "\033[1;1H")
201 WriteF(t, term, "\033[0J")
202 WriteF(t, term, "A\r\n")
203 WriteF(t, term, "B\r\n")
204 WriteF(t, term, "C\r\n")
205 WriteF(t, term, "\033[1;1H")
206 WriteF(t, term, "\033M")
207 WriteF(t, term, "X")
208
209 // |Xc______|
210 // |A_______|
211 // |B_______|
212 // |C_______|
213
214 CheckPos(t, term, 1, 0)
215 CheckContent(t, term, 0, 0, "X")
216 CheckContent(t, term, 1, 0, "")
217 CheckContent(t, term, 2, 0, "")
218 CheckContent(t, term, 0, 1, "A")
219 CheckContent(t, term, 1, 1, "")
220 CheckContent(t, term, 2, 1, "")
221 CheckContent(t, term, 0, 2, "B")
222 CheckContent(t, term, 1, 2, "")
223 CheckContent(t, term, 2, 2, "")
224 CheckContent(t, term, 0, 3, "C")
225 CheckContent(t, term, 1, 3, "")
226 CheckContent(t, term, 2, 3, "")
227 }
228
229 // TestRIv2 not top of screen, no scroll
230 func TestRIv2(t *testing.T) {
231 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
232 defer MustClose(t, term)
233 MustStart(t, term)
234
235 WriteF(t, term, "\033[1;1H")
236 WriteF(t, term, "\033[0J")
237 WriteF(t, term, "A\r\n")
238 WriteF(t, term, "B\r\n")
239 WriteF(t, term, "C\r\n")
240 WriteF(t, term, "\033[2;1H")
241 WriteF(t, term, "\033M")
242 WriteF(t, term, "X")
243
244 // |Xc______|
245 // |B_______|
246 // |C_______|
247 // |________|
248
249 CheckPos(t, term, 1, 0)
250 CheckContent(t, term, 0, 0, "X")
251 CheckContent(t, term, 1, 0, "")
252 CheckContent(t, term, 2, 0, "")
253 CheckContent(t, term, 0, 1, "B")
254 CheckContent(t, term, 1, 1, "")
255 CheckContent(t, term, 2, 1, "")
256 CheckContent(t, term, 0, 2, "C")
257 CheckContent(t, term, 1, 2, "")
258 CheckContent(t, term, 2, 2, "")
259 CheckContent(t, term, 0, 3, "")
260 CheckContent(t, term, 1, 3, "")
261 CheckContent(t, term, 2, 3, "")
262 }
263
264 // TestRIv3 scroll region
265 func TestRIv3(t *testing.T) {
266 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
267 defer MustClose(t, term)
268 MustStart(t, term)
269
270 WriteF(t, term, "\033[1;1H") // move to top-left
271 WriteF(t, term, "\033[0J") // clear screen
272 WriteF(t, term, "A\r\n")
273 WriteF(t, term, "B\r\n")
274 WriteF(t, term, "C\r\n")
275 WriteF(t, term, "\033[2;3r")
276 WriteF(t, term, "\033[2;1H")
277 WriteF(t, term, "\033M")
278
279 // |A_______|
280 // |c_______|
281 // |B_______|
282 // |________|
283
284 CheckPos(t, term, 0, 1)
285 CheckContent(t, term, 0, 0, "A")
286 CheckContent(t, term, 1, 0, "")
287 CheckContent(t, term, 2, 0, "")
288 CheckContent(t, term, 0, 1, "")
289 CheckContent(t, term, 1, 1, "")
290 CheckContent(t, term, 2, 1, "")
291 CheckContent(t, term, 0, 2, "B")
292 CheckContent(t, term, 1, 2, "")
293 CheckContent(t, term, 2, 2, "")
294 CheckContent(t, term, 0, 3, "")
295 CheckContent(t, term, 1, 3, "")
296 CheckContent(t, term, 2, 3, "")
297 }
298
299 // TestRIv4 outside scroll region - goes to top, does not scroll
300 func TestRIv4(t *testing.T) {
301 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
302 defer MustClose(t, term)
303 MustStart(t, term)
304
305 WriteF(t, term, "\033[1;1H") // move to top-left
306 WriteF(t, term, "\033[0J") // clear screen
307 WriteF(t, term, "A\r\n")
308 WriteF(t, term, "B\r\n")
309 WriteF(t, term, "C\r\n")
310 WriteF(t, term, "\033[2;3r")
311 WriteF(t, term, "\033[1;1H")
312 WriteF(t, term, "\033M")
313
314 // |A_______|
315 // |B_______|
316 // |C_______|
317 // |________|
318
319 CheckPos(t, term, 0, 0)
320 CheckContent(t, term, 0, 0, "A")
321 CheckContent(t, term, 1, 0, "")
322 CheckContent(t, term, 2, 0, "")
323 CheckContent(t, term, 0, 1, "B")
324 CheckContent(t, term, 1, 1, "")
325 CheckContent(t, term, 2, 1, "")
326 CheckContent(t, term, 0, 2, "C")
327 CheckContent(t, term, 1, 2, "")
328 CheckContent(t, term, 2, 2, "")
329 CheckContent(t, term, 0, 3, "")
330 CheckContent(t, term, 1, 3, "")
331 CheckContent(t, term, 2, 3, "")
332 }
333
334 // TODO: RIv5 - left right scroll regions (when we implement left/right regions)
335 // TODO: RIv6 - outside left/right scroll regions (when we implement left/right regions)
336
337 // TestINDv1 no scroll region, top of screen
338 func TestINDv1(t *testing.T) {
339 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
340 defer MustClose(t, term)
341 MustStart(t, term)
342
343 WriteF(t, term, "\033[1;1H") // move to top-left
344 WriteF(t, term, "\033[0J") // clear screen
345 WriteF(t, term, "A")
346 WriteF(t, term, "\033D")
347 WriteF(t, term, "X")
348
349 // |A_______|
350 // |_Xc_____|
351 // |________|
352 // |________|
353
354 CheckPos(t, term, 2, 1)
355 CheckContent(t, term, 0, 0, "A")
356 CheckContent(t, term, 1, 0, "")
357 CheckContent(t, term, 2, 0, "")
358 CheckContent(t, term, 0, 1, "")
359 CheckContent(t, term, 1, 1, "X")
360 CheckContent(t, term, 2, 1, "")
361 CheckContent(t, term, 0, 2, "")
362 CheckContent(t, term, 1, 2, "")
363 CheckContent(t, term, 2, 2, "")
364 CheckContent(t, term, 0, 3, "")
365 CheckContent(t, term, 1, 3, "")
366 CheckContent(t, term, 2, 3, "")
367 }
368
369 // TestINDv2 no scroll region, bottom of screen
370 func TestINDv2(t *testing.T) {
371 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
372 defer MustClose(t, term)
373 MustStart(t, term)
374
375 WriteF(t, term, "\033[1;1H") // move to top-left
376 WriteF(t, term, "\033[0J") // clear screen
377 WriteF(t, term, "\033[4;1H")
378 WriteF(t, term, "A")
379 WriteF(t, term, "\033D")
380 WriteF(t, term, "X")
381
382 // |________|
383 // |________|
384 // |A_______|
385 // |_Xc_____|
386
387 CheckPos(t, term, 2, 3)
388 CheckContent(t, term, 0, 0, "")
389 CheckContent(t, term, 1, 0, "")
390 CheckContent(t, term, 2, 0, "")
391 CheckContent(t, term, 0, 1, "")
392 CheckContent(t, term, 1, 1, "")
393 CheckContent(t, term, 2, 1, "")
394 CheckContent(t, term, 0, 2, "A")
395 CheckContent(t, term, 1, 2, "")
396 CheckContent(t, term, 2, 2, "")
397 CheckContent(t, term, 0, 3, "")
398 CheckContent(t, term, 1, 3, "X")
399 CheckContent(t, term, 2, 3, "")
400 }
401
402 // TestINDv3 inside scroll region
403 func TestINDv3(t *testing.T) {
404 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
405 defer MustClose(t, term)
406 MustStart(t, term)
407
408 WriteF(t, term, "\033[1;1H") // move to top-left
409 WriteF(t, term, "\033[0J")
410 WriteF(t, term, "\033[1;3r")
411 WriteF(t, term, "A")
412 WriteF(t, term, "\033D")
413 WriteF(t, term, "X")
414
415 // |A_______|
416 // |_Xc_____|
417 // |________|
418 // |________|
419
420 CheckPos(t, term, 2, 1)
421 CheckContent(t, term, 0, 0, "A")
422 CheckContent(t, term, 1, 0, "")
423 CheckContent(t, term, 2, 0, "")
424 CheckContent(t, term, 0, 1, "")
425 CheckContent(t, term, 1, 1, "X")
426 CheckContent(t, term, 2, 1, "")
427 CheckContent(t, term, 0, 2, "")
428 CheckContent(t, term, 1, 2, "")
429 CheckContent(t, term, 2, 2, "")
430 CheckContent(t, term, 0, 3, "")
431 CheckContent(t, term, 1, 3, "")
432 CheckContent(t, term, 2, 3, "")
433 }
434
435 // TestINDv4 bottom of scroll region
436 func TestINDv4(t *testing.T) {
437 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
438 defer MustClose(t, term)
439 MustStart(t, term)
440
441 WriteF(t, term, "\033[1;1H") // move to top-left
442 WriteF(t, term, "\033[0J")
443 WriteF(t, term, "\033[1;3r")
444 WriteF(t, term, "\033[4;1H")
445 WriteF(t, term, "B")
446 WriteF(t, term, "\033[3;1H")
447 WriteF(t, term, "A")
448 WriteF(t, term, "\033D")
449 WriteF(t, term, "X")
450
451 // |________|
452 // |A_______|
453 // |_Xc_____|
454 // |B_______|
455
456 CheckPos(t, term, 2, 2)
457 CheckContent(t, term, 0, 0, "")
458 CheckContent(t, term, 1, 0, "")
459 CheckContent(t, term, 2, 0, "")
460 CheckContent(t, term, 0, 1, "A")
461 CheckContent(t, term, 1, 1, "")
462 CheckContent(t, term, 2, 1, "")
463 CheckContent(t, term, 0, 2, "")
464 CheckContent(t, term, 1, 2, "X")
465 CheckContent(t, term, 2, 2, "")
466 CheckContent(t, term, 0, 3, "B")
467 CheckContent(t, term, 1, 3, "")
468 CheckContent(t, term, 2, 3, "")
469 }
470
471 // TestINDv5 bottom of screen with scroll region
472 func TestINDv5(t *testing.T) {
473 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
474 defer MustClose(t, term)
475 MustStart(t, term)
476
477 WriteF(t, term, "\033[1;1H") // move to top-left
478 WriteF(t, term, "\033[0J")
479 WriteF(t, term, "\033[1;3r")
480 WriteF(t, term, "\033[3;1H")
481 WriteF(t, term, "A")
482 WriteF(t, term, "\033[4;1H")
483 WriteF(t, term, "\033D")
484 WriteF(t, term, "X")
485
486 // |________|
487 // |________|
488 // |A_______|
489 // |________|
490 // |Xc______|
491
492 CheckPos(t, term, 1, 4)
493 CheckContent(t, term, 0, 0, "")
494 CheckContent(t, term, 1, 0, "")
495 CheckContent(t, term, 2, 0, "")
496 CheckContent(t, term, 0, 1, "")
497 CheckContent(t, term, 1, 1, "")
498 CheckContent(t, term, 2, 1, "")
499 CheckContent(t, term, 0, 2, "A")
500 CheckContent(t, term, 1, 2, "")
501 CheckContent(t, term, 2, 2, "")
502 CheckContent(t, term, 0, 3, "")
503 CheckContent(t, term, 1, 3, "")
504 CheckContent(t, term, 2, 3, "")
505 CheckContent(t, term, 0, 4, "X")
506 CheckContent(t, term, 1, 4, "")
507 CheckContent(t, term, 2, 4, "")
508 }
509
510 // TestINDv6 tests IND outside of left and right scroll region.
511 func TestINDv6(t *testing.T) {
512 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
513 defer MustClose(t, term)
514 MustStart(t, term)
515
516 WriteF(t, term, "\033[1;1H") // move to top-left
517 WriteF(t, term, "\033[0J")
518 WriteF(t, term, "\033[?69h")
519 WriteF(t, term, "\033[1;3r")
520 WriteF(t, term, "\033[3;5s")
521 WriteF(t, term, "\033[3;3H")
522 WriteF(t, term, "A")
523 WriteF(t, term, "\033[3;1H")
524 WriteF(t, term, "\033D")
525 WriteF(t, term, "X")
526
527 // |________|
528 // |________|
529 // |XcA_____|
530
531 CheckPos(t, term, 1, 2)
532 CheckContent(t, term, 0, 0, "")
533 CheckContent(t, term, 1, 0, "")
534 CheckContent(t, term, 2, 0, "")
535 CheckContent(t, term, 0, 1, "")
536 CheckContent(t, term, 1, 1, "")
537 CheckContent(t, term, 2, 1, "")
538 CheckContent(t, term, 0, 2, "X")
539 CheckContent(t, term, 1, 2, "")
540 CheckContent(t, term, 2, 2, "A")
541 CheckContent(t, term, 0, 3, "")
542 CheckContent(t, term, 1, 3, "")
543 CheckContent(t, term, 2, 3, "")
544 }
545
546 // TestINDv7 tests IND inside of left and right scroll region.
547 func TestINDv7(t *testing.T) {
548 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
549 defer MustClose(t, term)
550 MustStart(t, term)
551
552 WriteF(t, term, "\033[1;1H") // move to top-left
553 WriteF(t, term, "\033[0J")
554 WriteF(t, term, "111111\n\r")
555 WriteF(t, term, "222222\n\r")
556 WriteF(t, term, "333333\n\r")
557 WriteF(t, term, "\033[?69h")
558 WriteF(t, term, "\033[1;3s")
559 WriteF(t, term, "\033[1;3r")
560 WriteF(t, term, "\033[3;1H")
561 WriteF(t, term, "\033D")
562
563 // |222111__|
564 // |333222__|
565 // |c__333__|
566
567 CheckPos(t, term, 0, 2)
568 CheckContent(t, term, 0, 0, "2")
569 CheckContent(t, term, 1, 0, "2")
570 CheckContent(t, term, 2, 0, "2")
571 CheckContent(t, term, 3, 0, "1")
572 CheckContent(t, term, 4, 0, "1")
573 CheckContent(t, term, 5, 0, "1")
574 CheckContent(t, term, 0, 1, "3")
575 CheckContent(t, term, 1, 1, "3")
576 CheckContent(t, term, 2, 1, "3")
577 CheckContent(t, term, 3, 1, "2")
578 CheckContent(t, term, 4, 1, "2")
579 CheckContent(t, term, 5, 1, "2")
580 CheckContent(t, term, 0, 2, "")
581 CheckContent(t, term, 1, 2, "")
582 CheckContent(t, term, 2, 2, "")
583 CheckContent(t, term, 3, 2, "3")
584 CheckContent(t, term, 4, 2, "3")
585 CheckContent(t, term, 5, 2, "3")
586 }
587
588 // TestCUDv1 - cursor down
589 func TestCUDv1(t *testing.T) {
590 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
591 defer MustClose(t, term)
592 MustStart(t, term)
593
594 WriteF(t, term, "A")
595 WriteF(t, term, "\033[2B")
596 WriteF(t, term, "X")
597
598 // |A_______|
599 // |________|
600 // |_Xc_____|
601 // |________|
602
603 CheckPos(t, term, 2, 2)
604 CheckContent(t, term, 0, 0, "A")
605 CheckContent(t, term, 1, 0, "")
606 CheckContent(t, term, 2, 0, "")
607 CheckContent(t, term, 0, 1, "")
608 CheckContent(t, term, 1, 1, "")
609 CheckContent(t, term, 2, 1, "")
610 CheckContent(t, term, 0, 2, "")
611 CheckContent(t, term, 1, 2, "X")
612 CheckContent(t, term, 2, 2, "")
613 CheckContent(t, term, 0, 3, "")
614 CheckContent(t, term, 1, 3, "")
615 CheckContent(t, term, 2, 3, "")
616 }
617
618 // TestCUDv2 - cursor down above bottom margin
619 func TestCUDv2(t *testing.T) {
620 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
621 defer MustClose(t, term)
622 MustStart(t, term)
623
624 WriteF(t, term, "\033[1;1H")
625 WriteF(t, term, "\033[0J")
626 WriteF(t, term, "\n\n\n\n")
627 WriteF(t, term, "\033[1;3r")
628 WriteF(t, term, "A")
629 WriteF(t, term, "\033[5B")
630 WriteF(t, term, "X")
631
632 // |A_______|
633 // |________|
634 // |_Xc_____|
635 // |________|
636
637 CheckPos(t, term, 2, 2)
638 CheckContent(t, term, 0, 0, "A")
639 CheckContent(t, term, 1, 0, "")
640 CheckContent(t, term, 2, 0, "")
641 CheckContent(t, term, 0, 1, "")
642 CheckContent(t, term, 1, 1, "")
643 CheckContent(t, term, 2, 1, "")
644 CheckContent(t, term, 0, 2, "")
645 CheckContent(t, term, 1, 2, "X")
646 CheckContent(t, term, 2, 2, "")
647 CheckContent(t, term, 0, 3, "")
648 CheckContent(t, term, 1, 3, "")
649 CheckContent(t, term, 2, 3, "")
650 }
651
652 // TestCUDv3 - cursor down below bottom margin
653 func TestCUDv3(t *testing.T) {
654 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
655 defer MustClose(t, term)
656 MustStart(t, term)
657
658 WriteF(t, term, "\033[1;1H")
659 WriteF(t, term, "\033[0J")
660 WriteF(t, term, "\033[1;3r")
661 WriteF(t, term, "A")
662 WriteF(t, term, "\033[4;1H")
663 WriteF(t, term, "\033[5B")
664 WriteF(t, term, "X")
665
666 // |A_______|
667 // |________|
668 // |________|
669 // |________|
670 // |Xc______|
671
672 CheckPos(t, term, 1, 4)
673 CheckContent(t, term, 0, 0, "A")
674 CheckContent(t, term, 1, 0, "")
675 CheckContent(t, term, 2, 0, "")
676 CheckContent(t, term, 0, 1, "")
677 CheckContent(t, term, 1, 1, "")
678 CheckContent(t, term, 2, 1, "")
679 CheckContent(t, term, 0, 2, "")
680 CheckContent(t, term, 1, 2, "")
681 CheckContent(t, term, 2, 2, "")
682 CheckContent(t, term, 0, 3, "")
683 CheckContent(t, term, 1, 3, "")
684 CheckContent(t, term, 2, 3, "")
685 CheckContent(t, term, 0, 4, "X")
686 CheckContent(t, term, 1, 4, "")
687 CheckContent(t, term, 2, 4, "")
688 }
689
690 // TestCUUv1 tests cursor up.
691 func TestCUUv1(t *testing.T) {
692 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
693 defer MustClose(t, term)
694 MustStart(t, term)
695
696 WriteF(t, term, "\033[1;1H")
697 WriteF(t, term, "\033[0J")
698 WriteF(t, term, "\033[3;H")
699 WriteF(t, term, "A")
700 WriteF(t, term, "\033[2A")
701 WriteF(t, term, "X")
702
703 // |_Xc_____|
704 // |________|
705 // |A_______|
706
707 CheckPos(t, term, 2, 0)
708 CheckContent(t, term, 0, 0, "")
709 CheckContent(t, term, 1, 0, "X")
710 CheckContent(t, term, 2, 0, "")
711 CheckContent(t, term, 0, 1, "")
712 CheckContent(t, term, 1, 1, "")
713 CheckContent(t, term, 2, 1, "")
714 CheckContent(t, term, 0, 2, "A")
715 CheckContent(t, term, 1, 2, "")
716 CheckContent(t, term, 2, 2, "")
717 }
718
719 // TestCUUv2 tests cursor up below the top margin.
720 func TestCUUv2(t *testing.T) {
721 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
722 defer MustClose(t, term)
723 MustStart(t, term)
724
725 WriteF(t, term, "\033[1;1H")
726 WriteF(t, term, "\033[0J")
727 WriteF(t, term, "\033[2;4r")
728 WriteF(t, term, "\033[3;1H")
729 WriteF(t, term, "A")
730 WriteF(t, term, "\033[5A")
731 WriteF(t, term, "X")
732
733 // |________|
734 // |_Xc_____|
735 // |A_______|
736 // |________|
737
738 CheckPos(t, term, 2, 1)
739 CheckContent(t, term, 0, 0, "")
740 CheckContent(t, term, 1, 0, "")
741 CheckContent(t, term, 2, 0, "")
742 CheckContent(t, term, 0, 1, "")
743 CheckContent(t, term, 1, 1, "X")
744 CheckContent(t, term, 2, 1, "")
745 CheckContent(t, term, 0, 2, "A")
746 CheckContent(t, term, 1, 2, "")
747 CheckContent(t, term, 2, 2, "")
748 CheckContent(t, term, 0, 3, "")
749 CheckContent(t, term, 1, 3, "")
750 CheckContent(t, term, 2, 3, "")
751 }
752
753 // TestCUUv3 tests cursor up above the top margin.
754 func TestCUUv3(t *testing.T) {
755 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
756 defer MustClose(t, term)
757 MustStart(t, term)
758
759 WriteF(t, term, "\033[1;1H")
760 WriteF(t, term, "\033[0J")
761 WriteF(t, term, "\033[3;5r")
762 WriteF(t, term, "\033[3;1H")
763 WriteF(t, term, "A")
764 WriteF(t, term, "\033[2;1H")
765 WriteF(t, term, "\033[5A")
766 WriteF(t, term, "X")
767
768 // |Xc______|
769 // |________|
770 // |A_______|
771 // |________|
772 // |________|
773
774 CheckPos(t, term, 1, 0)
775 CheckContent(t, term, 0, 0, "X")
776 CheckContent(t, term, 1, 0, "")
777 CheckContent(t, term, 2, 0, "")
778 CheckContent(t, term, 0, 1, "")
779 CheckContent(t, term, 1, 1, "")
780 CheckContent(t, term, 2, 1, "")
781 CheckContent(t, term, 0, 2, "A")
782 CheckContent(t, term, 1, 2, "")
783 CheckContent(t, term, 2, 2, "")
784 CheckContent(t, term, 0, 3, "")
785 CheckContent(t, term, 1, 3, "")
786 CheckContent(t, term, 2, 3, "")
787 }
788
789 // TestCNLv1 - cursor next line
790 func TestCNLv1(t *testing.T) {
791 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
792 defer MustClose(t, term)
793 MustStart(t, term)
794
795 WriteF(t, term, "A")
796 WriteF(t, term, "\033[2E")
797 WriteF(t, term, "X")
798
799 // |A_______|
800 // |________|
801 // |Xc_____|
802 // |________|
803
804 CheckPos(t, term, 1, 2)
805 CheckContent(t, term, 0, 0, "A")
806 CheckContent(t, term, 1, 0, "")
807 CheckContent(t, term, 2, 0, "")
808 CheckContent(t, term, 0, 1, "")
809 CheckContent(t, term, 1, 1, "")
810 CheckContent(t, term, 2, 1, "")
811 CheckContent(t, term, 0, 2, "X")
812 CheckContent(t, term, 1, 2, "")
813 CheckContent(t, term, 2, 2, "")
814 CheckContent(t, term, 0, 3, "")
815 CheckContent(t, term, 1, 3, "")
816 CheckContent(t, term, 2, 3, "")
817 }
818
819 // TestCNLv2 - cursor next line above bottom margin
820 func TestCNLv2(t *testing.T) {
821 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 4})
822 defer MustClose(t, term)
823 MustStart(t, term)
824
825 WriteF(t, term, "\033[1;1H")
826 WriteF(t, term, "\033[0J")
827 WriteF(t, term, "\n\n\n\n")
828 WriteF(t, term, "\033[1;3r")
829 WriteF(t, term, "A")
830 WriteF(t, term, "\033[5E")
831 WriteF(t, term, "X")
832
833 // |A_______|
834 // |________|
835 // |Xc______|
836 // |________|
837
838 CheckPos(t, term, 1, 2)
839 CheckContent(t, term, 0, 0, "A")
840 CheckContent(t, term, 1, 0, "")
841 CheckContent(t, term, 2, 0, "")
842 CheckContent(t, term, 0, 1, "")
843 CheckContent(t, term, 1, 1, "")
844 CheckContent(t, term, 2, 1, "")
845 CheckContent(t, term, 0, 2, "X")
846 CheckContent(t, term, 1, 2, "")
847 CheckContent(t, term, 2, 2, "")
848 CheckContent(t, term, 0, 3, "")
849 CheckContent(t, term, 1, 3, "")
850 CheckContent(t, term, 2, 3, "")
851 }
852
853 // TestCNLv3 - cursor next line bottom margin
854 func TestCNLv3(t *testing.T) {
855 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
856 defer MustClose(t, term)
857 MustStart(t, term)
858
859 WriteF(t, term, "\033[1;1H")
860 WriteF(t, term, "\033[0J")
861 WriteF(t, term, "\033[1;3r")
862 WriteF(t, term, "A")
863 WriteF(t, term, "\033[4;3H")
864 WriteF(t, term, "\033[5E")
865 WriteF(t, term, "X")
866
867 // |A_______|
868 // |________|
869 // |________|
870 // |________|
871 // |Xc______|
872
873 CheckPos(t, term, 1, 4)
874 CheckContent(t, term, 0, 0, "A")
875 CheckContent(t, term, 1, 0, "")
876 CheckContent(t, term, 2, 0, "")
877 CheckContent(t, term, 0, 1, "")
878 CheckContent(t, term, 1, 1, "")
879 CheckContent(t, term, 2, 1, "")
880 CheckContent(t, term, 0, 2, "")
881 CheckContent(t, term, 1, 2, "")
882 CheckContent(t, term, 2, 2, "")
883 CheckContent(t, term, 0, 3, "")
884 CheckContent(t, term, 1, 3, "")
885 CheckContent(t, term, 2, 3, "")
886 CheckContent(t, term, 0, 4, "X")
887 CheckContent(t, term, 1, 4, "")
888 CheckContent(t, term, 2, 4, "")
889 }
890
891 // TestCPLv1 tests cursor previous line.
892 func TestCPLv1(t *testing.T) {
893 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
894 defer MustClose(t, term)
895 MustStart(t, term)
896
897 WriteF(t, term, "\033[1;1H")
898 WriteF(t, term, "\033[0J")
899 WriteF(t, term, "\033[3;H")
900 WriteF(t, term, "A")
901 WriteF(t, term, "\033[2F")
902 WriteF(t, term, "X")
903
904 // |Xc______|
905 // |________|
906 // |A_______|
907
908 CheckPos(t, term, 1, 0)
909 CheckContent(t, term, 0, 0, "X")
910 CheckContent(t, term, 1, 0, "")
911 CheckContent(t, term, 2, 0, "")
912 CheckContent(t, term, 0, 1, "")
913 CheckContent(t, term, 1, 1, "")
914 CheckContent(t, term, 2, 1, "")
915 CheckContent(t, term, 0, 2, "A")
916 CheckContent(t, term, 1, 2, "")
917 CheckContent(t, term, 2, 2, "")
918 }
919
920 // TestCPLv2 tests cursor previous line below the top margin.
921 func TestCPLv2(t *testing.T) {
922 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
923 defer MustClose(t, term)
924 MustStart(t, term)
925
926 WriteF(t, term, "\033[1;1H")
927 WriteF(t, term, "\033[0J")
928 WriteF(t, term, "\033[2;4r")
929 WriteF(t, term, "\033[3;1H")
930 WriteF(t, term, "A")
931 WriteF(t, term, "\033[5F")
932 WriteF(t, term, "X")
933
934 // |________|
935 // |Xc______|
936 // |A_______|
937 // |________|
938
939 CheckPos(t, term, 1, 1)
940 CheckContent(t, term, 0, 0, "")
941 CheckContent(t, term, 1, 0, "")
942 CheckContent(t, term, 2, 0, "")
943 CheckContent(t, term, 0, 1, "X")
944 CheckContent(t, term, 1, 1, "")
945 CheckContent(t, term, 2, 1, "")
946 CheckContent(t, term, 0, 2, "A")
947 CheckContent(t, term, 1, 2, "")
948 CheckContent(t, term, 2, 2, "")
949 CheckContent(t, term, 0, 3, "")
950 CheckContent(t, term, 1, 3, "")
951 CheckContent(t, term, 2, 3, "")
952 }
953
954 // TestCPLv3 tests cursor previous line above the top margin.
955 func TestCPLv3(t *testing.T) {
956 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
957 defer MustClose(t, term)
958 MustStart(t, term)
959
960 WriteF(t, term, "\033[1;1H")
961 WriteF(t, term, "\033[0J")
962 WriteF(t, term, "\033[3;5r")
963 WriteF(t, term, "\033[3;1H")
964 WriteF(t, term, "A")
965 WriteF(t, term, "\033[2;2H")
966 WriteF(t, term, "\033[5F")
967 WriteF(t, term, "X")
968
969 // |Xc______|
970 // |________|
971 // |A_______|
972 // |________|
973 // |________|
974
975 CheckPos(t, term, 1, 0)
976 CheckContent(t, term, 0, 0, "X")
977 CheckContent(t, term, 1, 0, "")
978 CheckContent(t, term, 2, 0, "")
979 CheckContent(t, term, 0, 1, "")
980 CheckContent(t, term, 1, 1, "")
981 CheckContent(t, term, 2, 1, "")
982 CheckContent(t, term, 0, 2, "A")
983 CheckContent(t, term, 1, 2, "")
984 CheckContent(t, term, 2, 2, "")
985 CheckContent(t, term, 0, 3, "")
986 CheckContent(t, term, 1, 3, "")
987 CheckContent(t, term, 2, 3, "")
988 }
989
990 // TestILv1 tests inserting a line.
991 func TestILv1(t *testing.T) {
992 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
993 defer MustClose(t, term)
994 MustStart(t, term)
995
996 WriteF(t, term, "\033[1;1H\033[0J")
997 WriteF(t, term, "ABC\n\r")
998 WriteF(t, term, "DEF\n\r")
999 WriteF(t, term, "GHI\n\r")
1000 WriteF(t, term, "\033[2;2H")
1001 WriteF(t, term, "\033[L")
1002
1003 // |ABC_____|
1004 // |c_______|
1005 // |DEF_____|
1006 // |GHI_____|
1007 // |________|
1008
1009 CheckPos(t, term, 0, 1)
1010 CheckContent(t, term, 0, 0, "A")
1011 CheckContent(t, term, 1, 0, "B")
1012 CheckContent(t, term, 2, 0, "C")
1013 CheckContent(t, term, 3, 0, "")
1014 CheckContent(t, term, 0, 1, "")
1015 CheckContent(t, term, 1, 1, "")
1016 CheckContent(t, term, 2, 1, "")
1017 CheckContent(t, term, 3, 1, "")
1018 CheckContent(t, term, 0, 2, "D")
1019 CheckContent(t, term, 1, 2, "E")
1020 CheckContent(t, term, 2, 2, "F")
1021 CheckContent(t, term, 3, 2, "")
1022 CheckContent(t, term, 0, 3, "G")
1023 CheckContent(t, term, 1, 3, "H")
1024 CheckContent(t, term, 2, 3, "I")
1025 CheckContent(t, term, 3, 3, "")
1026 }
1027
1028 // TestILv2 tests insert line outside of the scroll region.
1029 func TestILv2(t *testing.T) {
1030 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1031 defer MustClose(t, term)
1032 MustStart(t, term)
1033
1034 WriteF(t, term, "\033[1;1H\033[0J")
1035 WriteF(t, term, "ABC\n\r")
1036 WriteF(t, term, "DEF\n\r")
1037 WriteF(t, term, "GHI\n\r")
1038 WriteF(t, term, "\033[3;4r")
1039 WriteF(t, term, "\033[2;2H")
1040 WriteF(t, term, "\033[L")
1041
1042 // |ABC_____|
1043 // |DEF_____|
1044 // |GHI_____|
1045 // |________|
1046 // |________|
1047
1048 CheckPos(t, term, 1, 1)
1049 CheckContent(t, term, 0, 0, "A")
1050 CheckContent(t, term, 1, 0, "B")
1051 CheckContent(t, term, 2, 0, "C")
1052 CheckContent(t, term, 3, 0, "")
1053 CheckContent(t, term, 0, 1, "D")
1054 CheckContent(t, term, 1, 1, "E")
1055 CheckContent(t, term, 2, 1, "F")
1056 CheckContent(t, term, 3, 1, "")
1057 CheckContent(t, term, 0, 2, "G")
1058 CheckContent(t, term, 1, 2, "H")
1059 CheckContent(t, term, 2, 2, "I")
1060 CheckContent(t, term, 3, 2, "")
1061 }
1062
1063 // TestILv3 tests insert line with top and bottom scroll regions.
1064 func TestILv3(t *testing.T) {
1065 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1066 defer MustClose(t, term)
1067 MustStart(t, term)
1068
1069 WriteF(t, term, "\033[1;1H\033[0J")
1070 WriteF(t, term, "ABC\n\r")
1071 WriteF(t, term, "DEF\n\r")
1072 WriteF(t, term, "GHI\n\r")
1073 WriteF(t, term, "123\n\r")
1074 WriteF(t, term, "\033[1;3r")
1075 WriteF(t, term, "\033[2;2H")
1076 WriteF(t, term, "\033[L")
1077
1078 // |ABC_____|
1079 // |c_______|
1080 // |DEF_____|
1081 // |123_____|
1082
1083 CheckPos(t, term, 0, 1)
1084 CheckContent(t, term, 0, 0, "A")
1085 CheckContent(t, term, 1, 0, "B")
1086 CheckContent(t, term, 2, 0, "C")
1087 CheckContent(t, term, 3, 0, "")
1088 CheckContent(t, term, 0, 1, "")
1089 CheckContent(t, term, 1, 1, "")
1090 CheckContent(t, term, 2, 1, "")
1091 CheckContent(t, term, 3, 1, "")
1092 CheckContent(t, term, 0, 2, "D")
1093 CheckContent(t, term, 1, 2, "E")
1094 CheckContent(t, term, 2, 2, "F")
1095 CheckContent(t, term, 3, 2, "")
1096 CheckContent(t, term, 0, 3, "1")
1097 CheckContent(t, term, 1, 3, "2")
1098 CheckContent(t, term, 2, 3, "3")
1099 CheckContent(t, term, 3, 3, "")
1100 }
1101
1102 // TestILv4 tests insert line with left and right margins.
1103 func TestILv4(t *testing.T) {
1104 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1105 defer MustClose(t, term)
1106 MustStart(t, term)
1107
1108 WriteF(t, term, "\033[1;1H\033[0J")
1109 WriteF(t, term, "ABC123\n\r")
1110 WriteF(t, term, "DEF456\n\r")
1111 WriteF(t, term, "GHI789\n\r")
1112 WriteF(t, term, "\033[?69h")
1113 WriteF(t, term, "\033[2;4s")
1114 WriteF(t, term, "\033[2;2H")
1115 WriteF(t, term, "\033[L")
1116
1117 // |ABC123__|
1118 // |Dc__56__|
1119 // |GEF489__|
1120 // |_HI7____|
1121
1122 CheckPos(t, term, 0, 1)
1123 CheckContent(t, term, 0, 0, "A")
1124 CheckContent(t, term, 1, 0, "B")
1125 CheckContent(t, term, 2, 0, "C")
1126 CheckContent(t, term, 3, 0, "1")
1127 CheckContent(t, term, 4, 0, "2")
1128 CheckContent(t, term, 5, 0, "3")
1129 CheckContent(t, term, 0, 1, "D")
1130 CheckContent(t, term, 1, 1, "")
1131 CheckContent(t, term, 2, 1, "")
1132 CheckContent(t, term, 3, 1, "")
1133 CheckContent(t, term, 4, 1, "5")
1134 CheckContent(t, term, 5, 1, "6")
1135 CheckContent(t, term, 0, 2, "G")
1136 CheckContent(t, term, 1, 2, "E")
1137 CheckContent(t, term, 2, 2, "F")
1138 CheckContent(t, term, 3, 2, "4")
1139 CheckContent(t, term, 4, 2, "8")
1140 CheckContent(t, term, 5, 2, "9")
1141 CheckContent(t, term, 0, 3, "")
1142 CheckContent(t, term, 1, 3, "H")
1143 CheckContent(t, term, 2, 3, "I")
1144 CheckContent(t, term, 3, 3, "7")
1145 CheckContent(t, term, 4, 3, "")
1146 CheckContent(t, term, 5, 3, "")
1147 }
1148
1149 // TestDLv1 tests a simple delete line.
1150 func TestDLv1(t *testing.T) {
1151 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1152 defer MustClose(t, term)
1153 MustStart(t, term)
1154
1155 WriteF(t, term, "\033[1;1H\033[0J")
1156 WriteF(t, term, "ABC\n\r")
1157 WriteF(t, term, "DEF\n\r")
1158 WriteF(t, term, "GHI\n\r")
1159 WriteF(t, term, "\033[2;2H")
1160 WriteF(t, term, "\033[M")
1161
1162 // |ABC_____|
1163 // |GHI_____|
1164 // |________|
1165 // |________|
1166 // |________|
1167
1168 CheckPos(t, term, 0, 1)
1169 CheckContent(t, term, 0, 0, "A")
1170 CheckContent(t, term, 1, 0, "B")
1171 CheckContent(t, term, 2, 0, "C")
1172 CheckContent(t, term, 3, 0, "")
1173 CheckContent(t, term, 0, 1, "G")
1174 CheckContent(t, term, 1, 1, "H")
1175 CheckContent(t, term, 2, 1, "I")
1176 CheckContent(t, term, 3, 1, "")
1177 CheckContent(t, term, 0, 2, "")
1178 CheckContent(t, term, 1, 2, "")
1179 CheckContent(t, term, 2, 2, "")
1180 CheckContent(t, term, 2, 3, "")
1181 }
1182
1183 // TestDLv2 delete line outside of the scroll region.
1184 func TestDLv2(t *testing.T) {
1185 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1186 defer MustClose(t, term)
1187 MustStart(t, term)
1188
1189 WriteF(t, term, "\033[1;1H\033[0J")
1190 WriteF(t, term, "ABC\n\r")
1191 WriteF(t, term, "DEF\n\r")
1192 WriteF(t, term, "GHI\n\r")
1193 WriteF(t, term, "\033[3;4r")
1194 WriteF(t, term, "\033[2;2H")
1195 WriteF(t, term, "\033[M")
1196
1197 // |ABC_____|
1198 // |DEF_____|
1199 // |GHI_____|
1200 // |________|
1201 // |________|
1202
1203 CheckPos(t, term, 1, 1)
1204 CheckContent(t, term, 0, 0, "A")
1205 CheckContent(t, term, 1, 0, "B")
1206 CheckContent(t, term, 2, 0, "C")
1207 CheckContent(t, term, 3, 0, "")
1208 CheckContent(t, term, 0, 1, "D")
1209 CheckContent(t, term, 1, 1, "E")
1210 CheckContent(t, term, 2, 1, "F")
1211 CheckContent(t, term, 3, 1, "")
1212 CheckContent(t, term, 0, 2, "G")
1213 CheckContent(t, term, 1, 2, "H")
1214 CheckContent(t, term, 2, 2, "I")
1215 CheckContent(t, term, 3, 2, "")
1216 }
1217
1218 // TestDLv3 delete line with top and bottom scroll regions.
1219 func TestDLv3(t *testing.T) {
1220 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1221 defer MustClose(t, term)
1222 MustStart(t, term)
1223
1224 WriteF(t, term, "\033[1;1H\033[0J")
1225 WriteF(t, term, "ABC\n\r")
1226 WriteF(t, term, "DEF\n\r")
1227 WriteF(t, term, "GHI\n\r")
1228 WriteF(t, term, "123\n\r")
1229 WriteF(t, term, "\033[1;3r")
1230 WriteF(t, term, "\033[2;2H")
1231 WriteF(t, term, "\033[M")
1232
1233 // |ABC_____|
1234 // |GHI_____|
1235 // |________|
1236 // |123_____|
1237
1238 CheckPos(t, term, 0, 1)
1239 CheckContent(t, term, 0, 0, "A")
1240 CheckContent(t, term, 1, 0, "B")
1241 CheckContent(t, term, 2, 0, "C")
1242 CheckContent(t, term, 3, 0, "")
1243 CheckContent(t, term, 0, 1, "G")
1244 CheckContent(t, term, 1, 1, "H")
1245 CheckContent(t, term, 2, 1, "I")
1246 CheckContent(t, term, 3, 1, "")
1247 CheckContent(t, term, 0, 2, "")
1248 CheckContent(t, term, 1, 2, "")
1249 CheckContent(t, term, 2, 2, "")
1250 CheckContent(t, term, 3, 2, "")
1251 CheckContent(t, term, 0, 3, "1")
1252 CheckContent(t, term, 1, 3, "2")
1253 CheckContent(t, term, 2, 3, "3")
1254 CheckContent(t, term, 3, 3, "")
1255 }
1256
1257 // TestDLv4 delete line with left and right margins.
1258 func TestDLv4(t *testing.T) {
1259 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1260 defer MustClose(t, term)
1261 MustStart(t, term)
1262
1263 WriteF(t, term, "\033[1;1H\033[0J")
1264 WriteF(t, term, "ABC123\n\r")
1265 WriteF(t, term, "DEF456\n\r")
1266 WriteF(t, term, "GHI789\n\r")
1267 WriteF(t, term, "\033[?69h")
1268 WriteF(t, term, "\033[2;4s")
1269 WriteF(t, term, "\033[2;2H")
1270 WriteF(t, term, "\033[M")
1271
1272 // |ABC123__|
1273 // |DHI756__|
1274 // |G___89__|
1275 // |________|
1276
1277 CheckPos(t, term, 0, 1)
1278 CheckContent(t, term, 0, 0, "A")
1279 CheckContent(t, term, 1, 0, "B")
1280 CheckContent(t, term, 2, 0, "C")
1281 CheckContent(t, term, 3, 0, "1")
1282 CheckContent(t, term, 4, 0, "2")
1283 CheckContent(t, term, 5, 0, "3")
1284 CheckContent(t, term, 0, 1, "D")
1285 CheckContent(t, term, 1, 1, "H")
1286 CheckContent(t, term, 2, 1, "I")
1287 CheckContent(t, term, 3, 1, "7")
1288 CheckContent(t, term, 4, 1, "5")
1289 CheckContent(t, term, 5, 1, "6")
1290 CheckContent(t, term, 0, 2, "G")
1291 CheckContent(t, term, 1, 2, "")
1292 CheckContent(t, term, 2, 2, "")
1293 CheckContent(t, term, 3, 2, "")
1294 CheckContent(t, term, 4, 2, "8")
1295 CheckContent(t, term, 5, 2, "9")
1296 CheckContent(t, term, 0, 3, "")
1297 CheckContent(t, term, 1, 3, "")
1298 CheckContent(t, term, 2, 3, "")
1299 CheckContent(t, term, 3, 3, "")
1300 CheckContent(t, term, 4, 3, "")
1301 CheckContent(t, term, 5, 3, "")
1302 }
1303
1304 // TestDCv1 tests a simple delete character.
1305 func TestDCv1(t *testing.T) {
1306 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1307 defer MustClose(t, term)
1308 MustStart(t, term)
1309
1310 WriteF(t, term, "\033[1;1H\033[0J")
1311 WriteF(t, term, "ABC123")
1312 WriteF(t, term, "\033[3G")
1313 WriteF(t, term, "\033[2P")
1314
1315 // |AB23____|
1316 // |________|
1317 // |________|
1318 // |________|
1319
1320 CheckPos(t, term, 2, 0)
1321 CheckContent(t, term, 0, 0, "A")
1322 CheckContent(t, term, 1, 0, "B")
1323 CheckContent(t, term, 2, 0, "2")
1324 CheckContent(t, term, 3, 0, "3")
1325 CheckContent(t, term, 4, 0, "")
1326 CheckContent(t, term, 5, 0, "")
1327 CheckContent(t, term, 6, 0, "")
1328 }
1329
1330 // TestDCv2 tests delete character SGR state.
1331 func TestDCv2(t *testing.T) {
1332 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1333 defer MustClose(t, term)
1334 MustStart(t, term)
1335
1336 WriteF(t, term, "\033[1;1H\033[0J")
1337 WriteF(t, term, "ABC123")
1338 WriteF(t, term, "\033[3G")
1339 WriteF(t, term, "\033[41m")
1340 WriteF(t, term, "\x1b[1m")
1341 WriteF(t, term, "\033[2P")
1342
1343 // |AB23____|
1344 // |________|
1345 // |________|
1346 // |________|
1347
1348 CheckPos(t, term, 2, 0)
1349 CheckContent(t, term, 0, 0, "A")
1350 CheckContent(t, term, 1, 0, "B")
1351 CheckContent(t, term, 2, 0, "2")
1352 CheckContent(t, term, 3, 0, "3")
1353 CheckContent(t, term, 4, 0, "")
1354 CheckContent(t, term, 5, 0, "")
1355 CheckContent(t, term, 6, 0, "")
1356 CheckAttrs(t, term, 6, 0, vt.Plain)
1357 CheckAttrs(t, term, 7, 0, vt.Plain)
1358 CheckColors(t, term, 6, 0, color.Silver, color.Maroon)
1359 CheckColors(t, term, 7, 0, color.Silver, color.Maroon)
1360 }
1361
1362 // TestDCv3 tests delete outside the left/right scroll region.
1363 func TestDCv3(t *testing.T) {
1364 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1365 defer MustClose(t, term)
1366 MustStart(t, term)
1367
1368 WriteF(t, term, "\033[1;1H\033[0J")
1369 WriteF(t, term, "ABC123")
1370 WriteF(t, term, "\033[?69h")
1371 WriteF(t, term, "\033[3;5s")
1372 WriteF(t, term, "\x1b[2G")
1373 WriteF(t, term, "\033[P")
1374
1375 // |ABC123__|
1376 // |________|
1377 // |________|
1378 // |________|
1379
1380 CheckPos(t, term, 1, 0)
1381 CheckContent(t, term, 0, 0, "A")
1382 CheckContent(t, term, 1, 0, "B")
1383 CheckContent(t, term, 2, 0, "C")
1384 CheckContent(t, term, 3, 0, "1")
1385 CheckContent(t, term, 4, 0, "2")
1386 CheckContent(t, term, 5, 0, "3")
1387 CheckContent(t, term, 6, 0, "")
1388 }
1389
1390 // TestDCv4 tests delete inside the left/right scroll region.
1391 func TestDCv4(t *testing.T) {
1392 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1393 defer MustClose(t, term)
1394 MustStart(t, term)
1395
1396 WriteF(t, term, "\033[1;1H\033[0J")
1397 WriteF(t, term, "ABC123")
1398 WriteF(t, term, "\033[?69h")
1399 WriteF(t, term, "\033[3;5s")
1400 WriteF(t, term, "\x1b[4G")
1401 WriteF(t, term, "\033[P")
1402
1403 // |ABC2_3__|
1404 // |________|
1405 // |________|
1406 // |________|
1407
1408 CheckPos(t, term, 3, 0)
1409 CheckContent(t, term, 0, 0, "A")
1410 CheckContent(t, term, 1, 0, "B")
1411 CheckContent(t, term, 2, 0, "C")
1412 CheckContent(t, term, 3, 0, "2")
1413 CheckContent(t, term, 4, 0, "")
1414 CheckContent(t, term, 5, 0, "3")
1415 CheckContent(t, term, 6, 0, "")
1416 }
1417
1418 // TestDCv5 tests delete character splitting a wide character.
1419 func TestDCv5(t *testing.T) {
1420 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1421 defer MustClose(t, term)
1422 MustStart(t, term)
1423
1424 WriteF(t, term, "\033[1;1H\033[0J")
1425 WriteF(t, term, "A橋123")
1426 WriteF(t, term, "\x1b[3G")
1427 WriteF(t, term, "\033[P")
1428
1429 // |A_123___|
1430 // |________|
1431 // |________|
1432 // |________|
1433
1434 CheckPos(t, term, 2, 0)
1435 CheckContent(t, term, 0, 0, "A")
1436 CheckContent(t, term, 1, 0, "")
1437 CheckContent(t, term, 2, 0, "1")
1438 CheckContent(t, term, 3, 0, "2")
1439 CheckContent(t, term, 4, 0, "3")
1440 CheckContent(t, term, 5, 0, "")
1441 CheckContent(t, term, 6, 0, "")
1442 }
1443
1444 // TestICHv1 tests insert character without a scroll region, fitting on screen.
1445 func TestICHv1(t *testing.T) {
1446 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1447 defer MustClose(t, term)
1448 MustStart(t, term)
1449
1450 WriteF(t, term, "ABC")
1451 WriteF(t, term, "\033[1G")
1452 WriteF(t, term, "\x1b[2@")
1453 WriteF(t, term, "X")
1454
1455 // |XcABC___|
1456 // |________|
1457 // |________|
1458 // |________|
1459
1460 CheckPos(t, term, 1, 0)
1461 CheckContent(t, term, 0, 0, "X")
1462 CheckContent(t, term, 1, 0, "")
1463 CheckContent(t, term, 2, 0, "A")
1464 CheckContent(t, term, 3, 0, "B")
1465 CheckContent(t, term, 4, 0, "C")
1466 CheckContent(t, term, 5, 0, "")
1467 CheckContent(t, term, 6, 0, "")
1468 }
1469
1470 // TestICHv2 tests insert character SGR state.
1471 func TestICHv2(t *testing.T) {
1472 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1473 defer MustClose(t, term)
1474 MustStart(t, term)
1475
1476 WriteF(t, term, "\033[1;1H\033[0J")
1477 WriteF(t, term, "ABC")
1478 WriteF(t, term, "\033[1G")
1479 WriteF(t, term, "\033[41m\033[7m")
1480 WriteF(t, term, "\x1b[2@")
1481 WriteF(t, term, "X")
1482
1483 // |XcABC___|
1484 // |________|
1485 // |________|
1486 // |________|
1487
1488 CheckPos(t, term, 1, 0)
1489 CheckContent(t, term, 0, 0, "X")
1490 CheckContent(t, term, 1, 0, "")
1491 CheckContent(t, term, 2, 0, "A")
1492 CheckContent(t, term, 3, 0, "B")
1493 CheckContent(t, term, 4, 0, "C")
1494 CheckContent(t, term, 5, 0, "")
1495 CheckContent(t, term, 6, 0, "")
1496 CheckAttrs(t, term, 0, 0, vt.Reverse)
1497 CheckAttrs(t, term, 1, 0, vt.Reverse)
1498 CheckAttrs(t, term, 2, 0, vt.Plain)
1499 CheckAttrs(t, term, 3, 0, vt.Plain)
1500 CheckAttrs(t, term, 4, 0, vt.Plain)
1501 CheckColors(t, term, 0, 0, color.Silver, color.Maroon)
1502 CheckColors(t, term, 1, 0, color.Silver, color.Maroon)
1503 CheckColors(t, term, 2, 0, color.Silver, color.Black)
1504 CheckColors(t, term, 3, 0, color.Silver, color.Black)
1505 CheckColors(t, term, 4, 0, color.Silver, color.Black)
1506 }
1507
1508 // TestICHv3 tests insert character shifting off screen
1509 func TestICHv3(t *testing.T) {
1510 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1511 defer MustClose(t, term)
1512 MustStart(t, term)
1513
1514 WriteF(t, term, "\033[1;1H\033[0J")
1515 WriteF(t, term, "\033[8G")
1516 WriteF(t, term, "\033[2D")
1517 WriteF(t, term, "ABC")
1518 WriteF(t, term, "\033[2D")
1519 WriteF(t, term, "\033[2@")
1520 WriteF(t, term, "X")
1521
1522 // |_____XcA|
1523 // |________|
1524 // |________|
1525 // |________|
1526
1527 CheckPos(t, term, 6, 0)
1528 CheckContent(t, term, 0, 0, "")
1529 CheckContent(t, term, 1, 0, "")
1530 CheckContent(t, term, 2, 0, "")
1531 CheckContent(t, term, 3, 0, "")
1532 CheckContent(t, term, 4, 0, "")
1533 CheckContent(t, term, 5, 0, "X")
1534 CheckContent(t, term, 6, 0, "")
1535 CheckContent(t, term, 7, 0, "A")
1536 }
1537
1538 // TestICHv4 tests insert character inside left and right scroll regions.
1539 func TestICHv4(t *testing.T) {
1540 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1541 defer MustClose(t, term)
1542 MustStart(t, term)
1543
1544 WriteF(t, term, "\033[1;1H\033[0J")
1545 WriteF(t, term, "\033[?69h")
1546 WriteF(t, term, "\033[3;5s")
1547 WriteF(t, term, "\033[3G")
1548 WriteF(t, term, "ABC")
1549 WriteF(t, term, "\033[3G")
1550 WriteF(t, term, "\033[2@")
1551 WriteF(t, term, "X")
1552
1553 // |__XcA___|
1554 // |________|
1555 // |________|
1556 // |________|
1557
1558 CheckPos(t, term, 3, 0)
1559 CheckContent(t, term, 0, 0, "")
1560 CheckContent(t, term, 1, 0, "")
1561 CheckContent(t, term, 2, 0, "X")
1562 CheckContent(t, term, 3, 0, "")
1563 CheckContent(t, term, 4, 0, "A")
1564 CheckContent(t, term, 5, 0, "")
1565 CheckContent(t, term, 6, 0, "")
1566 CheckContent(t, term, 7, 0, "")
1567 }
1568
1569 // TestICHv5 tests insert character outside left and right scroll regions.
1570 func TestICHv5(t *testing.T) {
1571 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1572 defer MustClose(t, term)
1573 MustStart(t, term)
1574
1575 WriteF(t, term, "\033[1;1H\033[0J")
1576 WriteF(t, term, "\033[?69h")
1577 WriteF(t, term, "\033[3;5s")
1578 WriteF(t, term, "\033[3G")
1579 WriteF(t, term, "ABC")
1580 WriteF(t, term, "\033[1G")
1581 WriteF(t, term, "\033[2@")
1582 WriteF(t, term, "X")
1583
1584 // |XcABC___|
1585 // |________|
1586 // |________|
1587 // |________|
1588
1589 CheckPos(t, term, 1, 0)
1590 CheckContent(t, term, 0, 0, "X")
1591 CheckContent(t, term, 1, 0, "")
1592 CheckContent(t, term, 2, 0, "A")
1593 CheckContent(t, term, 3, 0, "B")
1594 CheckContent(t, term, 4, 0, "C")
1595 CheckContent(t, term, 5, 0, "")
1596 CheckContent(t, term, 6, 0, "")
1597 CheckContent(t, term, 7, 0, "")
1598 }
1599
1600 // TestICHv5a tests insert character outside left and right scroll regions resets auto-wrap.
1601 func TestICHv5a(t *testing.T) {
1602 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1603 defer MustClose(t, term)
1604 MustStart(t, term)
1605
1606 WriteF(t, term, "\033[1;1H\033[0J")
1607 WriteF(t, term, "\033[?69h")
1608 WriteF(t, term, "\033[3;5s")
1609 WriteF(t, term, "\033[3G")
1610 WriteF(t, term, "ABC")
1611 WriteF(t, term, "\033[8G")
1612 WriteF(t, term, "X")
1613 WriteF(t, term, "\033[2@")
1614 WriteF(t, term, "Y")
1615 WriteF(t, term, "Z")
1616
1617 // |__ABC__Y|
1618 // |Zc______|
1619 // |________|
1620 // |________|
1621
1622 CheckPos(t, term, 1, 1)
1623 CheckContent(t, term, 0, 0, "")
1624 CheckContent(t, term, 1, 0, "")
1625 CheckContent(t, term, 2, 0, "A")
1626 CheckContent(t, term, 3, 0, "B")
1627 CheckContent(t, term, 4, 0, "C")
1628 CheckContent(t, term, 5, 0, "")
1629 CheckContent(t, term, 6, 0, "")
1630 CheckContent(t, term, 7, 0, "Y")
1631 CheckContent(t, term, 0, 1, "Z")
1632 }
1633
1634 // TestICHv6 tests insert character splitting a wide character on the right of the screen.
1635 func TestICHv6(t *testing.T) {
1636 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1637 defer MustClose(t, term)
1638 MustStart(t, term)
1639
1640 WriteF(t, term, "\033[8G")
1641 WriteF(t, term, "\033[1D")
1642 WriteF(t, term, "橋")
1643 WriteF(t, term, "\033[2D")
1644 WriteF(t, term, "\033[@")
1645 WriteF(t, term, "X")
1646
1647 // |_____Xc_|
1648
1649 CheckPos(t, term, 6, 0)
1650 CheckContent(t, term, 0, 0, "")
1651 CheckContent(t, term, 1, 0, "")
1652 CheckContent(t, term, 2, 0, "")
1653 CheckContent(t, term, 3, 0, "")
1654 CheckContent(t, term, 4, 0, "")
1655 CheckContent(t, term, 5, 0, "X")
1656 CheckContent(t, term, 6, 0, "")
1657 CheckContent(t, term, 7, 0, "")
1658 }
1659
1660 // TestICHv6a tests insert character splitting a wide character at the right margin.
1661 func TestICHv6a(t *testing.T) {
1662 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1663 defer MustClose(t, term)
1664 MustStart(t, term)
1665
1666 WriteF(t, term, "\033[4G")
1667 WriteF(t, term, "橋")
1668 WriteF(t, term, "\033[?69h")
1669 WriteF(t, term, "\033[3;5s")
1670 WriteF(t, term, "\033[3G")
1671 WriteF(t, term, "\033[@")
1672 WriteF(t, term, "X")
1673
1674 // |__Xc____|
1675
1676 CheckPos(t, term, 3, 0)
1677 CheckContent(t, term, 0, 0, "")
1678 CheckContent(t, term, 1, 0, "")
1679 CheckContent(t, term, 2, 0, "X")
1680 CheckContent(t, term, 3, 0, "")
1681 CheckContent(t, term, 4, 0, "")
1682 CheckContent(t, term, 5, 0, "")
1683 CheckContent(t, term, 6, 0, "")
1684 }
1685
1686 // TestICHv6b tests insert character splitting a wide character at the left margin.
1687 func TestICHv6b(t *testing.T) {
1688 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1689 defer MustClose(t, term)
1690 MustStart(t, term)
1691
1692 WriteF(t, term, "\033[2G")
1693 WriteF(t, term, "橋")
1694 WriteF(t, term, "\033[?69h")
1695 WriteF(t, term, "\033[3;5s")
1696 WriteF(t, term, "\033[3G")
1697 WriteF(t, term, "\033[@")
1698 WriteF(t, term, "X")
1699
1700 // |__Xc____|
1701
1702 CheckPos(t, term, 3, 0)
1703 CheckContent(t, term, 0, 0, "")
1704 CheckContent(t, term, 1, 0, "")
1705 CheckContent(t, term, 2, 0, "X")
1706 CheckContent(t, term, 3, 0, "")
1707 CheckContent(t, term, 4, 0, "")
1708 CheckContent(t, term, 5, 0, "")
1709 CheckContent(t, term, 6, 0, "")
1710 }
1711
1712 // TestDECSCUSRv1 tests setting the cursor.
1713 func TestDECSCUSRv1(t *testing.T) {
1714 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1715 defer MustClose(t, term)
1716 MustStart(t, term)
1717
1718 WriteF(t, term, "\033[ q")
1719 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock, "")
1720 WriteF(t, term, "\033[0 q")
1721 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock, "")
1722 WriteF(t, term, "\033[1 q")
1723 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock, "")
1724 WriteF(t, term, "\033[2 q")
1725 VerifyF(t, term.Backend().GetCursor() == vt.SteadyBlock, "")
1726 WriteF(t, term, "\033[3 q")
1727 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingUnderline, "")
1728 WriteF(t, term, "\033[4 q")
1729 VerifyF(t, term.Backend().GetCursor() == vt.SteadyUnderline, "")
1730 WriteF(t, term, "\033[5 q")
1731 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBar, "")
1732 WriteF(t, term, "\033[6 q")
1733 VerifyF(t, term.Backend().GetCursor() == vt.SteadyBar, "")
1734 }
1735
1736 // TestDECSCUSRv2 tests setting the cursor while hidden.
1737 func TestDECSCUSRv2(t *testing.T) {
1738 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1739 defer MustClose(t, term)
1740 MustStart(t, term)
1741
1742 WriteF(t, term, "\033[?25l")
1743 WriteF(t, term, "\033[ q")
1744 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock.Hide(), "")
1745 WriteF(t, term, "\033[0 q")
1746 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock.Hide(), "")
1747 WriteF(t, term, "\033[1 q")
1748 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock.Hide(), "")
1749 WriteF(t, term, "\033[2 q")
1750 VerifyF(t, term.Backend().GetCursor() == vt.SteadyBlock.Hide(), "")
1751 WriteF(t, term, "\033[3 q")
1752 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingUnderline.Hide(), "")
1753 WriteF(t, term, "\033[4 q")
1754 VerifyF(t, term.Backend().GetCursor() == vt.SteadyUnderline.Hide(), "")
1755 WriteF(t, term, "\033[5 q")
1756 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBar.Hide(), "")
1757 WriteF(t, term, "\033[6 q")
1758 VerifyF(t, term.Backend().GetCursor() == vt.SteadyBar.Hide(), "")
1759 }
1760
1761 // TestDECSCUSRv3 tests setting the blink private mode.
1762 func TestDECSCUSRv3(t *testing.T) {
1763 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1764 defer MustClose(t, term)
1765 MustStart(t, term)
1766
1767 WriteF(t, term, "\033[0 q")
1768 WriteF(t, term, "\033[?12l")
1769 VerifyF(t, term.Backend().GetCursor() == vt.SteadyBlock, "")
1770 WriteF(t, term, "\033[?12h")
1771 VerifyF(t, term.Backend().GetCursor() == vt.BlinkingBlock, "")
1772 }
1773
1774 // TestOSC8v1 tests hyperlinks.
1775 func TestOSC8v1(t *testing.T) {
1776 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1777 defer MustClose(t, term)
1778 MustStart(t, term)
1779
1780 WriteF(t, term, "\033]8;bob=junk:id=123:junk;https://example.com\033\\")
1781 WriteF(t, term, "Hello")
1782 WriteF(t, term, "\033]8;;\033\\")
1783 WriteF(t, term, " World!")
1784
1785 term.Drain()
1786 for col := range Col(10) {
1787 cell := term.GetCell(Coord{X: col, Y: 0})
1788 if col < 5 {
1789 if u, i := cell.S.Url(); u != "https://example.com" || i != "123" {
1790 t.Errorf("wrong data at column %d: url %q id %q", col, u, i)
1791 }
1792 } else {
1793 if u, i := cell.S.Url(); u != "" || i != "" {
1794 t.Errorf("wrong data at column %d: url %q id %q", col, u, i)
1795 }
1796 }
1797 }
1798 }
1799
1800 // TestOSC52v1 tests pasting and retrieving the clipboard.
1801 func TestOSC52v1(t *testing.T) {
1802 term := vt.NewMockTerm(vt.MockOptSize{X: 8, Y: 5})
1803 defer MustClose(t, term)
1804 MustStart(t, term)
1805
1806 str := "Hello, World."
1807 enc := make([]byte, base64.StdEncoding.EncodedLen(len(str)))
1808 base64.StdEncoding.Encode(enc, []byte(str))
1809
1810 WriteF(t, term, "\033]52;c;%s\033\\", enc)
1811 VerifyF(t, string(term.Backend().GetClipboard()) == str, "clipboard contents did not match (%s != %s)",
1812 string(term.Backend().GetClipboard()), str)
1813 WriteF(t, term, "\033]52;c;?\033\\")
1814
1815 response := ReadF(t, term)
1816 expect := fmt.Sprintf("\033]52;c;%s\033\\", enc)
1817 VerifyF(t, response == expect, "retrieved value did not match (%q != %q)", response, expect)
1818
1819 // any invalid base64 clears the clipboard
1820 WriteF(t, term, "\033]52;c;junk1\033\\")
1821 VerifyF(t, string(term.Backend().GetClipboard()) == "", "")
1822
1823 // empty clears the clipboard
1824 term.Backend().SetClipboard([]byte("something"))
1825 WriteF(t, term, "\033]52;c;\033\\")
1826 VerifyF(t, string(term.Backend().GetClipboard()) == "", "")
1827
1828 // but a bogus sequence without two fields does nothing
1829 term.Backend().SetClipboard([]byte("something"))
1830 WriteF(t, term, "\033]52;x\033\\")
1831 VerifyF(t, string(term.Backend().GetClipboard()) == "something", "")
1832 }