diff options
-rw-r--r-- | boxes.c | 129 |
1 files changed, 81 insertions, 48 deletions
@@ -305,22 +305,23 @@ struct key | |||
305 | 305 | ||
306 | // This table includes some variations I have found on some terminals, and the MC "Esc digit" versions. | 306 | // This table includes some variations I have found on some terminals, and the MC "Esc digit" versions. |
307 | // TODO - Don't think I got all the linux console variations. | 307 | // TODO - Don't think I got all the linux console variations. |
308 | // TODO - Add more shift variations, plus Ctrl & Alt variations. | 308 | // TODO - Add more shift variations, plus Ctrl & Alt variations when needed. |
309 | // TODO - tmux messes with the shift function keys somehow. | 309 | // TODO - tmux messes with the shift function keys somehow. |
310 | // TODO - Add other miscelany that does not use an escape sequence. Including mouse events. | 310 | // TODO - Add other miscelany that does not use an escape sequence. |
311 | // TODO - maybe worth writing a proper CSI parse instead. Would be useful for terminal size and mouse reports. | ||
311 | 312 | ||
312 | // This is sorted to say which terminal is which, though there is some overlap. | 313 | // This is sorted by type, though there is some overlap. |
313 | // Human typing speeds wont need binary searching speeds on this small table. | 314 | // Human typing speeds wont need binary searching speeds on this small table. |
314 | // So simple wins out over speed, and sorting by terminal type wins the simple test. | 315 | // So simple wins out over speed, and sorting by terminal type wins the simple test. |
315 | struct key keys[] = | 316 | struct key keys[] = |
316 | { | 317 | { |
317 | // Control characters. | 318 | // Control characters. |
318 | // {"\x00", "^@"}, // NUL Commented out coz it's the C string terminator, and may confuse things. | 319 | // {"\x00", "^@"}, // NUL Commented out coz it's the C string terminator, and may confuse things. |
319 | {"\x01", "^A"}, // SOH | 320 | {"\x01", "^A"}, // SOH Apparently sometimes sent as Home |
320 | {"\x02", "^B"}, // STX | 321 | {"\x02", "^B"}, // STX |
321 | {"\x03", "^C"}, // ETX SIGTERM | 322 | {"\x03", "^C"}, // ETX SIGTERM |
322 | {"\x04", "^D"}, // EOT | 323 | {"\x04", "^D"}, // EOT |
323 | {"\x05", "^E"}, // ENQ | 324 | {"\x05", "^E"}, // ENQ Apparently sometimes sent as End |
324 | {"\x06", "^F"}, // ACK | 325 | {"\x06", "^F"}, // ACK |
325 | {"\x07", "^G"}, // BEL | 326 | {"\x07", "^G"}, // BEL |
326 | {"\x08", "Del"}, // BS Delete key, usually. | 327 | {"\x08", "Del"}, // BS Delete key, usually. |
@@ -342,47 +343,23 @@ struct key keys[] = | |||
342 | {"\x18", "^X"}, // CAN | 343 | {"\x18", "^X"}, // CAN |
343 | {"\x19", "^Y"}, // EM | 344 | {"\x19", "^Y"}, // EM |
344 | {"\x1A", "^Z"}, // SUB | 345 | {"\x1A", "^Z"}, // SUB |
345 | // {"\x1B", "^["}, // ESC Esc key. Commented out coz it's the ANSI start byte in the above multibyte keys. Handled in the code with a timeout. | 346 | // {"\x1B", "^["}, // ESC Esc key. Commented out coz it's the ANSI start byte in the below multibyte keys. Handled in the code with a timeout. |
346 | {"\x1C", "^\\"}, // FS SIGQUIT | 347 | {"\x1C", "^\\"}, // FS SIGQUIT |
347 | {"\x1D", "^]"}, // GS | 348 | {"\x1D", "^]"}, // GS |
348 | {"\x1E", "^^"}, // RS | 349 | {"\x1E", "^^"}, // RS |
349 | {"\x1F", "^_"}, // US | 350 | {"\x1F", "^_"}, // US |
350 | {"\x7f", "BS"}, // Backspace key, usually. Ctrl-? perhaps? | 351 | {"\x7F", "BS"}, // Backspace key, usually. Ctrl-? perhaps? |
352 | {"\x9B", "CSI"}, // CSI The eight bit encoding of "Esc [". | ||
351 | 353 | ||
352 | // TODO - sort these into terminal types, just for reference. | 354 | // "Usual" xterm CSI sequences, with ";1" omitted for no modifiers. |
353 | {"\x1B[3~", "Del"}, | 355 | {"\x1B[1~", "Home"}, // Duplicate, think I've seen this somewhere. |
354 | {"\x1B[2~", "Ins"}, | 356 | {"\x1B[2~", "Ins"}, |
355 | {"\x1B[D", "Left"}, | 357 | {"\x1B[3~", "Del"}, |
356 | {"\x1BOD", "Left"}, | 358 | {"\x1B[4~", "End"}, // Duplicate, think I've seen this somewhere. |
357 | {"\x1B[C", "Right"}, | ||
358 | {"\x1BOC", "Right"}, | ||
359 | {"\x1B[A", "Up"}, | ||
360 | {"\x1BOA", "Up"}, | ||
361 | {"\x1B[B", "Down"}, | ||
362 | {"\x1BOB", "Down"}, | ||
363 | {"\x1B\x4f\x48", "Home"}, | ||
364 | {"\x1B[1~", "Home"}, | ||
365 | {"\x1B[7~", "Home"}, | ||
366 | {"\x1B[H", "Home"}, | ||
367 | {"\x1BOH", "Home"}, | ||
368 | {"\x1B\x4f\x46", "End"}, | ||
369 | {"\x1B[4~", "End"}, | ||
370 | {"\x1B[8~", "End"}, | ||
371 | {"\x1B[F", "End"}, | ||
372 | {"\x1BOF", "End"}, | ||
373 | {"\x1BOw", "End"}, | ||
374 | {"\x1B[5~", "PgUp"}, | 359 | {"\x1B[5~", "PgUp"}, |
375 | {"\x1B[6~", "PgDn"}, | 360 | {"\x1B[6~", "PgDn"}, |
376 | {"\x1B\x4F\x50", "F1"}, | 361 | {"\x1B[7~", "Home"}, |
377 | {"\x1B\x4F\x51", "F2"}, | 362 | {"\x1B[8~", "End"}, |
378 | {"\x1B\x4F\x52", "F3"}, | ||
379 | {"\x1B\x4F\x53", "F4"}, | ||
380 | |||
381 | {"\x1BOP", "F1"}, | ||
382 | {"\x1BOO", "F2"}, | ||
383 | {"\x1BOR", "F3"}, | ||
384 | {"\x1BOS", "F4"}, | ||
385 | |||
386 | {"\x1B[11~", "F1"}, | 363 | {"\x1B[11~", "F1"}, |
387 | {"\x1B[12~", "F2"}, | 364 | {"\x1B[12~", "F2"}, |
388 | {"\x1B[13~", "F3"}, | 365 | {"\x1B[13~", "F3"}, |
@@ -396,16 +373,19 @@ struct key keys[] = | |||
396 | {"\x1B[23~", "F11"}, | 373 | {"\x1B[23~", "F11"}, |
397 | {"\x1B[24~", "F12"}, | 374 | {"\x1B[24~", "F12"}, |
398 | 375 | ||
399 | {"\x1B\x4f\x31;2P", "Shift F1"}, | 376 | // As above, ";2" means shift modifier. |
400 | {"\x1B\x4f\x31;2Q", "Shift F2"}, | 377 | {"\x1B[1;2~", "Shift Home"}, |
401 | {"\x1B\x4f\x31;2R", "Shift F3"}, | 378 | {"\x1B[2;2~", "Shift Ins"}, |
402 | {"\x1B\x4f\x31;2S", "Shift F4"}, | 379 | {"\x1B[3;2~", "Shift Del"}, |
403 | 380 | {"\x1B[4;2~", "Shift End"}, | |
404 | {"\x1B[1;2P", "Shift F1"}, | 381 | {"\x1B[5;2~", "Shift PgUp"}, |
405 | {"\x1B[1;2Q", "Shift F2"}, | 382 | {"\x1B[6;2~", "Shift PgDn"}, |
406 | {"\x1B[1;2R", "Shift F3"}, | 383 | {"\x1B[7;2~", "Shift Home"}, |
407 | {"\x1B[1;2S", "Shift F4"}, | 384 | {"\x1B[8;2~", "Shift End"}, |
408 | 385 | {"\x1B[11;2~", "Shift F1"}, | |
386 | {"\x1B[12;2~", "Shift F2"}, | ||
387 | {"\x1B[13;2~", "Shift F3"}, | ||
388 | {"\x1B[14;2~", "Shift F4"}, | ||
409 | {"\x1B[15;2~", "Shift F5"}, | 389 | {"\x1B[15;2~", "Shift F5"}, |
410 | {"\x1B[17;2~", "Shift F6"}, | 390 | {"\x1B[17;2~", "Shift F6"}, |
411 | {"\x1B[18;2~", "Shift F7"}, | 391 | {"\x1B[18;2~", "Shift F7"}, |
@@ -415,6 +395,59 @@ struct key keys[] = | |||
415 | {"\x1B[23;2~", "Shift F11"}, | 395 | {"\x1B[23;2~", "Shift F11"}, |
416 | {"\x1B[24;2~", "Shift F12"}, | 396 | {"\x1B[24;2~", "Shift F12"}, |
417 | 397 | ||
398 | // Some terminals are special, and it seems they only have four function keys. | ||
399 | {"\x1B[A", "Up"}, | ||
400 | {"\x1B[B", "Down"}, | ||
401 | {"\x1B[C", "Right"}, | ||
402 | {"\x1B[D", "Left"}, | ||
403 | {"\x1B[F", "End"}, | ||
404 | {"\x1B[H", "Home"}, | ||
405 | {"\x1B[P", "F1"}, | ||
406 | {"\x1B[Q", "F2"}, | ||
407 | {"\x1B[R", "F3"}, | ||
408 | {"\x1B[S", "F4"}, | ||
409 | {"\x1B[1;2P", "Shift F1"}, | ||
410 | {"\x1B[1;2Q", "Shift F2"}, | ||
411 | {"\x1B[1;2R", "Shift F3"}, | ||
412 | {"\x1B[1;2S", "Shift F4"}, | ||
413 | |||
414 | // Not sure what this odd collection is. | ||
415 | {"\x1BOA", "Up"}, | ||
416 | {"\x1BOB", "Down"}, | ||
417 | {"\x1BOC", "Right"}, | ||
418 | {"\x1BOD", "Left"}, | ||
419 | {"\x1BOF", "End"}, | ||
420 | {"\x1BOH", "Home"}, | ||
421 | {"\x1BOn", "Del"}, | ||
422 | {"\x1BOp", "Ins"}, | ||
423 | {"\x1BOq", "End"}, | ||
424 | {"\x1BOw", "Home"}, | ||
425 | {"\x1BOP", "F1"}, | ||
426 | {"\x1BOO", "F2"}, | ||
427 | {"\x1BOR", "F3"}, | ||
428 | {"\x1BOS", "F4"}, | ||
429 | {"\x1BOT", "F5"}, | ||
430 | // These two conflict with the above four function key variation. | ||
431 | {"\x1B[R", "F6"}, | ||
432 | {"\x1B[S", "F7"}, | ||
433 | {"\x1B[T", "F8"}, | ||
434 | {"\x1B[U", "F9"}, | ||
435 | {"\x1B[V", "F10"}, | ||
436 | {"\x1B[W", "F11"}, | ||
437 | {"\x1B[X", "F12"}, | ||
438 | |||
439 | // Can't remember, but saw them somewhere. | ||
440 | {"\x1B\x4f\x46", "End"}, | ||
441 | {"\x1B\x4f\x48", "Home"}, | ||
442 | {"\x1B\x4F\x50", "F1"}, | ||
443 | {"\x1B\x4F\x51", "F2"}, | ||
444 | {"\x1B\x4F\x52", "F3"}, | ||
445 | {"\x1B\x4F\x53", "F4"}, | ||
446 | {"\x1B\x4f\x31;2P", "Shift F1"}, | ||
447 | {"\x1B\x4f\x31;2Q", "Shift F2"}, | ||
448 | {"\x1B\x4f\x31;2R", "Shift F3"}, | ||
449 | {"\x1B\x4f\x31;2S", "Shift F4"}, | ||
450 | |||
418 | // MC "Esc digit" specials. | 451 | // MC "Esc digit" specials. |
419 | // NOTE - The MC Esc variations might not be such a good idea, other programs want the Esc key for other things. | 452 | // NOTE - The MC Esc variations might not be such a good idea, other programs want the Esc key for other things. |
420 | // Notably seems that "Esc somekey" is used in place of "Alt somekey" AKA "Meta somekey" coz apparently some OSes swallow those. | 453 | // Notably seems that "Esc somekey" is used in place of "Alt somekey" AKA "Meta somekey" coz apparently some OSes swallow those. |