| 1 |
package vt |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
uv "github.com/charmbracelet/ultraviolet" |
| 7 |
) |
| 8 |
|
| 9 |
// testLogger wraps a testing.TB to implement the Logger interface. |
| 10 |
type testLogger struct { |
| 11 |
t testing.TB |
| 12 |
} |
| 13 |
|
| 14 |
// Printf implements the Logger interface. |
| 15 |
func (l *testLogger) Printf(format string, v ...any) { |
| 16 |
l.t.Logf(format, v...) |
| 17 |
} |
| 18 |
|
| 19 |
// newTestTerminal creates a new test terminal. |
| 20 |
func newTestTerminal(t testing.TB, width, height int) *Emulator { |
| 21 |
term := NewEmulator(width, height) |
| 22 |
term.SetLogger(&testLogger{t}) |
| 23 |
return term |
| 24 |
} |
| 25 |
|
| 26 |
var cases = []struct { |
| 27 |
name string |
| 28 |
w, h int |
| 29 |
input []string |
| 30 |
want []string |
| 31 |
pos uv.Position |
| 32 |
}{ |
| 33 |
// Cursor Backward Tabulation [ansi.CBT] |
| 34 |
{ |
| 35 |
name: "CBT Left Beyond First Column", |
| 36 |
w: 10, h: 1, |
| 37 |
input: []string{ |
| 38 |
"\x1b[?W", // reset tab stops |
| 39 |
"\x1b[10Z", |
| 40 |
"A", |
| 41 |
}, |
| 42 |
want: []string{"A "}, |
| 43 |
pos: uv.Pos(1, 0), |
| 44 |
}, |
| 45 |
{ |
| 46 |
name: "CBT Left Starting After Tab Stop", |
| 47 |
w: 11, h: 1, |
| 48 |
input: []string{ |
| 49 |
"\x1b[?W", // reset tab stops |
| 50 |
"\x1b[1;10H", |
| 51 |
"X", |
| 52 |
"\x1b[Z", |
| 53 |
"A", |
| 54 |
}, |
| 55 |
want: []string{" AX "}, |
| 56 |
pos: uv.Pos(9, 0), |
| 57 |
}, |
| 58 |
{ |
| 59 |
name: "CBT Left Starting on Tabstop", |
| 60 |
w: 10, h: 1, |
| 61 |
input: []string{ |
| 62 |
"\x1b[?W", // reset tab stops |
| 63 |
"\x1b[1;9H", |
| 64 |
"X", |
| 65 |
"\x1b[1;9H", |
| 66 |
"\x1b[Z", |
| 67 |
"A", |
| 68 |
}, |
| 69 |
want: []string{"A X "}, |
| 70 |
pos: uv.Pos(1, 0), |
| 71 |
}, |
| 72 |
{ |
| 73 |
name: "CBT Left Margin with Origin Mode", |
| 74 |
w: 10, h: 1, |
| 75 |
input: []string{ |
| 76 |
"\x1b[1;1H", // move to top left |
| 77 |
"\x1b[2J", // clear screen |
| 78 |
"\x1b[?W", // reset tab stops |
| 79 |
"\x1b[?6h", // origin mode |
| 80 |
"\x1b[?69h", // left margin mode |
| 81 |
"\x1b[3;6s", // scroll region left/right |
| 82 |
"\x1b[1;2H", |
| 83 |
"X", |
| 84 |
"\x1b[Z", |
| 85 |
"A", |
| 86 |
}, |
| 87 |
want: []string{" AX "}, |
| 88 |
pos: uv.Pos(3, 0), |
| 89 |
}, |
| 90 |
|
| 91 |
// Cursor Horizontal Tabulation [ansi.CHT] |
| 92 |
{ |
| 93 |
name: "CHT Right Beyond Last Column", |
| 94 |
w: 10, h: 1, |
| 95 |
input: []string{ |
| 96 |
"\x1b[?W", // reset tab stops |
| 97 |
"\x1b[100I", // move right 100 tab stops |
| 98 |
"A", |
| 99 |
}, |
| 100 |
want: []string{" A"}, |
| 101 |
pos: uv.Pos(9, 0), |
| 102 |
}, |
| 103 |
{ |
| 104 |
name: "CHT Right From Before Tabstop", |
| 105 |
w: 10, h: 1, |
| 106 |
input: []string{ |
| 107 |
"\x1b[?W", // reset tab stops |
| 108 |
"\x1b[1;2H", // move to column 2 |
| 109 |
"A", |
| 110 |
"\x1b[I", // move right one tab stop |
| 111 |
"X", |
| 112 |
}, |
| 113 |
want: []string{" A X "}, |
| 114 |
pos: uv.Pos(9, 0), |
| 115 |
}, |
| 116 |
{ |
| 117 |
name: "CHT Right Margin", |
| 118 |
w: 10, h: 1, |
| 119 |
input: []string{ |
| 120 |
"\x1b[1;1H", // move to top-left |
| 121 |
"\x1b[2J", // clear screen |
| 122 |
"\x1b[?W", // reset tab stops |
| 123 |
"\x1b[?69h", // enable left/right margins |
| 124 |
"\x1b[3;6s", // scroll region left/right |
| 125 |
"\x1b[1;1H", // move cursor in region |
| 126 |
"X", |
| 127 |
"\x1b[I", // move right one tab stop |
| 128 |
"A", |
| 129 |
}, |
| 130 |
want: []string{"X A "}, |
| 131 |
pos: uv.Pos(6, 0), |
| 132 |
}, |
| 133 |
|
| 134 |
// Carriage Return [ansi.CR] |
| 135 |
{ |
| 136 |
name: "CR Pending Wrap is Unset", |
| 137 |
w: 10, h: 2, |
| 138 |
input: []string{ |
| 139 |
"\x1b[10G", // move to last column |
| 140 |
"A", // set pending wrap state |
| 141 |
"\r", // carriage return |
| 142 |
"X", |
| 143 |
}, |
| 144 |
want: []string{ |
| 145 |
"X A", |
| 146 |
" ", |
| 147 |
}, |
| 148 |
pos: uv.Pos(1, 0), |
| 149 |
}, |
| 150 |
{ |
| 151 |
name: "CR Left Margin", |
| 152 |
w: 10, h: 1, |
| 153 |
input: []string{ |
| 154 |
"\x1b[1;1H", // move to top-left |
| 155 |
"\x1b[2J", // clear screen |
| 156 |
"\x1b[?69h", // enable left/right margin mode |
| 157 |
"\x1b[2;5s", // set left/right margin |
| 158 |
"\x1b[4G", // move to column 4 |
| 159 |
"A", |
| 160 |
"\r", |
| 161 |
"X", |
| 162 |
}, |
| 163 |
want: []string{" X A "}, |
| 164 |
pos: uv.Pos(2, 0), |
| 165 |
}, |
| 166 |
{ |
| 167 |
name: "CR Left of Left Margin", |
| 168 |
w: 10, h: 1, |
| 169 |
input: []string{ |
| 170 |
"\x1b[1;1H", // move to top-left |
| 171 |
"\x1b[2J", // clear screen |
| 172 |
"\x1b[?69h", // enable left/right margin mode |
| 173 |
"\x1b[2;5s", // set left/right margin |
| 174 |
"\x1b[4G", // move to column 4 |
| 175 |
"A", |
| 176 |
"\x1b[1G", |
| 177 |
"\r", |
| 178 |
"X", |
| 179 |
}, |
| 180 |
want: []string{"X A "}, |
| 181 |
pos: uv.Pos(1, 0), |
| 182 |
}, |
| 183 |
{ |
| 184 |
name: "CR Left Margin with Origin Mode", |
| 185 |
w: 10, h: 1, |
| 186 |
input: []string{ |
| 187 |
"\x1b[1;1H", // move to top-left |
| 188 |
"\x1b[2J", // clear screen |
| 189 |
"\x1b[?6h", // enable origin mode |
| 190 |
"\x1b[?69h", // enable left/right margin mode |
| 191 |
"\x1b[2;5s", // set left/right margin |
| 192 |
"\x1b[4G", // move to column 4 |
| 193 |
"A", |
| 194 |
"\x1b[1G", |
| 195 |
"\r", |
| 196 |
"X", |
| 197 |
}, |
| 198 |
want: []string{" X A "}, |
| 199 |
pos: uv.Pos(2, 0), |
| 200 |
}, |
| 201 |
|
| 202 |
// Cursor Backward [ansi.CUB] |
| 203 |
{ |
| 204 |
name: "CUB Pending Wrap is Unset", |
| 205 |
w: 10, h: 2, |
| 206 |
input: []string{ |
| 207 |
"\x1b[10G", // move to last column |
| 208 |
"A", // set pending wrap state |
| 209 |
"\x1b[D", // move back one |
| 210 |
"XYZ", |
| 211 |
}, |
| 212 |
want: []string{ |
| 213 |
" XY", |
| 214 |
"Z ", |
| 215 |
}, |
| 216 |
pos: uv.Pos(1, 1), |
| 217 |
}, |
| 218 |
{ |
| 219 |
name: "CUB Leftmost Boundary with Reverse Wrap Disabled", |
| 220 |
w: 10, h: 2, |
| 221 |
input: []string{ |
| 222 |
"\x1b[?45l", // disable reverse wrap |
| 223 |
"A\n", |
| 224 |
"\x1b[10D", // back |
| 225 |
"B", |
| 226 |
}, |
| 227 |
want: []string{ |
| 228 |
"A ", |
| 229 |
"B ", |
| 230 |
}, |
| 231 |
pos: uv.Pos(1, 1), |
| 232 |
}, |
| 233 |
{ |
| 234 |
name: "CUB Reverse Wrap", |
| 235 |
w: 10, h: 2, |
| 236 |
input: []string{ |
| 237 |
"\x1b[?7h", // enable wraparound |
| 238 |
"\x1b[?45h", // enable reverse wrap |
| 239 |
"\x1b[1;1H", // move to top-left |
| 240 |
"\x1b[2J", // clear screen |
| 241 |
"\x1b[10G", // move to end of line |
| 242 |
"AB", // write and wrap |
| 243 |
"\x1b[D", // move back one |
| 244 |
"X", |
| 245 |
}, |
| 246 |
want: []string{ |
| 247 |
" A", |
| 248 |
"X ", |
| 249 |
}, |
| 250 |
pos: uv.Pos(1, 1), |
| 251 |
}, |
| 252 |
// XXX: Support Reverse Wrap (XTREVWRAP) and Extended Reverse Wrap (XTREVWRAP2) |
| 253 |
// { |
| 254 |
// name: "CUB Extended Reverse Wrap Single Line", |
| 255 |
// w: 10, h: 2, |
| 256 |
// input: []string{ |
| 257 |
// "\x1b[?7h", // enable wraparound |
| 258 |
// "\x1b[?1045h", // enable extended reverse wrap |
| 259 |
// "\x1b[1;1H", // move to top-left |
| 260 |
// "\x1b[2J", // clear screen |
| 261 |
// "A\nB", |
| 262 |
// "\x1b[2D", // move back two |
| 263 |
// "X", |
| 264 |
// }, |
| 265 |
// want: []string{ |
| 266 |
// "A X", |
| 267 |
// "B ", |
| 268 |
// }, |
| 269 |
// pos: uv.Pos(9, 0), |
| 270 |
// }, |
| 271 |
// { |
| 272 |
// name: "CUB Extended Reverse Wrap Wraps to Bottom", |
| 273 |
// w: 10, h: 3, |
| 274 |
// input: []string{ |
| 275 |
// "\x1b[?7h", // enable wraparound |
| 276 |
// "\x1b[?1045h", // enable extended reverse wrap |
| 277 |
// "\x1b[1;1H", // move to top-left |
| 278 |
// "\x1b[2J", // clear screen |
| 279 |
// "\x1b[1;3r", // set scrolling region |
| 280 |
// "A\nB", |
| 281 |
// "\x1b[D", // move back one |
| 282 |
// "\x1b[10D", // move back entire width |
| 283 |
// "\x1b[D", // move back one |
| 284 |
// "X", |
| 285 |
// }, |
| 286 |
// want: []string{ |
| 287 |
// "A ", |
| 288 |
// "B ", |
| 289 |
// " X", |
| 290 |
// }, |
| 291 |
// pos: uv.Pos(9, 2), |
| 292 |
// }, |
| 293 |
// { |
| 294 |
// name: "CUB Reverse Wrap Outside of Margins", |
| 295 |
// w: 10, h: 3, |
| 296 |
// input: []string{ |
| 297 |
// "\x1b[1;1H", // move to top-left |
| 298 |
// "\x1b[2J", // clear screen |
| 299 |
// "\x1b[?45h", // enable reverse wrap |
| 300 |
// "\x1b[3r", // set scroll region |
| 301 |
// "\b", // backspace |
| 302 |
// "X", |
| 303 |
// }, |
| 304 |
// want: []string{ |
| 305 |
// " ", |
| 306 |
// " ", |
| 307 |
// "X ", |
| 308 |
// }, |
| 309 |
// pos: uv.Pos(1, 2), |
| 310 |
// }, |
| 311 |
// { |
| 312 |
// name: "CUB Reverse Wrap with Pending Wrap State", |
| 313 |
// w: 10, h: 1, |
| 314 |
// input: []string{ |
| 315 |
// "\x1b[?45h", // enable reverse wrap |
| 316 |
// "\x1b[10G", // move to end |
| 317 |
// "\x1b[4D", // back 4 |
| 318 |
// "ABCDE", |
| 319 |
// "\x1b[D", // back 1 |
| 320 |
// "X", |
| 321 |
// }, |
| 322 |
// want: []string{ |
| 323 |
// " ABCDX", |
| 324 |
// }, |
| 325 |
// pos: uv.Pos(9, 0), |
| 326 |
// }, |
| 327 |
|
| 328 |
// Cursor Down [ansi.CUD] |
| 329 |
{ |
| 330 |
name: "CUD Cursor Down", |
| 331 |
w: 10, h: 3, |
| 332 |
input: []string{ |
| 333 |
"A", |
| 334 |
"\x1b[2B", // cursor down 2 lines |
| 335 |
"X", |
| 336 |
}, |
| 337 |
want: []string{ |
| 338 |
"A ", |
| 339 |
" ", |
| 340 |
" X ", |
| 341 |
}, |
| 342 |
pos: uv.Pos(2, 2), |
| 343 |
}, |
| 344 |
{ |
| 345 |
name: "CUD Cursor Down Above Bottom Margin", |
| 346 |
w: 10, h: 4, |
| 347 |
input: []string{ |
| 348 |
"\x1b[1;1H", // move to top-left |
| 349 |
"\x1b[2J", // clear screen |
| 350 |
"\n\n\n\n", // move down 4 lines |
| 351 |
"\x1b[1;3r", // set scrolling region |
| 352 |
"A", |
| 353 |
"\x1b[5B", // cursor down 5 lines |
| 354 |
"X", |
| 355 |
}, |
| 356 |
want: []string{ |
| 357 |
"A ", |
| 358 |
" ", |
| 359 |
" X ", |
| 360 |
" ", |
| 361 |
}, |
| 362 |
pos: uv.Pos(2, 2), |
| 363 |
}, |
| 364 |
{ |
| 365 |
name: "CUD Cursor Down Below Bottom Margin", |
| 366 |
w: 10, h: 5, |
| 367 |
input: []string{ |
| 368 |
"\x1b[1;1H", // move to top-left |
| 369 |
"\x1b[2J", // clear screen |
| 370 |
"\n\n\n\n\n", // move down 5 lines |
| 371 |
"\x1b[1;3r", // set scrolling region |
| 372 |
"A", |
| 373 |
"\x1b[4;1H", // move below region |
| 374 |
"\x1b[5B", // cursor down 5 lines |
| 375 |
"X", |
| 376 |
}, |
| 377 |
want: []string{ |
| 378 |
"A ", |
| 379 |
" ", |
| 380 |
" ", |
| 381 |
" ", |
| 382 |
"X ", |
| 383 |
}, |
| 384 |
pos: uv.Pos(1, 4), |
| 385 |
}, |
| 386 |
|
| 387 |
// Cursor Position [ansi.CUP] |
| 388 |
{ |
| 389 |
name: "CUP Normal Usage", |
| 390 |
w: 10, h: 2, |
| 391 |
input: []string{ |
| 392 |
"\x1b[1;1H", // move to top-left |
| 393 |
"\x1b[2J", // clear screen |
| 394 |
"\x1b[2;3H", // move to row 2, col 3 |
| 395 |
"A", |
| 396 |
}, |
| 397 |
want: []string{ |
| 398 |
" ", |
| 399 |
" A ", |
| 400 |
}, |
| 401 |
pos: uv.Pos(3, 1), |
| 402 |
}, |
| 403 |
{ |
| 404 |
name: "CUP Off the Screen", |
| 405 |
w: 10, h: 3, |
| 406 |
input: []string{ |
| 407 |
"\x1b[1;1H", // move to top-left |
| 408 |
"\x1b[2J", // clear screen |
| 409 |
"\x1b[500;500H", // move way off screen |
| 410 |
"A", |
| 411 |
}, |
| 412 |
want: []string{ |
| 413 |
" ", |
| 414 |
" ", |
| 415 |
" A", |
| 416 |
}, |
| 417 |
pos: uv.Pos(9, 2), |
| 418 |
}, |
| 419 |
{ |
| 420 |
name: "CUP Relative to Origin", |
| 421 |
w: 10, h: 2, |
| 422 |
input: []string{ |
| 423 |
"\x1b[1;1H", // move to top-left |
| 424 |
"\x1b[2J", // clear screen |
| 425 |
"\x1b[2;3r", // scroll region top/bottom |
| 426 |
"\x1b[?6h", // origin mode |
| 427 |
"\x1b[1;1H", // move to top-left |
| 428 |
"X", |
| 429 |
}, |
| 430 |
want: []string{ |
| 431 |
" ", |
| 432 |
"X ", |
| 433 |
}, |
| 434 |
pos: uv.Pos(1, 1), |
| 435 |
}, |
| 436 |
{ |
| 437 |
name: "CUP Relative to Origin with Margins", |
| 438 |
w: 10, h: 2, |
| 439 |
input: []string{ |
| 440 |
"\x1b[1;1H", // move to top-left |
| 441 |
"\x1b[2J", // clear screen |
| 442 |
"\x1b[?69h", // enable left/right margins |
| 443 |
"\x1b[3;5s", // scroll region left/right |
| 444 |
"\x1b[2;3r", // scroll region top/bottom |
| 445 |
"\x1b[?6h", // origin mode |
| 446 |
"\x1b[1;1H", // move to top-left |
| 447 |
"X", |
| 448 |
}, |
| 449 |
want: []string{ |
| 450 |
" ", |
| 451 |
" X ", |
| 452 |
}, |
| 453 |
pos: uv.Pos(3, 1), |
| 454 |
}, |
| 455 |
{ |
| 456 |
name: "CUP Limits with Scroll Region and Origin Mode", |
| 457 |
w: 10, h: 3, |
| 458 |
input: []string{ |
| 459 |
"\x1b[1;1H", // move to top-left |
| 460 |
"\x1b[2J", // clear screen |
| 461 |
"\x1b[?69h", // enable left/right margins |
| 462 |
"\x1b[3;5s", // scroll region left/right |
| 463 |
"\x1b[2;3r", // scroll region top/bottom |
| 464 |
"\x1b[?6h", // origin mode |
| 465 |
"\x1b[500;500H", // move way off screen |
| 466 |
"X", |
| 467 |
}, |
| 468 |
want: []string{ |
| 469 |
" ", |
| 470 |
" ", |
| 471 |
" X ", |
| 472 |
}, |
| 473 |
pos: uv.Pos(5, 2), |
| 474 |
}, |
| 475 |
{ |
| 476 |
name: "CUP Pending Wrap is Unset", |
| 477 |
w: 10, h: 1, |
| 478 |
input: []string{ |
| 479 |
"\x1b[10G", // move to last column |
| 480 |
"A", // set pending wrap state |
| 481 |
"\x1b[1;1H", |
| 482 |
"X", |
| 483 |
}, |
| 484 |
want: []string{ |
| 485 |
"X A", |
| 486 |
}, |
| 487 |
pos: uv.Pos(1, 0), |
| 488 |
}, |
| 489 |
|
| 490 |
// Cursor Forward [ansi.CUF] |
| 491 |
{ |
| 492 |
name: "CUF Pending Wrap is Unset", |
| 493 |
w: 10, h: 2, |
| 494 |
input: []string{ |
| 495 |
"\x1b[10G", // move to last column |
| 496 |
"A", // set pending wrap state |
| 497 |
"\x1b[C", // move forward one |
| 498 |
"XYZ", |
| 499 |
}, |
| 500 |
want: []string{ |
| 501 |
" X", |
| 502 |
"YZ ", |
| 503 |
}, |
| 504 |
pos: uv.Pos(2, 1), |
| 505 |
}, |
| 506 |
{ |
| 507 |
name: "CUF Rightmost Boundary", |
| 508 |
w: 10, h: 1, |
| 509 |
input: []string{ |
| 510 |
"A", |
| 511 |
"\x1b[500C", // forward larger than screen width |
| 512 |
"B", |
| 513 |
}, |
| 514 |
want: []string{ |
| 515 |
"A B", |
| 516 |
}, |
| 517 |
pos: uv.Pos(9, 0), |
| 518 |
}, |
| 519 |
{ |
| 520 |
name: "CUF Left of Right Margin", |
| 521 |
w: 10, h: 1, |
| 522 |
input: []string{ |
| 523 |
"\x1b[1;1H", // move to top-left |
| 524 |
"\x1b[2J", // clear screen |
| 525 |
"\x1b[?69h", // enable left/right margins |
| 526 |
"\x1b[3;5s", // scroll region left/right |
| 527 |
"\x1b[1G", // move to left |
| 528 |
"\x1b[500C", // forward larger than screen width |
| 529 |
"X", |
| 530 |
}, |
| 531 |
want: []string{ |
| 532 |
" X ", |
| 533 |
}, |
| 534 |
pos: uv.Pos(5, 0), |
| 535 |
}, |
| 536 |
{ |
| 537 |
name: "CUF Right of Right Margin", |
| 538 |
w: 10, h: 1, |
| 539 |
input: []string{ |
| 540 |
"\x1b[1;1H", // move to top-left |
| 541 |
"\x1b[2J", // clear screen |
| 542 |
"\x1b[?69h", // enable left/right margins |
| 543 |
"\x1b[3;5s", // scroll region left/right |
| 544 |
"\x1b[6G", // move to right of margin |
| 545 |
"\x1b[500C", // forward larger than screen width |
| 546 |
"X", |
| 547 |
}, |
| 548 |
want: []string{ |
| 549 |
" X", |
| 550 |
}, |
| 551 |
pos: uv.Pos(9, 0), |
| 552 |
}, |
| 553 |
|
| 554 |
// Cursor Up [ansi.CUU] |
| 555 |
{ |
| 556 |
name: "CUU Normal Usage", |
| 557 |
w: 10, h: 3, |
| 558 |
input: []string{ |
| 559 |
"\x1b[1;1H", // move to top-left |
| 560 |
"\x1b[2J", // clear screen |
| 561 |
"\x1b[3;1H", // move to row 3 |
| 562 |
"A", |
| 563 |
"\x1b[2A", // cursor up 2 |
| 564 |
"X", |
| 565 |
}, |
| 566 |
want: []string{ |
| 567 |
" X ", |
| 568 |
" ", |
| 569 |
"A ", |
| 570 |
}, |
| 571 |
pos: uv.Pos(2, 0), |
| 572 |
}, |
| 573 |
{ |
| 574 |
name: "CUU Below Top Margin", |
| 575 |
w: 10, h: 4, |
| 576 |
input: []string{ |
| 577 |
"\x1b[1;1H", // move to top-left |
| 578 |
"\x1b[2J", // clear screen |
| 579 |
"\x1b[2;4r", // set scrolling region |
| 580 |
"\x1b[3;1H", // move to row 3 |
| 581 |
"A", |
| 582 |
"\x1b[5A", // cursor up 5 |
| 583 |
"X", |
| 584 |
}, |
| 585 |
want: []string{ |
| 586 |
" ", |
| 587 |
" X ", |
| 588 |
"A ", |
| 589 |
" ", |
| 590 |
}, |
| 591 |
pos: uv.Pos(2, 1), |
| 592 |
}, |
| 593 |
{ |
| 594 |
name: "CUU Above Top Margin", |
| 595 |
w: 10, h: 5, |
| 596 |
input: []string{ |
| 597 |
"\x1b[1;1H", // move to top-left |
| 598 |
"\x1b[2J", // clear screen |
| 599 |
"\x1b[3;5r", // set scrolling region |
| 600 |
"\x1b[3;1H", // move to row 3 |
| 601 |
"A", |
| 602 |
"\x1b[2;1H", // move above region |
| 603 |
"\x1b[5A", // cursor up 5 |
| 604 |
"X", |
| 605 |
}, |
| 606 |
want: []string{ |
| 607 |
"X ", |
| 608 |
" ", |
| 609 |
"A ", |
| 610 |
" ", |
| 611 |
" ", |
| 612 |
}, |
| 613 |
pos: uv.Pos(1, 0), |
| 614 |
}, |
| 615 |
|
| 616 |
// Delete Line [ansi.DL] |
| 617 |
{ |
| 618 |
name: "DL Simple Delete Line", |
| 619 |
w: 8, h: 3, |
| 620 |
input: []string{ |
| 621 |
"\x1b[1;1H", // move to top-left |
| 622 |
"\x1b[2J", // clear screen |
| 623 |
"ABC\r\n", |
| 624 |
"DEF\r\n", |
| 625 |
"GHI", |
| 626 |
"\x1b[2;2H", |
| 627 |
"\x1b[M", |
| 628 |
}, |
| 629 |
want: []string{ |
| 630 |
"ABC ", |
| 631 |
"GHI ", |
| 632 |
" ", |
| 633 |
}, |
| 634 |
pos: uv.Pos(0, 1), |
| 635 |
}, |
| 636 |
{ |
| 637 |
name: "DL Cursor Outside Scroll Region", |
| 638 |
w: 8, h: 3, |
| 639 |
input: []string{ |
| 640 |
"\x1b[1;1H", // move to top-left |
| 641 |
"\x1b[2J", // clear screen |
| 642 |
"ABC\r\n", |
| 643 |
"DEF\r\n", |
| 644 |
"GHI", |
| 645 |
"\x1b[3;4r", // scroll region top/bottom |
| 646 |
"\x1b[2;2H", |
| 647 |
"\x1b[M", |
| 648 |
}, |
| 649 |
want: []string{ |
| 650 |
"ABC ", |
| 651 |
"DEF ", |
| 652 |
"GHI ", |
| 653 |
}, |
| 654 |
pos: uv.Pos(1, 1), |
| 655 |
}, |
| 656 |
{ |
| 657 |
name: "DL With Top/Bottom Scroll Regions", |
| 658 |
w: 8, h: 4, |
| 659 |
input: []string{ |
| 660 |
"\x1b[1;1H", // move to top-left |
| 661 |
"\x1b[2J", // clear screen |
| 662 |
"ABC\r\n", |
| 663 |
"DEF\r\n", |
| 664 |
"GHI\r\n", |
| 665 |
"123", |
| 666 |
"\x1b[1;3r", // scroll region top/bottom |
| 667 |
"\x1b[2;2H", |
| 668 |
"\x1b[M", |
| 669 |
}, |
| 670 |
want: []string{ |
| 671 |
"ABC ", |
| 672 |
"GHI ", |
| 673 |
" ", |
| 674 |
"123 ", |
| 675 |
}, |
| 676 |
pos: uv.Pos(0, 1), |
| 677 |
}, |
| 678 |
{ |
| 679 |
name: "DL With Left/Right Scroll Regions", |
| 680 |
w: 8, h: 3, |
| 681 |
input: []string{ |
| 682 |
"\x1b[1;1H", // move to top-left |
| 683 |
"\x1b[2J", // clear screen |
| 684 |
"ABC123\r\n", |
| 685 |
"DEF456\r\n", |
| 686 |
"GHI789", |
| 687 |
"\x1b[?69h", // enable left/right margins |
| 688 |
"\x1b[2;4s", // scroll region left/right |
| 689 |
"\x1b[2;2H", |
| 690 |
"\x1b[M", |
| 691 |
}, |
| 692 |
want: []string{ |
| 693 |
"ABC123 ", |
| 694 |
"DHI756 ", |
| 695 |
"G 89 ", |
| 696 |
}, |
| 697 |
pos: uv.Pos(1, 1), |
| 698 |
}, |
| 699 |
|
| 700 |
// Insert Line [ansi.IL] |
| 701 |
{ |
| 702 |
name: "IL Simple Insert Line", |
| 703 |
w: 8, h: 4, |
| 704 |
input: []string{ |
| 705 |
"\x1b[1;1H", // move to top-left |
| 706 |
"\x1b[2J", // clear screen |
| 707 |
"ABC\r\n", |
| 708 |
"DEF\r\n", |
| 709 |
"GHI", |
| 710 |
"\x1b[2;2H", |
| 711 |
"\x1b[L", |
| 712 |
}, |
| 713 |
want: []string{ |
| 714 |
"ABC ", |
| 715 |
" ", |
| 716 |
"DEF ", |
| 717 |
"GHI ", |
| 718 |
}, |
| 719 |
pos: uv.Pos(0, 1), |
| 720 |
}, |
| 721 |
{ |
| 722 |
name: "IL Cursor Outside Scroll Region", |
| 723 |
w: 8, h: 3, |
| 724 |
input: []string{ |
| 725 |
"\x1b[1;1H", // move to top-left |
| 726 |
"\x1b[2J", // clear screen |
| 727 |
"ABC\r\n", |
| 728 |
"DEF\r\n", |
| 729 |
"GHI", |
| 730 |
"\x1b[3;4r", // scroll region top/bottom |
| 731 |
"\x1b[2;2H", |
| 732 |
"\x1b[L", |
| 733 |
}, |
| 734 |
want: []string{ |
| 735 |
"ABC ", |
| 736 |
"DEF ", |
| 737 |
"GHI ", |
| 738 |
}, |
| 739 |
pos: uv.Pos(1, 1), |
| 740 |
}, |
| 741 |
{ |
| 742 |
name: "IL With Top/Bottom Scroll Regions", |
| 743 |
w: 8, h: 4, |
| 744 |
input: []string{ |
| 745 |
"\x1b[1;1H", // move to top-left |
| 746 |
"\x1b[2J", // clear screen |
| 747 |
"ABC\r\n", |
| 748 |
"DEF\r\n", |
| 749 |
"GHI\r\n", |
| 750 |
"123", |
| 751 |
"\x1b[1;3r", // scroll region top/bottom |
| 752 |
"\x1b[2;2H", |
| 753 |
"\x1b[L", |
| 754 |
}, |
| 755 |
want: []string{ |
| 756 |
"ABC ", |
| 757 |
" ", |
| 758 |
"DEF ", |
| 759 |
"123 ", |
| 760 |
}, |
| 761 |
pos: uv.Pos(0, 1), |
| 762 |
}, |
| 763 |
{ |
| 764 |
name: "IL With Left/Right Scroll Regions", |
| 765 |
w: 8, h: 4, |
| 766 |
input: []string{ |
| 767 |
"\x1b[1;1H", // move to top-left |
| 768 |
"\x1b[2J", // clear screen |
| 769 |
"ABC123\r\n", |
| 770 |
"DEF456\r\n", |
| 771 |
"GHI789", |
| 772 |
"\x1b[?69h", // enable left/right margins |
| 773 |
"\x1b[2;4s", // scroll region left/right |
| 774 |
"\x1b[2;2H", |
| 775 |
"\x1b[L", |
| 776 |
}, |
| 777 |
want: []string{ |
| 778 |
"ABC123 ", |
| 779 |
"D 56 ", |
| 780 |
"GEF489 ", |
| 781 |
" HI7 ", |
| 782 |
}, |
| 783 |
pos: uv.Pos(1, 1), |
| 784 |
}, |
| 785 |
|
| 786 |
// Delete Character [ansi.DCH] |
| 787 |
{ |
| 788 |
name: "DCH Simple Delete Character", |
| 789 |
w: 8, h: 1, |
| 790 |
input: []string{ |
| 791 |
"ABC123", |
| 792 |
"\x1b[3G", |
| 793 |
"\x1b[2P", |
| 794 |
}, |
| 795 |
want: []string{"AB23 "}, |
| 796 |
pos: uv.Pos(2, 0), |
| 797 |
}, |
| 798 |
{ |
| 799 |
name: "DCH with SGR State", |
| 800 |
w: 8, h: 1, |
| 801 |
input: []string{ |
| 802 |
"ABC123", |
| 803 |
"\x1b[3G", |
| 804 |
"\x1b[41m", |
| 805 |
"\x1b[2P", |
| 806 |
}, |
| 807 |
want: []string{"AB23 "}, |
| 808 |
pos: uv.Pos(2, 0), |
| 809 |
}, |
| 810 |
{ |
| 811 |
name: "DCH Outside Left/Right Scroll Region", |
| 812 |
w: 8, h: 1, |
| 813 |
input: []string{ |
| 814 |
"\x1b[1;1H", // move to top-left |
| 815 |
"\x1b[2J", // clear screen |
| 816 |
"ABC123", |
| 817 |
"\x1b[?69h", // enable left/right margins |
| 818 |
"\x1b[3;5s", // scroll region left/right |
| 819 |
"\x1b[2G", |
| 820 |
"\x1b[P", |
| 821 |
}, |
| 822 |
want: []string{"ABC123 "}, |
| 823 |
pos: uv.Pos(1, 0), |
| 824 |
}, |
| 825 |
{ |
| 826 |
name: "DCH Inside Left/Right Scroll Region", |
| 827 |
w: 8, h: 1, |
| 828 |
input: []string{ |
| 829 |
"\x1b[1;1H", // move to top-left |
| 830 |
"\x1b[2J", // clear screen |
| 831 |
"ABC123", |
| 832 |
"\x1b[?69h", // enable left/right margins |
| 833 |
"\x1b[3;5s", // scroll region left/right |
| 834 |
"\x1b[4G", |
| 835 |
"\x1b[P", |
| 836 |
}, |
| 837 |
want: []string{"ABC2 3 "}, |
| 838 |
pos: uv.Pos(3, 0), |
| 839 |
}, |
| 840 |
{ |
| 841 |
name: "DCH Split Wide Character", |
| 842 |
w: 10, h: 1, |
| 843 |
input: []string{ |
| 844 |
"\x1b[1;1H", // move to top-left |
| 845 |
"\x1b[2J", // clear screen |
| 846 |
"A橋123", |
| 847 |
"\x1b[3G", |
| 848 |
"\x1b[P", |
| 849 |
}, |
| 850 |
want: []string{"A 123 "}, |
| 851 |
pos: uv.Pos(2, 0), |
| 852 |
}, |
| 853 |
|
| 854 |
// Set Top and Bottom Margins [ansi.DECSTBM] |
| 855 |
{ |
| 856 |
name: "DECSTBM Full Screen Scroll Up", |
| 857 |
w: 8, h: 4, |
| 858 |
input: []string{ |
| 859 |
"\x1b[1;1H", // move to top-left |
| 860 |
"\x1b[2J", // clear screen |
| 861 |
"ABC\r\n", |
| 862 |
"DEF\r\n", |
| 863 |
"GHI", |
| 864 |
"\x1b[r", // set full screen scroll region |
| 865 |
"\x1b[T", // scroll up |
| 866 |
}, |
| 867 |
want: []string{ |
| 868 |
" ", |
| 869 |
"ABC ", |
| 870 |
"DEF ", |
| 871 |
"GHI ", |
| 872 |
}, |
| 873 |
pos: uv.Pos(0, 0), |
| 874 |
}, |
| 875 |
{ |
| 876 |
name: "DECSTBM Top Only Scroll Up", |
| 877 |
w: 8, h: 4, |
| 878 |
input: []string{ |
| 879 |
"\x1b[1;1H", // move to top-left |
| 880 |
"\x1b[2J", // clear screen |
| 881 |
"ABC\r\n", |
| 882 |
"DEF\r\n", |
| 883 |
"GHI", |
| 884 |
"\x1b[2r", // set scroll region from line 2 |
| 885 |
"\x1b[T", // scroll up |
| 886 |
}, |
| 887 |
want: []string{ |
| 888 |
"ABC ", |
| 889 |
" ", |
| 890 |
"DEF ", |
| 891 |
"GHI ", |
| 892 |
}, |
| 893 |
pos: uv.Pos(0, 0), |
| 894 |
}, |
| 895 |
{ |
| 896 |
name: "DECSTBM Top and Bottom Scroll Up", |
| 897 |
w: 8, h: 4, |
| 898 |
input: []string{ |
| 899 |
"\x1b[1;1H", // move to top-left |
| 900 |
"\x1b[2J", // clear screen |
| 901 |
"ABC\r\n", |
| 902 |
"DEF\r\n", |
| 903 |
"GHI", |
| 904 |
"\x1b[1;2r", // set scroll region from line 1 to 2 |
| 905 |
"\x1b[T", // scroll up |
| 906 |
}, |
| 907 |
want: []string{ |
| 908 |
" ", |
| 909 |
"ABC ", |
| 910 |
"GHI ", |
| 911 |
" ", |
| 912 |
}, |
| 913 |
pos: uv.Pos(0, 0), |
| 914 |
}, |
| 915 |
{ |
| 916 |
name: "DECSTBM Top Equal Bottom Scroll Up", |
| 917 |
w: 8, h: 4, |
| 918 |
input: []string{ |
| 919 |
"\x1b[1;1H", // move to top-left |
| 920 |
"\x1b[2J", // clear screen |
| 921 |
"ABC\r\n", |
| 922 |
"DEF\r\n", |
| 923 |
"GHI", |
| 924 |
"\x1b[2;2r", // set scroll region at line 2 only |
| 925 |
"\x1b[T", // scroll up |
| 926 |
}, |
| 927 |
want: []string{ |
| 928 |
" ", |
| 929 |
"ABC ", |
| 930 |
"DEF ", |
| 931 |
"GHI ", |
| 932 |
}, |
| 933 |
pos: uv.Pos(3, 2), |
| 934 |
}, |
| 935 |
|
| 936 |
// Set Left/Right Margins [ansi.DECSLRM] |
| 937 |
{ |
| 938 |
name: "DECSLRM Full Screen", |
| 939 |
w: 8, h: 3, |
| 940 |
input: []string{ |
| 941 |
"\x1b[1;1H", // move to top-left |
| 942 |
"\x1b[2J", // clear screen |
| 943 |
"ABC\r\n", |
| 944 |
"DEF\r\n", |
| 945 |
"GHI", |
| 946 |
"\x1b[?69h", // enable left/right margins |
| 947 |
"\x1b[s", // scroll region left/right |
| 948 |
"\x1b[X", |
| 949 |
}, |
| 950 |
want: []string{ |
| 951 |
" BC ", |
| 952 |
"DEF ", |
| 953 |
"GHI ", |
| 954 |
}, |
| 955 |
pos: uv.Pos(0, 0), |
| 956 |
}, |
| 957 |
{ |
| 958 |
name: "DECSLRM Left Only", |
| 959 |
w: 8, h: 4, |
| 960 |
input: []string{ |
| 961 |
"\x1b[1;1H", // move to top-left |
| 962 |
"\x1b[2J", // clear screen |
| 963 |
"ABC\r\n", |
| 964 |
"DEF\r\n", |
| 965 |
"GHI", |
| 966 |
"\x1b[?69h", // enable left/right margins |
| 967 |
"\x1b[2s", // scroll region left/right |
| 968 |
"\x1b[2G", // move cursor to column 2 |
| 969 |
"\x1b[L", |
| 970 |
}, |
| 971 |
want: []string{ |
| 972 |
"A ", |
| 973 |
"DBC ", |
| 974 |
"GEF ", |
| 975 |
" HI ", |
| 976 |
}, |
| 977 |
pos: uv.Pos(1, 0), |
| 978 |
}, |
| 979 |
{ |
| 980 |
name: "DECSLRM Left And Right", |
| 981 |
w: 8, h: 4, |
| 982 |
input: []string{ |
| 983 |
"\x1b[1;1H", // move to top-left |
| 984 |
"\x1b[2J", // clear screen |
| 985 |
"ABC\r\n", |
| 986 |
"DEF\r\n", |
| 987 |
"GHI", |
| 988 |
"\x1b[?69h", // enable left/right margins |
| 989 |
"\x1b[1;2s", // scroll region left/right |
| 990 |
"\x1b[2G", // move cursor to column 2 |
| 991 |
"\x1b[L", |
| 992 |
}, |
| 993 |
want: []string{ |
| 994 |
" C ", |
| 995 |
"ABF ", |
| 996 |
"DEI ", |
| 997 |
"GH ", |
| 998 |
}, |
| 999 |
pos: uv.Pos(0, 0), |
| 1000 |
}, |
| 1001 |
{ |
| 1002 |
name: "DECSLRM Left Equal to Right", |
| 1003 |
w: 8, h: 3, |
| 1004 |
input: []string{ |
| 1005 |
"\x1b[1;1H", // move to top-left |
| 1006 |
"\x1b[2J", // clear screen |
| 1007 |
"ABC\r\n", |
| 1008 |
"DEF\r\n", |
| 1009 |
"GHI", |
| 1010 |
"\x1b[?69h", // enable left/right margins |
| 1011 |
"\x1b[2;2s", // scroll region left/right |
| 1012 |
"\x1b[X", |
| 1013 |
}, |
| 1014 |
want: []string{ |
| 1015 |
"ABC ", |
| 1016 |
"DEF ", |
| 1017 |
"GHI ", |
| 1018 |
}, |
| 1019 |
pos: uv.Pos(3, 2), |
| 1020 |
}, |
| 1021 |
|
| 1022 |
// Erase Character [ansi.ECH] |
| 1023 |
{ |
| 1024 |
name: "ECH Simple Operation", |
| 1025 |
w: 8, h: 1, |
| 1026 |
input: []string{ |
| 1027 |
"ABC", |
| 1028 |
"\x1b[1G", |
| 1029 |
"\x1b[2X", |
| 1030 |
}, |
| 1031 |
want: []string{" C "}, |
| 1032 |
pos: uv.Pos(0, 0), |
| 1033 |
}, |
| 1034 |
{ |
| 1035 |
name: "ECH Erasing Beyond Edge of Screen", |
| 1036 |
w: 8, h: 1, |
| 1037 |
input: []string{ |
| 1038 |
"\x1b[8G", |
| 1039 |
"\x1b[2D", |
| 1040 |
"ABC", |
| 1041 |
"\x1b[D", |
| 1042 |
"\x1b[10X", |
| 1043 |
}, |
| 1044 |
want: []string{" A "}, |
| 1045 |
pos: uv.Pos(6, 0), |
| 1046 |
}, |
| 1047 |
{ |
| 1048 |
name: "ECH Reset Pending Wrap State", |
| 1049 |
w: 8, h: 1, |
| 1050 |
input: []string{ |
| 1051 |
"\x1b[8G", // move to last column |
| 1052 |
"A", // set pending wrap state |
| 1053 |
"\x1b[X", // erase one char |
| 1054 |
"X", // write X |
| 1055 |
}, |
| 1056 |
want: []string{" X"}, |
| 1057 |
pos: uv.Pos(7, 0), |
| 1058 |
}, |
| 1059 |
{ |
| 1060 |
name: "ECH with SGR State", |
| 1061 |
w: 8, h: 1, |
| 1062 |
input: []string{ |
| 1063 |
"ABC", |
| 1064 |
"\x1b[1G", |
| 1065 |
"\x1b[41m", // set red background |
| 1066 |
"\x1b[2X", |
| 1067 |
}, |
| 1068 |
want: []string{" C "}, |
| 1069 |
pos: uv.Pos(0, 0), |
| 1070 |
}, |
| 1071 |
{ |
| 1072 |
name: "ECH Multi-cell Character", |
| 1073 |
w: 8, h: 1, |
| 1074 |
input: []string{ |
| 1075 |
"橋BC", |
| 1076 |
"\x1b[1G", |
| 1077 |
"\x1b[X", |
| 1078 |
"X", |
| 1079 |
}, |
| 1080 |
want: []string{"X BC "}, |
| 1081 |
pos: uv.Pos(1, 0), |
| 1082 |
}, |
| 1083 |
{ |
| 1084 |
name: "ECH Left/Right Scroll Region Ignored", |
| 1085 |
w: 10, h: 1, |
| 1086 |
input: []string{ |
| 1087 |
"\x1b[1;1H", // move to top-left |
| 1088 |
"\x1b[2J", // clear screen |
| 1089 |
"\x1b[?69h", // enable left/right margins |
| 1090 |
"\x1b[1;3s", // scroll region left/right |
| 1091 |
"\x1b[4G", |
| 1092 |
"ABC", |
| 1093 |
"\x1b[1G", |
| 1094 |
"\x1b[4X", |
| 1095 |
}, |
| 1096 |
want: []string{" BC "}, |
| 1097 |
pos: uv.Pos(0, 0), |
| 1098 |
}, |
| 1099 |
// XXX: Support DECSCA |
| 1100 |
// { |
| 1101 |
// name: "ECH Protected Attributes Ignored with DECSCA", |
| 1102 |
// w: 8, h: 1, |
| 1103 |
// input: []string{ |
| 1104 |
// "\x1bV", |
| 1105 |
// "ABC", |
| 1106 |
// "\x1b[1\"q", |
| 1107 |
// "\x1b[0\"q", |
| 1108 |
// "\x1b[1G", |
| 1109 |
// "\x1b[2X", |
| 1110 |
// }, |
| 1111 |
// want: []string{" C "}, |
| 1112 |
// pos: uv.Pos(0, 0), |
| 1113 |
// }, |
| 1114 |
// { |
| 1115 |
// name: "ECH Protected Attributes Respected without DECSCA", |
| 1116 |
// w: 8, h: 1, |
| 1117 |
// input: []string{ |
| 1118 |
// "\x1b[1\"q", |
| 1119 |
// "ABC", |
| 1120 |
// "\x1bV", |
| 1121 |
// "\x1b[1G", |
| 1122 |
// "\x1b[2X", |
| 1123 |
// }, |
| 1124 |
// want: []string{"ABC "}, |
| 1125 |
// pos: uv.Pos(0, 0), |
| 1126 |
// }, |
| 1127 |
|
| 1128 |
// Erase Line [ansi.EL] |
| 1129 |
{ |
| 1130 |
name: "EL Simple Erase Right", |
| 1131 |
w: 8, h: 1, |
| 1132 |
input: []string{ |
| 1133 |
"ABCDE", |
| 1134 |
"\x1b[3G", |
| 1135 |
"\x1b[0K", |
| 1136 |
}, |
| 1137 |
want: []string{"AB "}, |
| 1138 |
pos: uv.Pos(2, 0), |
| 1139 |
}, |
| 1140 |
{ |
| 1141 |
name: "EL Erase Right Resets Pending Wrap", |
| 1142 |
w: 8, h: 1, |
| 1143 |
input: []string{ |
| 1144 |
"\x1b[8G", // move to last column |
| 1145 |
"A", // set pending wrap state |
| 1146 |
"\x1b[0K", // erase right |
| 1147 |
"X", |
| 1148 |
}, |
| 1149 |
want: []string{" X"}, |
| 1150 |
pos: uv.Pos(7, 0), |
| 1151 |
}, |
| 1152 |
{ |
| 1153 |
name: "EL Erase Right with SGR State", |
| 1154 |
w: 8, h: 1, |
| 1155 |
input: []string{ |
| 1156 |
"ABC", |
| 1157 |
"\x1b[2G", |
| 1158 |
"\x1b[41m", // set red background |
| 1159 |
"\x1b[0K", |
| 1160 |
}, |
| 1161 |
want: []string{"A "}, |
| 1162 |
pos: uv.Pos(1, 0), |
| 1163 |
}, |
| 1164 |
{ |
| 1165 |
name: "EL Erase Right Multi-cell Character", |
| 1166 |
w: 8, h: 1, |
| 1167 |
input: []string{ |
| 1168 |
"AB橋DE", |
| 1169 |
"\x1b[4G", |
| 1170 |
"\x1b[0K", |
| 1171 |
}, |
| 1172 |
want: []string{"AB "}, |
| 1173 |
pos: uv.Pos(3, 0), |
| 1174 |
}, |
| 1175 |
{ |
| 1176 |
name: "EL Erase Right with Left/Right Margins", |
| 1177 |
w: 10, h: 1, |
| 1178 |
input: []string{ |
| 1179 |
"\x1b[1;1H", // move to top-left |
| 1180 |
"\x1b[2J", // clear screen |
| 1181 |
"ABCDE", |
| 1182 |
"\x1b[?69h", // enable left/right margins |
| 1183 |
"\x1b[1;3s", // scroll region left/right |
| 1184 |
"\x1b[2G", |
| 1185 |
"\x1b[0K", |
| 1186 |
}, |
| 1187 |
want: []string{"A "}, |
| 1188 |
pos: uv.Pos(1, 0), |
| 1189 |
}, |
| 1190 |
{ |
| 1191 |
name: "EL Simple Erase Left", |
| 1192 |
w: 8, h: 1, |
| 1193 |
input: []string{ |
| 1194 |
"ABCDE", |
| 1195 |
"\x1b[3G", |
| 1196 |
"\x1b[1K", |
| 1197 |
}, |
| 1198 |
want: []string{" DE "}, |
| 1199 |
pos: uv.Pos(2, 0), |
| 1200 |
}, |
| 1201 |
{ |
| 1202 |
name: "EL Erase Left with SGR State", |
| 1203 |
w: 8, h: 1, |
| 1204 |
input: []string{ |
| 1205 |
"ABC", |
| 1206 |
"\x1b[2G", |
| 1207 |
"\x1b[41m", // set red background |
| 1208 |
"\x1b[1K", |
| 1209 |
}, |
| 1210 |
want: []string{" C "}, |
| 1211 |
pos: uv.Pos(1, 0), |
| 1212 |
}, |
| 1213 |
{ |
| 1214 |
name: "EL Erase Left Multi-cell Character", |
| 1215 |
w: 8, h: 1, |
| 1216 |
input: []string{ |
| 1217 |
"AB橋DE", |
| 1218 |
"\x1b[3G", |
| 1219 |
"\x1b[1K", |
| 1220 |
}, |
| 1221 |
want: []string{" DE "}, |
| 1222 |
pos: uv.Pos(2, 0), |
| 1223 |
}, |
| 1224 |
// XXX: Support DECSCA |
| 1225 |
// { |
| 1226 |
// name: "EL Erase Left Protected Attributes Ignored with DECSCA", |
| 1227 |
// w: 8, h: 1, |
| 1228 |
// input: []string{ |
| 1229 |
// "\x1bV", |
| 1230 |
// "ABCDE", |
| 1231 |
// "\x1b[1\"q", |
| 1232 |
// "\x1b[0\"q", |
| 1233 |
// "\x1b[2G", |
| 1234 |
// "\x1b[1K", |
| 1235 |
// }, |
| 1236 |
// want: []string{" CDE "}, |
| 1237 |
// pos: uv.Pos(1, 0), |
| 1238 |
// }, |
| 1239 |
{ |
| 1240 |
name: "EL Simple Erase Complete Line", |
| 1241 |
w: 8, h: 1, |
| 1242 |
input: []string{ |
| 1243 |
"ABCDE", |
| 1244 |
"\x1b[3G", |
| 1245 |
"\x1b[2K", |
| 1246 |
}, |
| 1247 |
want: []string{" "}, |
| 1248 |
pos: uv.Pos(2, 0), |
| 1249 |
}, |
| 1250 |
{ |
| 1251 |
name: "EL Erase Complete with SGR State", |
| 1252 |
w: 8, h: 1, |
| 1253 |
input: []string{ |
| 1254 |
"ABC", |
| 1255 |
"\x1b[2G", |
| 1256 |
"\x1b[41m", // set red background |
| 1257 |
"\x1b[2K", |
| 1258 |
}, |
| 1259 |
want: []string{" "}, |
| 1260 |
pos: uv.Pos(1, 0), |
| 1261 |
}, |
| 1262 |
|
| 1263 |
// Index [ansi.IND] |
| 1264 |
{ |
| 1265 |
name: "IND No Scroll Region Top of Screen", |
| 1266 |
w: 10, h: 2, |
| 1267 |
input: []string{ |
| 1268 |
"\x1b[1;1H", // move to top-left |
| 1269 |
"\x1b[2J", // clear screen |
| 1270 |
"A", |
| 1271 |
"\x1bD", // index |
| 1272 |
"X", |
| 1273 |
}, |
| 1274 |
want: []string{ |
| 1275 |
"A ", |
| 1276 |
" X ", |
| 1277 |
}, |
| 1278 |
pos: uv.Pos(2, 1), |
| 1279 |
}, |
| 1280 |
{ |
| 1281 |
name: "IND Bottom of Primary Screen", |
| 1282 |
w: 10, h: 2, |
| 1283 |
input: []string{ |
| 1284 |
"\x1b[1;1H", // move to top-left |
| 1285 |
"\x1b[2J", // clear screen |
| 1286 |
"\x1b[2;1H", // move to bottom-left |
| 1287 |
"A", |
| 1288 |
"\x1bD", // index |
| 1289 |
"X", |
| 1290 |
}, |
| 1291 |
want: []string{ |
| 1292 |
"A ", |
| 1293 |
" X ", |
| 1294 |
}, |
| 1295 |
pos: uv.Pos(2, 1), |
| 1296 |
}, |
| 1297 |
{ |
| 1298 |
name: "IND Inside Scroll Region", |
| 1299 |
w: 10, h: 2, |
| 1300 |
input: []string{ |
| 1301 |
"\x1b[1;1H", // move to top-left |
| 1302 |
"\x1b[2J", // clear screen |
| 1303 |
"\x1b[1;3r", // scroll region |
| 1304 |
"A", |
| 1305 |
"\x1bD", // index |
| 1306 |
"X", |
| 1307 |
}, |
| 1308 |
want: []string{ |
| 1309 |
"A ", |
| 1310 |
" X ", |
| 1311 |
}, |
| 1312 |
pos: uv.Pos(2, 1), |
| 1313 |
}, |
| 1314 |
{ |
| 1315 |
name: "IND Bottom of Scroll Region", |
| 1316 |
w: 10, h: 4, |
| 1317 |
input: []string{ |
| 1318 |
"\x1b[1;1H", // move to top-left |
| 1319 |
"\x1b[2J", // clear screen |
| 1320 |
"\x1b[1;3r", // scroll region |
| 1321 |
"\x1b[4;1H", // below scroll region |
| 1322 |
"B", |
| 1323 |
"\x1b[3;1H", // move to last row of region |
| 1324 |
"A", |
| 1325 |
"\x1bD", // index |
| 1326 |
"X", |
| 1327 |
}, |
| 1328 |
want: []string{ |
| 1329 |
" ", |
| 1330 |
"A ", |
| 1331 |
" X ", |
| 1332 |
"B ", |
| 1333 |
}, |
| 1334 |
pos: uv.Pos(2, 2), |
| 1335 |
}, |
| 1336 |
{ |
| 1337 |
name: "IND Bottom of Primary Screen with Scroll Region", |
| 1338 |
w: 10, h: 5, |
| 1339 |
input: []string{ |
| 1340 |
"\x1b[1;1H", // move to top-left |
| 1341 |
"\x1b[2J", // clear screen |
| 1342 |
"\x1b[1;3r", // scroll region |
| 1343 |
"\x1b[3;1H", // move to last row of region |
| 1344 |
"A", |
| 1345 |
"\x1b[5;1H", // move to bottom-left |
| 1346 |
"\x1bD", // index |
| 1347 |
"X", |
| 1348 |
}, |
| 1349 |
want: []string{ |
| 1350 |
" ", |
| 1351 |
" ", |
| 1352 |
"A ", |
| 1353 |
" ", |
| 1354 |
"X ", |
| 1355 |
}, |
| 1356 |
pos: uv.Pos(1, 4), |
| 1357 |
}, |
| 1358 |
{ |
| 1359 |
name: "IND Outside of Left/Right Scroll Region", |
| 1360 |
w: 10, h: 3, |
| 1361 |
input: []string{ |
| 1362 |
"\x1b[1;1H", // move to top-left |
| 1363 |
"\x1b[2J", // clear screen |
| 1364 |
"\x1b[?69h", // enable left/right margins |
| 1365 |
"\x1b[1;3r", // scroll region top/bottom |
| 1366 |
"\x1b[3;5s", // scroll region left/right |
| 1367 |
"\x1b[3;3H", |
| 1368 |
"A", |
| 1369 |
"\x1b[3;1H", |
| 1370 |
"\x1bD", // index |
| 1371 |
"X", |
| 1372 |
}, |
| 1373 |
want: []string{ |
| 1374 |
" ", |
| 1375 |
" ", |
| 1376 |
"X A ", |
| 1377 |
}, |
| 1378 |
pos: uv.Pos(1, 2), |
| 1379 |
}, |
| 1380 |
{ |
| 1381 |
name: "IND Inside of Left/Right Scroll Region", |
| 1382 |
w: 10, h: 3, |
| 1383 |
input: []string{ |
| 1384 |
"\x1b[1;1H", // move to top-left |
| 1385 |
"\x1b[2J", // clear screen |
| 1386 |
"AAAAAA\r\n", |
| 1387 |
"AAAAAA\r\n", |
| 1388 |
"AAAAAA", |
| 1389 |
"\x1b[?69h", // enable left/right margins |
| 1390 |
"\x1b[1;3s", // set scroll region left/right |
| 1391 |
"\x1b[1;3r", // set scroll region top/bottom |
| 1392 |
"\x1b[3;1H", // Move to bottom left |
| 1393 |
"\x1bD", // index |
| 1394 |
}, |
| 1395 |
want: []string{ |
| 1396 |
"AAAAAA ", |
| 1397 |
"AAAAAA ", |
| 1398 |
" AAA ", |
| 1399 |
}, |
| 1400 |
pos: uv.Pos(0, 2), |
| 1401 |
}, |
| 1402 |
|
| 1403 |
// Erase Display [ansi.ED] |
| 1404 |
{ |
| 1405 |
name: "ED Simple Erase Below", |
| 1406 |
w: 8, h: 3, |
| 1407 |
input: []string{ |
| 1408 |
"\x1b[1;1H", // move to top-left |
| 1409 |
"\x1b[2J", // clear screen |
| 1410 |
"ABC\r\n", |
| 1411 |
"DEF\r\n", |
| 1412 |
"GHI", |
| 1413 |
"\x1b[2;2H", |
| 1414 |
"\x1b[0J", |
| 1415 |
}, |
| 1416 |
want: []string{ |
| 1417 |
"ABC ", |
| 1418 |
"D ", |
| 1419 |
" ", |
| 1420 |
}, |
| 1421 |
pos: uv.Pos(1, 1), |
| 1422 |
}, |
| 1423 |
{ |
| 1424 |
name: "ED Erase Below with SGR State", |
| 1425 |
w: 8, h: 3, |
| 1426 |
input: []string{ |
| 1427 |
"\x1b[1;1H", // move to top-left |
| 1428 |
"\x1b[0J", // clear screen |
| 1429 |
"ABC\r\n", |
| 1430 |
"DEF\r\n", |
| 1431 |
"GHI", |
| 1432 |
"\x1b[2;2H", |
| 1433 |
"\x1b[41m", // set red background |
| 1434 |
"\x1b[0J", |
| 1435 |
}, |
| 1436 |
want: []string{ |
| 1437 |
"ABC ", |
| 1438 |
"D ", |
| 1439 |
" ", |
| 1440 |
}, |
| 1441 |
pos: uv.Pos(1, 1), |
| 1442 |
}, |
| 1443 |
{ |
| 1444 |
name: "ED Erase Below with Multi-Cell Character", |
| 1445 |
w: 8, h: 3, |
| 1446 |
input: []string{ |
| 1447 |
"\x1b[1;1H", // move to top-left |
| 1448 |
"\x1b[2J", // clear screen |
| 1449 |
"AB橋C\r\n", |
| 1450 |
"DE橋F\r\n", |
| 1451 |
"GH橋I", |
| 1452 |
"\x1b[2;3H", // move to 2nd row 3rd column |
| 1453 |
"\x1b[0J", |
| 1454 |
}, |
| 1455 |
want: []string{ |
| 1456 |
"AB橋C ", |
| 1457 |
"DE ", |
| 1458 |
" ", |
| 1459 |
}, |
| 1460 |
pos: uv.Pos(2, 1), |
| 1461 |
}, |
| 1462 |
{ |
| 1463 |
name: "ED Simple Erase Above", |
| 1464 |
w: 8, h: 3, |
| 1465 |
input: []string{ |
| 1466 |
"\x1b[1;1H", // move to top-left |
| 1467 |
"\x1b[2J", // clear screen |
| 1468 |
"ABC\r\n", |
| 1469 |
"DEF\r\n", |
| 1470 |
"GHI", |
| 1471 |
"\x1b[2;2H", |
| 1472 |
"\x1b[1J", |
| 1473 |
}, |
| 1474 |
want: []string{ |
| 1475 |
" ", |
| 1476 |
" ", |
| 1477 |
"GHI ", |
| 1478 |
}, |
| 1479 |
pos: uv.Pos(1, 1), |
| 1480 |
}, |
| 1481 |
{ |
| 1482 |
name: "ED Simple Erase Complete", |
| 1483 |
w: 8, h: 3, |
| 1484 |
input: []string{ |
| 1485 |
"\x1b[1;1H", // move to top-left |
| 1486 |
"\x1b[2J", // clear screen |
| 1487 |
"ABC\r\n", |
| 1488 |
"DEF\r\n", |
| 1489 |
"GHI", |
| 1490 |
"\x1b[2;2H", |
| 1491 |
"\x1b[2J", |
| 1492 |
}, |
| 1493 |
want: []string{ |
| 1494 |
" ", |
| 1495 |
" ", |
| 1496 |
" ", |
| 1497 |
}, |
| 1498 |
pos: uv.Pos(1, 1), |
| 1499 |
}, |
| 1500 |
|
| 1501 |
// Reverse Index [ansi.RI] |
| 1502 |
{ |
| 1503 |
name: "RI No Scroll Region Top of Screen", |
| 1504 |
w: 10, h: 4, |
| 1505 |
input: []string{ |
| 1506 |
"\x1b[1;1H", // move to top-left |
| 1507 |
"\x1b[2J", // clear screen |
| 1508 |
"A\r\n", |
| 1509 |
"B\r\n", |
| 1510 |
"C\r\n", |
| 1511 |
"\x1b[1;1H", // move to top-left |
| 1512 |
"\x1bM", // reverse index |
| 1513 |
"X", |
| 1514 |
}, |
| 1515 |
want: []string{ |
| 1516 |
"X ", |
| 1517 |
"A ", |
| 1518 |
"B ", |
| 1519 |
"C ", |
| 1520 |
}, |
| 1521 |
pos: uv.Pos(1, 0), |
| 1522 |
}, |
| 1523 |
{ |
| 1524 |
name: "RI No Scroll Region Not Top of Screen", |
| 1525 |
w: 10, h: 3, |
| 1526 |
input: []string{ |
| 1527 |
"\x1b[1;1H", // move to top-left |
| 1528 |
"\x1b[2J", // clear screen |
| 1529 |
"A\r\n", |
| 1530 |
"B\r\n", |
| 1531 |
"C", |
| 1532 |
"\x1b[2;1H", |
| 1533 |
"\x1bM", // reverse index |
| 1534 |
"X", |
| 1535 |
}, |
| 1536 |
want: []string{ |
| 1537 |
"X ", |
| 1538 |
"B ", |
| 1539 |
"C ", |
| 1540 |
}, |
| 1541 |
pos: uv.Pos(1, 0), |
| 1542 |
}, |
| 1543 |
{ |
| 1544 |
name: "RI Top/Bottom Scroll Region", |
| 1545 |
w: 10, h: 3, |
| 1546 |
input: []string{ |
| 1547 |
"\x1b[1;1H", // move to top-left |
| 1548 |
"\x1b[2J", // clear screen |
| 1549 |
"A\r\n", |
| 1550 |
"B\r\n", |
| 1551 |
"C", |
| 1552 |
"\x1b[2;3r", // scroll region |
| 1553 |
"\x1b[2;1H", |
| 1554 |
"\x1bM", // reverse index |
| 1555 |
"X", |
| 1556 |
}, |
| 1557 |
want: []string{ |
| 1558 |
"A ", |
| 1559 |
"X ", |
| 1560 |
"B ", |
| 1561 |
}, |
| 1562 |
pos: uv.Pos(1, 1), |
| 1563 |
}, |
| 1564 |
{ |
| 1565 |
name: "RI Outside of Top/Bottom Scroll Region", |
| 1566 |
w: 10, h: 3, |
| 1567 |
input: []string{ |
| 1568 |
"\x1b[1;1H", // move to top-left |
| 1569 |
"\x1b[2J", // clear screen |
| 1570 |
"A\r\n", |
| 1571 |
"B\r\n", |
| 1572 |
"C", |
| 1573 |
"\x1b[2;3r", // scroll region |
| 1574 |
"\x1b[1;1H", |
| 1575 |
"\x1bM", // reverse index |
| 1576 |
}, |
| 1577 |
want: []string{ |
| 1578 |
"A ", |
| 1579 |
"B ", |
| 1580 |
"C ", |
| 1581 |
}, |
| 1582 |
pos: uv.Pos(0, 0), |
| 1583 |
}, |
| 1584 |
{ |
| 1585 |
name: "RI Left/Right Scroll Region", |
| 1586 |
w: 10, h: 4, |
| 1587 |
input: []string{ |
| 1588 |
"\x1b[1;1H", // move to top-left |
| 1589 |
"\x1b[2J", // clear screen |
| 1590 |
"ABC\r\n", |
| 1591 |
"DEF\r\n", |
| 1592 |
"GHI", |
| 1593 |
"\x1b[?69h", // enable left/right margins |
| 1594 |
"\x1b[2;3s", // scroll region left/right |
| 1595 |
"\x1b[1;2H", |
| 1596 |
"\x1bM", |
| 1597 |
}, |
| 1598 |
want: []string{ |
| 1599 |
"A ", |
| 1600 |
"DBC ", |
| 1601 |
"GEF ", |
| 1602 |
" HI ", |
| 1603 |
}, |
| 1604 |
pos: uv.Pos(1, 0), |
| 1605 |
}, |
| 1606 |
{ |
| 1607 |
name: "RI Outside Left/Right Scroll Region", |
| 1608 |
w: 10, h: 3, |
| 1609 |
input: []string{ |
| 1610 |
"\x1b[1;1H", // move to top-left |
| 1611 |
"\x1b[2J", // clear screen |
| 1612 |
"ABC\r\n", |
| 1613 |
"DEF\r\n", |
| 1614 |
"GHI", |
| 1615 |
"\x1b[?69h", // enable left/right margins |
| 1616 |
"\x1b[2;3s", // scroll region left/right |
| 1617 |
"\x1b[2;1H", |
| 1618 |
"\x1bM", |
| 1619 |
}, |
| 1620 |
want: []string{ |
| 1621 |
"ABC ", |
| 1622 |
"DEF ", |
| 1623 |
"GHI ", |
| 1624 |
}, |
| 1625 |
pos: uv.Pos(0, 0), |
| 1626 |
}, |
| 1627 |
|
| 1628 |
// Scroll Down [ansi.SD] |
| 1629 |
{ |
| 1630 |
name: "SD Outside of Top/Bottom Scroll Region", |
| 1631 |
w: 10, h: 4, |
| 1632 |
input: []string{ |
| 1633 |
"\x1b[1;1H", // move to top-left |
| 1634 |
"\x1b[2J", // clear screen |
| 1635 |
"ABC\r\n", |
| 1636 |
"DEF\r\n", |
| 1637 |
"GHI", |
| 1638 |
"\x1b[3;4r", // scroll region top/bottom |
| 1639 |
"\x1b[2;2H", // move cursor outside region |
| 1640 |
"\x1b[T", // scroll down |
| 1641 |
}, |
| 1642 |
want: []string{ |
| 1643 |
"ABC ", |
| 1644 |
"DEF ", |
| 1645 |
" ", |
| 1646 |
"GHI ", |
| 1647 |
}, |
| 1648 |
pos: uv.Pos(1, 1), |
| 1649 |
}, |
| 1650 |
|
| 1651 |
// Scroll Up [ansi.SU] |
| 1652 |
{ |
| 1653 |
name: "SU Simple Usage", |
| 1654 |
w: 10, h: 3, |
| 1655 |
input: []string{ |
| 1656 |
"\x1b[1;1H", // move to top-left |
| 1657 |
"\x1b[2J", // clear screen |
| 1658 |
"ABC\r\n", |
| 1659 |
"DEF\r\n", |
| 1660 |
"GHI", |
| 1661 |
"\x1b[2;2H", |
| 1662 |
"\x1b[S", |
| 1663 |
}, |
| 1664 |
want: []string{ |
| 1665 |
"DEF ", |
| 1666 |
"GHI ", |
| 1667 |
" ", |
| 1668 |
}, |
| 1669 |
pos: uv.Pos(1, 1), |
| 1670 |
}, |
| 1671 |
{ |
| 1672 |
name: "SU Top/Bottom Scroll Region", |
| 1673 |
w: 10, h: 3, |
| 1674 |
input: []string{ |
| 1675 |
"\x1b[1;1H", // move to top-left |
| 1676 |
"\x1b[2J", // clear screen |
| 1677 |
"ABC\r\n", |
| 1678 |
"DEF\r\n", |
| 1679 |
"GHI", |
| 1680 |
"\x1b[2;3r", // scroll region top/bottom |
| 1681 |
"\x1b[1;1H", |
| 1682 |
"\x1b[S", |
| 1683 |
}, |
| 1684 |
want: []string{ |
| 1685 |
"ABC ", |
| 1686 |
"GHI ", |
| 1687 |
" ", |
| 1688 |
}, |
| 1689 |
pos: uv.Pos(0, 0), |
| 1690 |
}, |
| 1691 |
{ |
| 1692 |
name: "SU Left/Right Scroll Regions", |
| 1693 |
w: 10, h: 3, |
| 1694 |
input: []string{ |
| 1695 |
"\x1b[1;1H", // move to top-left |
| 1696 |
"\x1b[2J", // clear screen |
| 1697 |
"ABC123\r\n", |
| 1698 |
"DEF456\r\n", |
| 1699 |
"GHI789", |
| 1700 |
"\x1b[?69h", // enable left/right margins |
| 1701 |
"\x1b[2;4s", // scroll region left/right |
| 1702 |
"\x1b[2;2H", |
| 1703 |
"\x1b[S", |
| 1704 |
}, |
| 1705 |
want: []string{ |
| 1706 |
"AEF423 ", |
| 1707 |
"DHI756 ", |
| 1708 |
"G 89 ", |
| 1709 |
}, |
| 1710 |
pos: uv.Pos(1, 1), |
| 1711 |
}, |
| 1712 |
{ |
| 1713 |
name: "SU Preserves Pending Wrap", |
| 1714 |
w: 10, h: 4, |
| 1715 |
input: []string{ |
| 1716 |
"\x1b[1;10H", // move to top-right |
| 1717 |
"\x1b[2J", // clear screen |
| 1718 |
"A", |
| 1719 |
"\x1b[2;10H", |
| 1720 |
"B", |
| 1721 |
"\x1b[3;10H", |
| 1722 |
"C", |
| 1723 |
"\x1b[S", |
| 1724 |
"X", |
| 1725 |
}, |
| 1726 |
want: []string{ |
| 1727 |
" B", |
| 1728 |
" C", |
| 1729 |
" ", |
| 1730 |
"X ", |
| 1731 |
}, |
| 1732 |
pos: uv.Pos(1, 3), |
| 1733 |
}, |
| 1734 |
{ |
| 1735 |
name: "SU Scroll Full Top/Bottom Scroll Region", |
| 1736 |
w: 10, h: 5, |
| 1737 |
input: []string{ |
| 1738 |
"\x1b[1;1H", // move to top-left |
| 1739 |
"\x1b[2J", // clear screen |
| 1740 |
"top", |
| 1741 |
"\x1b[5;1H", |
| 1742 |
"ABCDEF", |
| 1743 |
"\x1b[2;5r", // scroll region top/bottom |
| 1744 |
"\x1b[4S", |
| 1745 |
}, |
| 1746 |
want: []string{ |
| 1747 |
"top ", |
| 1748 |
" ", |
| 1749 |
" ", |
| 1750 |
" ", |
| 1751 |
" ", |
| 1752 |
}, |
| 1753 |
pos: uv.Pos(0, 0), |
| 1754 |
}, |
| 1755 |
|
| 1756 |
// Tab Clear [ansi.TBC] |
| 1757 |
{ |
| 1758 |
name: "TBC Clear Single Tab Stop", |
| 1759 |
w: 23, h: 1, |
| 1760 |
input: []string{ |
| 1761 |
"\x1b[1;1H", // move to top-left |
| 1762 |
"\x1b[2J", // clear screen |
| 1763 |
"\x1b[?W", // reset tabs |
| 1764 |
"\t", // tab to first stop |
| 1765 |
"\x1b[g", // clear current tab stop |
| 1766 |
"\x1b[1G", // move back to start |
| 1767 |
"\t", // tab again - should go to next stop |
| 1768 |
}, |
| 1769 |
want: []string{" "}, |
| 1770 |
pos: uv.Pos(16, 0), |
| 1771 |
}, |
| 1772 |
{ |
| 1773 |
name: "TBC Clear All Tab Stops", |
| 1774 |
w: 23, h: 1, |
| 1775 |
input: []string{ |
| 1776 |
"\x1b[1;1H", // move to top-left |
| 1777 |
"\x1b[2J", // clear screen |
| 1778 |
"\x1b[?W", // reset tabs |
| 1779 |
"\x1b[3g", // clear all tab stops |
| 1780 |
"\x1b[1G", // move back to start |
| 1781 |
"\t", // tab - should go to end since no stops |
| 1782 |
}, |
| 1783 |
want: []string{" "}, |
| 1784 |
pos: uv.Pos(22, 0), |
| 1785 |
}, |
| 1786 |
} |
| 1787 |
|
| 1788 |
// TestTerminal tests the terminal. |
| 1789 |
func TestTerminal(t *testing.T) { |
| 1790 |
for _, tt := range cases { |
| 1791 |
t.Run(tt.name, func(t *testing.T) { |
| 1792 |
term := newTestTerminal(t, tt.w, tt.h) |
| 1793 |
for _, in := range tt.input { |
| 1794 |
term.Write([]byte(in)) |
| 1795 |
} |
| 1796 |
got := termText(term) |
| 1797 |
if len(got) != len(tt.want) { |
| 1798 |
t.Errorf("output length doesn't match: want %d, got %d", len(tt.want), len(got)) |
| 1799 |
} |
| 1800 |
for i := 0; i < len(got) && i < len(tt.want); i++ { |
| 1801 |
if got[i] != tt.want[i] { |
| 1802 |
t.Errorf("line %d doesn't match:\nwant: %q\ngot: %q", i+1, tt.want[i], got[i]) |
| 1803 |
} |
| 1804 |
} |
| 1805 |
pos := term.CursorPosition() |
| 1806 |
if pos != tt.pos { |
| 1807 |
t.Errorf("cursor position doesn't match: want %v, got %v", tt.pos, pos) |
| 1808 |
} |
| 1809 |
}) |
| 1810 |
} |
| 1811 |
} |
| 1812 |
|
| 1813 |
func termText(term *Emulator) []string { |
| 1814 |
var lines []string |
| 1815 |
for y := range term.Height() { |
| 1816 |
var line string |
| 1817 |
for x := 0; x < term.Width(); x++ { |
| 1818 |
cell := term.CellAt(x, y) |
| 1819 |
if cell == nil { |
| 1820 |
continue |
| 1821 |
} |
| 1822 |
line += cell.String() |
| 1823 |
x += cell.Width - 1 |
| 1824 |
} |
| 1825 |
lines = append(lines, line) |
| 1826 |
} |
| 1827 |
return lines |
| 1828 |
} |