| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package tests |
| 16 |
|
| 17 |
import ( |
| 18 |
"testing" |
| 19 |
"time" |
| 20 |
|
| 21 |
"github.com/gdamore/tcell/v3/vt" |
| 22 |
) |
| 23 |
|
| 24 |
|
| 25 |
func TestScanCodes(t *testing.T) { |
| 26 |
cases := []struct { |
| 27 |
name string |
| 28 |
key vt.Key |
| 29 |
code vt.ScanCode |
| 30 |
}{ |
| 31 |
{"A", vt.KeyA, 0x1e}, |
| 32 |
{"B", vt.KeyB, 0x30}, |
| 33 |
{"C", vt.KeyC, 0x2e}, |
| 34 |
{"D", vt.KeyD, 0x20}, |
| 35 |
{"E", vt.KeyE, 0x12}, |
| 36 |
{"F", vt.KeyF, 0x21}, |
| 37 |
{"G", vt.KeyG, 0x22}, |
| 38 |
{"H", vt.KeyH, 0x23}, |
| 39 |
{"I", vt.KeyI, 0x17}, |
| 40 |
{"J", vt.KeyJ, 0x24}, |
| 41 |
{"K", vt.KeyK, 0x25}, |
| 42 |
{"L", vt.KeyL, 0x26}, |
| 43 |
{"M", vt.KeyM, 0x32}, |
| 44 |
{"N", vt.KeyN, 0x31}, |
| 45 |
{"O", vt.KeyO, 0x18}, |
| 46 |
{"P", vt.KeyP, 0x19}, |
| 47 |
{"Q", vt.KeyQ, 0x10}, |
| 48 |
{"R", vt.KeyR, 0x13}, |
| 49 |
{"S", vt.KeyS, 0x1f}, |
| 50 |
{"T", vt.KeyT, 0x14}, |
| 51 |
{"U", vt.KeyU, 0x16}, |
| 52 |
{"V", vt.KeyV, 0x2f}, |
| 53 |
{"W", vt.KeyW, 0x11}, |
| 54 |
{"X", vt.KeyX, 0x2d}, |
| 55 |
{"Y", vt.KeyY, 0x15}, |
| 56 |
{"Z", vt.KeyZ, 0x2c}, |
| 57 |
{"1", vt.Key1, 0x02}, |
| 58 |
{"2", vt.Key2, 0x03}, |
| 59 |
{"3", vt.Key3, 0x04}, |
| 60 |
{"4", vt.Key4, 0x05}, |
| 61 |
{"5", vt.Key5, 0x06}, |
| 62 |
{"6", vt.Key6, 0x07}, |
| 63 |
{"7", vt.Key7, 0x08}, |
| 64 |
{"8", vt.Key8, 0x09}, |
| 65 |
{"9", vt.Key9, 0x0a}, |
| 66 |
{"0", vt.Key0, 0x0b}, |
| 67 |
{"enter", vt.KeyEnter, 0x1c}, |
| 68 |
{"escape", vt.KeyEsc, 0x01}, |
| 69 |
{"bs", vt.KeyBackspace, 0x0e}, |
| 70 |
{"tab", vt.KeyTab, 0x0f}, |
| 71 |
{"space", vt.KeySpace, 0x39}, |
| 72 |
{"minus", vt.KeyMinus, 0x0c}, |
| 73 |
{"equals", vt.KeyEqual, 0x0d}, |
| 74 |
{"lbrace", vt.KeyLBrace, 0x1a}, |
| 75 |
{"rbrace", vt.KeyRBrace, 0x1b}, |
| 76 |
{"backslash", vt.KeyBackslash, 0x2b}, |
| 77 |
{"semicolon", vt.KeySemi, 0x27}, |
| 78 |
{"quote", vt.KeyQuote, 0x28}, |
| 79 |
{"grave", vt.KeyGrave, 0x29}, |
| 80 |
{"comma", vt.KeyComma, 0x33}, |
| 81 |
{"period", vt.KeyPeriod, 0x34}, |
| 82 |
{"slash", vt.KeySlash, 0x35}, |
| 83 |
{"capsLock", vt.KeyCapsLock, 0x3a}, |
| 84 |
{"f1", vt.KeyF1, 0x3b}, |
| 85 |
{"f2", vt.KeyF2, 0x3c}, |
| 86 |
{"f3", vt.KeyF3, 0x3d}, |
| 87 |
{"f4", vt.KeyF4, 0x3e}, |
| 88 |
{"f5", vt.KeyF5, 0x3f}, |
| 89 |
{"f6", vt.KeyF6, 0x40}, |
| 90 |
{"f7", vt.KeyF7, 0x41}, |
| 91 |
{"f8", vt.KeyF8, 0x42}, |
| 92 |
{"f9", vt.KeyF9, 0x43}, |
| 93 |
{"f10", vt.KeyF10, 0x44}, |
| 94 |
{"f11", vt.KeyF11, 0x57}, |
| 95 |
{"f12", vt.KeyF12, 0x58}, |
| 96 |
{"prtScr", vt.KeyPrtScr, 0x54}, |
| 97 |
{"scrLock", vt.KeyScrLock, 0x46}, |
| 98 |
{"pause", vt.KeyPause, 0xe046}, |
| 99 |
{"ins", vt.KeyInsert, 0xe052}, |
| 100 |
{"home", vt.KeyHome, 0xe047}, |
| 101 |
{"pgUp", vt.KeyPgUp, 0xe049}, |
| 102 |
{"del", vt.KeyDelete, 0xe053}, |
| 103 |
{"end", vt.KeyEnd, 0xe04f}, |
| 104 |
{"pgDn", vt.KeyPgDn, 0xe051}, |
| 105 |
{"right", vt.KeyRight, 0xe04d}, |
| 106 |
{"left", vt.KeyLeft, 0xe04b}, |
| 107 |
{"down", vt.KeyDown, 0xe050}, |
| 108 |
{"up", vt.KeyUp, 0xe048}, |
| 109 |
{"numLock", vt.KeyNumLock, 0x45}, |
| 110 |
{"div", vt.KeyPadDiv, 0xe035}, |
| 111 |
{"mul", vt.KeyPadMul, 0x37}, |
| 112 |
{"sub", vt.KeyPadSub, 0x4a}, |
| 113 |
{"add", vt.KeyPadAdd, 0x4e}, |
| 114 |
{"enter", vt.KeyPadEnter, 0xe01c}, |
| 115 |
{"pad1", vt.KeyPad1, 0x4f}, |
| 116 |
{"pad2", vt.KeyPad2, 0x50}, |
| 117 |
{"pad3", vt.KeyPad3, 0x51}, |
| 118 |
{"pad4", vt.KeyPad4, 0x4b}, |
| 119 |
{"pad5", vt.KeyPad5, 0x4c}, |
| 120 |
{"pad6", vt.KeyPad6, 0x4d}, |
| 121 |
{"pad7", vt.KeyPad7, 0x47}, |
| 122 |
{"pad8", vt.KeyPad8, 0x48}, |
| 123 |
{"pad9", vt.KeyPad9, 0x49}, |
| 124 |
{"pad0", vt.KeyPad0, 0x52}, |
| 125 |
{"padDecimal", vt.KeyPadDec, 0x53}, |
| 126 |
{"isoBackSlash", vt.KeyIsoBackSlash, 0x56}, |
| 127 |
{"padEqual", vt.KeyPadEqual, 0x59}, |
| 128 |
{"f13", vt.KeyF13, 0x64}, |
| 129 |
{"f14", vt.KeyF14, 0x65}, |
| 130 |
{"f15", vt.KeyF15, 0x66}, |
| 131 |
{"f16", vt.KeyF16, 0x67}, |
| 132 |
{"f17", vt.KeyF17, 0x68}, |
| 133 |
{"f18", vt.KeyF18, 0x69}, |
| 134 |
{"f19", vt.KeyF19, 0x6a}, |
| 135 |
{"f20", vt.KeyF20, 0x6b}, |
| 136 |
{"f21", vt.KeyF21, 0x6c}, |
| 137 |
{"f22", vt.KeyF22, 0x6d}, |
| 138 |
{"f23", vt.KeyF23, 0x6e}, |
| 139 |
{"f24", vt.KeyF24, 0x76}, |
| 140 |
{"padComma", vt.KeyPadComma, 0x7e}, |
| 141 |
{"padIsoSlash", vt.KeyIsoSlash, 0x73}, |
| 142 |
{"hiragana", vt.KeyHiragana, 0x70}, |
| 143 |
{"yen", vt.KeyYen, 0x7d}, |
| 144 |
{"convert", vt.KeyConvert, 0x79}, |
| 145 |
{"noConvert", vt.KeyNonConvert, 0x7b}, |
| 146 |
{"leftCtrl", vt.KeyLCtrl, 0x1d}, |
| 147 |
{"leftShift", vt.KeyLShift, 0x2a}, |
| 148 |
{"leftAlt", vt.KeyLAlt, 0x38}, |
| 149 |
{"leftMeta", vt.KeyLMeta, 0xe05b}, |
| 150 |
{"rightCtrl", vt.KeyRCtrl, 0xe01d}, |
| 151 |
{"rightShift", vt.KeyRShift, 0x36}, |
| 152 |
{"rightAlt", vt.KeyRAlt, 0xe038}, |
| 153 |
{"rightMeta", vt.KeyRMeta, 0xe05c}, |
| 154 |
{"menu", vt.KeyMenu, 0xe05d}, |
| 155 |
} |
| 156 |
for i := range cases { |
| 157 |
t.Run(cases[i].name, func(t *testing.T) { |
| 158 |
VerifyF(t, cases[i].key.ScanCode() == cases[i].code, "Scan code %x did not match %x", cases[i].key.ScanCode(), cases[i].code) |
| 159 |
}) |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
seen := make(map[vt.ScanCode]vt.Key) |
| 164 |
for i := range cases { |
| 165 |
sc := cases[i].key.ScanCode() |
| 166 |
if other, ok := seen[sc]; ok { |
| 167 |
t.Errorf("Duplicate scan %x code for key %x and %x", sc, cases[i].key, other) |
| 168 |
} |
| 169 |
seen[sc] = cases[i].key |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
func TestBaseKeys(t *testing.T) { |
| 176 |
cases := []struct { |
| 177 |
name string |
| 178 |
key vt.Key |
| 179 |
base vt.BaseKey |
| 180 |
shifted rune |
| 181 |
}{ |
| 182 |
{"A", vt.KeyA, 'a', 'A'}, |
| 183 |
{"B", vt.KeyB, 'b', 'B'}, |
| 184 |
{"C", vt.KeyC, 'c', 'C'}, |
| 185 |
{"D", vt.KeyD, 'd', 'D'}, |
| 186 |
{"E", vt.KeyE, 'e', 'E'}, |
| 187 |
{"F", vt.KeyF, 'f', 'F'}, |
| 188 |
{"G", vt.KeyG, 'g', 'G'}, |
| 189 |
{"H", vt.KeyH, 'h', 'H'}, |
| 190 |
{"I", vt.KeyI, 'i', 'I'}, |
| 191 |
{"J", vt.KeyJ, 'j', 'J'}, |
| 192 |
{"K", vt.KeyK, 'k', 'K'}, |
| 193 |
{"L", vt.KeyL, 'l', 'L'}, |
| 194 |
{"M", vt.KeyM, 'm', 'M'}, |
| 195 |
{"N", vt.KeyN, 'n', 'N'}, |
| 196 |
{"O", vt.KeyO, 'o', 'O'}, |
| 197 |
{"P", vt.KeyP, 'p', 'P'}, |
| 198 |
{"Q", vt.KeyQ, 'q', 'Q'}, |
| 199 |
{"R", vt.KeyR, 'r', 'R'}, |
| 200 |
{"S", vt.KeyS, 's', 'S'}, |
| 201 |
{"T", vt.KeyT, 't', 'T'}, |
| 202 |
{"U", vt.KeyU, 'u', 'U'}, |
| 203 |
{"V", vt.KeyV, 'v', 'V'}, |
| 204 |
{"W", vt.KeyW, 'w', 'W'}, |
| 205 |
{"X", vt.KeyX, 'x', 'X'}, |
| 206 |
{"Y", vt.KeyY, 'y', 'Y'}, |
| 207 |
{"Z", vt.KeyZ, 'z', 'Z'}, |
| 208 |
{"1", vt.Key1, '1', '!'}, |
| 209 |
{"2", vt.Key2, '2', '@'}, |
| 210 |
{"3", vt.Key3, '3', '#'}, |
| 211 |
{"4", vt.Key4, '4', '$'}, |
| 212 |
{"5", vt.Key5, '5', '%'}, |
| 213 |
{"6", vt.Key6, '6', '^'}, |
| 214 |
{"7", vt.Key7, '7', '&'}, |
| 215 |
{"8", vt.Key8, '8', '*'}, |
| 216 |
{"9", vt.Key9, '9', '('}, |
| 217 |
{"0", vt.Key0, '0', ')'}, |
| 218 |
{"minus", vt.KeyMinus, '-', '_'}, |
| 219 |
{"equal", vt.KeyEqual, '=', '+'}, |
| 220 |
{"lbrace", vt.KeyLBrace, '[', '{'}, |
| 221 |
{"backslash", vt.KeyBackslash, '\\', '|'}, |
| 222 |
{"rbrace", vt.KeyRBrace, ']', '}'}, |
| 223 |
{"semi", vt.KeySemi, ';', ':'}, |
| 224 |
{"backslash-iso", vt.KeyIsoBackSlash, '\\', '|'}, |
| 225 |
{"comma", vt.KeyComma, ',', '<'}, |
| 226 |
{"period", vt.KeyPeriod, '.', '>'}, |
| 227 |
{"slash", vt.KeySlash, '/', '?'}, |
| 228 |
{"yen", vt.KeyYen, '¥', '|'}, |
| 229 |
} |
| 230 |
for i := range cases { |
| 231 |
t.Run(cases[i].name, func(t *testing.T) { |
| 232 |
base := cases[i].key.KittyBase() |
| 233 |
shift := base.Shifted() |
| 234 |
VerifyF(t, base == cases[i].base, "Base code %x did not match %x", base, cases[i].base) |
| 235 |
VerifyF(t, shift == cases[i].shifted, "Base code %q %x did not match %q %x", string(shift), shift, string(cases[i].shifted), cases[i].shifted) |
| 236 |
}) |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
func TestKeyRepeat(t *testing.T) { |
| 242 |
term := vt.NewMockTerm() |
| 243 |
defer MustClose(t, term) |
| 244 |
|
| 245 |
MustStart(t, term) |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 250 |
|
| 251 |
term.KeyPress(vt.KeyX) |
| 252 |
time.Sleep(100 * time.Millisecond) |
| 253 |
term.KeyPress(vt.KeyX) |
| 254 |
term.KeyRelease(vt.KeyX) |
| 255 |
term.KeyRelease(vt.KeyCapsLock) |
| 256 |
|
| 257 |
CheckRead(t, term, "xx") |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
func TestKeyRepeatDisabled(t *testing.T) { |
| 262 |
term := vt.NewMockTerm() |
| 263 |
defer MustClose(t, term) |
| 264 |
|
| 265 |
MustStart(t, term) |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 270 |
WriteF(t, term, "\x1b[?8l") |
| 271 |
|
| 272 |
term.KeyPress(vt.KeyX) |
| 273 |
time.Sleep(100 * time.Millisecond) |
| 274 |
term.KeyPress(vt.KeyX) |
| 275 |
term.KeyRelease(vt.KeyX) |
| 276 |
|
| 277 |
CheckRead(t, term, "x") |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
func TestKeyRepeatCapsLock(t *testing.T) { |
| 282 |
term := vt.NewMockTerm() |
| 283 |
defer MustClose(t, term) |
| 284 |
|
| 285 |
MustStart(t, term) |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
term.SetRepeat(time.Millisecond*50, time.Millisecond*250) |
| 290 |
|
| 291 |
term.KeyPress(vt.KeyCapsLock) |
| 292 |
term.KeyPress(vt.KeyZ) |
| 293 |
time.Sleep(90 * time.Millisecond) |
| 294 |
term.KeyPress(vt.KeyZ) |
| 295 |
term.KeyRelease(vt.KeyZ) |
| 296 |
term.KeyRelease(vt.KeyCapsLock) |
| 297 |
|
| 298 |
CheckRead(t, term, "ZZ") |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
func TestKeyRepeatNoAlt(t *testing.T) { |
| 303 |
term := vt.NewMockTerm() |
| 304 |
defer MustClose(t, term) |
| 305 |
|
| 306 |
MustStart(t, term) |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 311 |
|
| 312 |
term.KeyPress(vt.KeyLAlt) |
| 313 |
term.KeyPress(vt.KeyZ) |
| 314 |
time.Sleep(100 * time.Millisecond) |
| 315 |
term.KeyPress(vt.KeyZ) |
| 316 |
term.KeyRelease(vt.KeyZ) |
| 317 |
term.KeyRelease(vt.KeyLAlt) |
| 318 |
|
| 319 |
CheckRead(t, term, "\x1bz") |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
func TestKeyRepeatShift(t *testing.T) { |
| 324 |
term := vt.NewMockTerm() |
| 325 |
defer MustClose(t, term) |
| 326 |
|
| 327 |
MustStart(t, term) |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
term.SetRepeat(time.Millisecond*50, time.Millisecond*250) |
| 332 |
|
| 333 |
term.KeyPress(vt.KeyLShift) |
| 334 |
term.KeyPress(vt.Key1) |
| 335 |
time.Sleep(90 * time.Millisecond) |
| 336 |
term.KeyPress(vt.Key1) |
| 337 |
term.KeyRelease(vt.Key1) |
| 338 |
term.KeyRelease(vt.KeyLShift) |
| 339 |
|
| 340 |
CheckRead(t, term, "!!") |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
func TestKeyRepeatShiftRelease(t *testing.T) { |
| 345 |
term := vt.NewMockTerm() |
| 346 |
defer MustClose(t, term) |
| 347 |
|
| 348 |
MustStart(t, term) |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
term.SetRepeat(time.Millisecond*50, time.Millisecond*250) |
| 353 |
|
| 354 |
term.KeyPress(vt.KeyLShift) |
| 355 |
term.KeyPress(vt.Key2) |
| 356 |
term.KeyRelease(vt.KeyLShift) |
| 357 |
time.Sleep(90 * time.Millisecond) |
| 358 |
term.KeyPress(vt.Key2) |
| 359 |
term.KeyRelease(vt.Key2) |
| 360 |
|
| 361 |
CheckRead(t, term, "@2") |
| 362 |
} |
| 363 |
|
| 364 |
func TestKeyRepeatCursor(t *testing.T) { |
| 365 |
term := vt.NewMockTerm() |
| 366 |
defer MustClose(t, term) |
| 367 |
|
| 368 |
MustStart(t, term) |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 373 |
|
| 374 |
term.KeyPress(vt.KeyRight) |
| 375 |
time.Sleep(100 * time.Millisecond) |
| 376 |
term.KeyPress(vt.KeyRight) |
| 377 |
term.KeyRelease(vt.KeyRight) |
| 378 |
term.KeyRelease(vt.KeyRight) |
| 379 |
|
| 380 |
CheckRead(t, term, "\x1b[C\x1b[C") |
| 381 |
} |
| 382 |
|
| 383 |
func TestKeyWin32(t *testing.T) { |
| 384 |
|
| 385 |
|
| 386 |
term := vt.NewMockTerm() |
| 387 |
defer MustClose(t, term) |
| 388 |
|
| 389 |
MustStart(t, term) |
| 390 |
WriteF(t, term, "%s", vt.PmWin32Input.Enable()) |
| 391 |
|
| 392 |
var want string |
| 393 |
|
| 394 |
term.KeyTap(vt.KeySpace) |
| 395 |
want = "\x1b[32;57;32;1;0;1_" + "\x1b[32;57;32;0;0;1_" |
| 396 |
CheckRead(t, term, want) |
| 397 |
|
| 398 |
term.KeyTap(vt.KeyLAlt, vt.KeyG) |
| 399 |
want = "\x1b[164;56;0;1;2;1_" + |
| 400 |
"\x1b[71;34;103;1;2;1_" + |
| 401 |
"\x1b[71;34;103;0;2;1_" + |
| 402 |
"\x1b[164;56;0;0;0;1_" |
| 403 |
CheckRead(t, term, want) |
| 404 |
|
| 405 |
term.KeyTap(vt.KeyRAlt, vt.Key1) |
| 406 |
want = "\x1b[165;57400;0;1;1;1_" + |
| 407 |
"\x1b[49;2;49;1;1;1_" + |
| 408 |
"\x1b[49;2;49;0;1;1_" + |
| 409 |
"\x1b[165;57400;0;0;0;1_" |
| 410 |
CheckRead(t, term, want) |
| 411 |
|
| 412 |
term.KeyTap(vt.KeyRCtrl, vt.KeyF1) |
| 413 |
want = "\x1b[163;57373;0;1;4;1_" + |
| 414 |
"\x1b[112;59;0;1;4;1_" + |
| 415 |
"\x1b[112;59;0;0;4;1_" + |
| 416 |
"\x1b[163;57373;0;0;0;1_" |
| 417 |
CheckRead(t, term, want) |
| 418 |
|
| 419 |
|
| 420 |
term.KeyTap(vt.KeyLShift, vt.KeyTab) |
| 421 |
want = "\x1b[160;42;0;1;16;1_\x1b[9;15;9;1;16;1_\x1b[9;15;9;0;16;1_\x1b[160;42;0;0;0;1_" |
| 422 |
CheckRead(t, term, want) |
| 423 |
|
| 424 |
term.KeyTap(vt.KeyNumLock) |
| 425 |
term.KeyTap(vt.KeyPad0) |
| 426 |
term.KeyTap(vt.KeyNumLock) |
| 427 |
want = "\x1b[144;69;0;1;32;1_" + |
| 428 |
"\x1b[144;69;0;0;32;1_" + |
| 429 |
"\x1b[45;82;48;1;32;1_" + |
| 430 |
"\x1b[45;82;48;0;32;1_" + |
| 431 |
"\x1b[144;69;0;1;0;1_" + |
| 432 |
"\x1b[144;69;0;0;0;1_" |
| 433 |
CheckRead(t, term, want) |
| 434 |
|
| 435 |
term.KeyTap(vt.KeyCapsLock) |
| 436 |
term.KeyTap(vt.KeyJ) |
| 437 |
term.KeyTap(vt.KeyCapsLock) |
| 438 |
want = "\x1b[20;58;0;1;128;1_" + |
| 439 |
"\x1b[20;58;0;0;128;1_" + |
| 440 |
"\x1b[74;36;74;1;128;1_" + |
| 441 |
"\x1b[74;36;74;0;128;1_" + |
| 442 |
"\x1b[20;58;0;1;0;1_" + |
| 443 |
"\x1b[20;58;0;0;0;1_" |
| 444 |
CheckRead(t, term, want) |
| 445 |
|
| 446 |
term.KeyTap(vt.KeyPadEnter) |
| 447 |
want = "\x1b[0;57372;13;1;0;1_\x1b[0;57372;13;0;0;1_" |
| 448 |
CheckRead(t, term, want) |
| 449 |
|
| 450 |
term.KeyTap(vt.KeyPadDiv) |
| 451 |
want = "\x1b[111;57397;47;1;0;1_\x1b[111;57397;47;0;0;1_" |
| 452 |
CheckRead(t, term, want) |
| 453 |
|
| 454 |
term.KeyTap(vt.KeyInsert) |
| 455 |
want = "\x1b[45;57426;0;1;0;1_\x1b[45;57426;0;0;0;1_" |
| 456 |
CheckRead(t, term, want) |
| 457 |
|
| 458 |
term.KeyTap(vt.KeyDelete) |
| 459 |
want = "\x1b[46;57427;0;1;0;1_\x1b[46;57427;0;0;0;1_" |
| 460 |
CheckRead(t, term, want) |
| 461 |
|
| 462 |
term.KeyTap(vt.KeyPgUp) |
| 463 |
want = "\x1b[33;57417;0;1;0;1_\x1b[33;57417;0;0;0;1_" |
| 464 |
CheckRead(t, term, want) |
| 465 |
|
| 466 |
term.KeyTap(vt.KeyPgDn) |
| 467 |
want = "\x1b[34;57425;0;1;256;1_\x1b[34;57425;0;0;256;1_" |
| 468 |
CheckRead(t, term, want) |
| 469 |
|
| 470 |
term.KeyTap(vt.KeyHome) |
| 471 |
want = "\x1b[36;57415;0;1;0;1_\x1b[36;57415;0;0;0;1_" |
| 472 |
CheckRead(t, term, want) |
| 473 |
|
| 474 |
term.KeyTap(vt.KeyEnd) |
| 475 |
want = "\x1b[35;57423;0;1;0;1_\x1b[35;57423;0;0;0;1_" |
| 476 |
CheckRead(t, term, want) |
| 477 |
|
| 478 |
term.KeyTap(vt.KeyEnter) |
| 479 |
want = "\x1b[13;28;13;1;0;1_\x1b[13;28;13;0;0;1_" |
| 480 |
CheckRead(t, term, want) |
| 481 |
|
| 482 |
term.KeyTap(vt.KeyLMeta) |
| 483 |
want = "\x1b[91;57435;0;1;0;1_\x1b[91;57435;0;0;0;1_" |
| 484 |
CheckRead(t, term, want) |
| 485 |
} |
| 486 |
|
| 487 |
func TestKeyWin32NoRepeat(t *testing.T) { |
| 488 |
term := vt.NewMockTerm() |
| 489 |
defer MustClose(t, term) |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 494 |
MustStart(t, term) |
| 495 |
WriteF(t, term, "%s", vt.PmWin32Input.Enable()) |
| 496 |
WriteF(t, term, "%s", vt.PmAutoRepeat.Enable()) |
| 497 |
|
| 498 |
term.KeyPress(vt.KeyPause) |
| 499 |
time.Sleep(time.Millisecond * 100) |
| 500 |
term.KeyPress(vt.KeyPause) |
| 501 |
term.KeyRelease(vt.KeyPause) |
| 502 |
want := "\x1b[19;57414;0;1;0;1_\x1b[19;57414;0;0;0;1_" |
| 503 |
CheckRead(t, term, want) |
| 504 |
} |
| 505 |
|
| 506 |
func TestKeyWin32Repeat(t *testing.T) { |
| 507 |
term := vt.NewMockTerm() |
| 508 |
defer MustClose(t, term) |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 513 |
MustStart(t, term) |
| 514 |
WriteF(t, term, "%s", vt.PmWin32Input.Enable()) |
| 515 |
WriteF(t, term, "%s", vt.PmAutoRepeat.Enable()) |
| 516 |
|
| 517 |
term.KeyPress(vt.KeyA) |
| 518 |
time.Sleep(time.Millisecond * 100) |
| 519 |
term.KeyPress(vt.KeyA) |
| 520 |
term.KeyRelease(vt.KeyA) |
| 521 |
want := "\x1b[65;30;97;1;0;1_\x1b[65;30;97;1;0;1_\x1b[65;30;97;0;0;1_" |
| 522 |
CheckRead(t, term, want) |
| 523 |
} |
| 524 |
|
| 525 |
func TestKeyWin32NoRepeatMode(t *testing.T) { |
| 526 |
term := vt.NewMockTerm() |
| 527 |
defer MustClose(t, term) |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
term.SetRepeat(time.Millisecond*50, time.Second) |
| 532 |
MustStart(t, term) |
| 533 |
WriteF(t, term, "%s", vt.PmWin32Input.Enable()) |
| 534 |
WriteF(t, term, "%s", vt.PmAutoRepeat.Disable()) |
| 535 |
|
| 536 |
term.KeyPress(vt.KeyB) |
| 537 |
time.Sleep(time.Millisecond * 100) |
| 538 |
term.KeyPress(vt.KeyB) |
| 539 |
term.KeyRelease(vt.KeyB) |
| 540 |
want := "\x1b[66;48;98;1;0;1_\x1b[66;48;98;0;0;1_" |
| 541 |
CheckRead(t, term, want) |
| 542 |
} |