tweaks: fold translation of all modified keypad keystrokes together

The escape-sequence codes for the different keypad keys are simply
the relevant ASCII code plus 0x40, so they are easy to translate.

Also, do not accept keypad keys with multiple modifiers (Shift+Alt,
Shift+Ctrl, Alt+Ctrl, Shift+Alt+Ctrl) -- report "Unknown sequence"
for those.
master
Benno Schulenberg 2020-07-10 19:47:28 +02:00
parent 476c838753
commit 2e4d78a714
1 changed files with 12 additions and 21 deletions

View File

@ -369,22 +369,19 @@ int convert_sequence(const int *seq, size_t length, int *consumed)
}
break;
case '2': /* Shift */
case '4': /* Shift+Alt */
case '6': /* Shift+Ctrl */
if (length > 2) {
*consumed = 3;
/* Allow typing digits on the numeric keypad without
* engaging NumLock. Esc O 2 p == Shift-0, .... */
return (seq[2] - 0x40);
}
break;
case '3': /* Alt */
case '4': /* Shift+Alt */
case '5': /* Ctrl */
case '6': /* Shift+Ctrl */
case '7': /* Alt+Ctrl */
case '8': /* Shift+Alt+Ctrl */
if (length > 2) {
*consumed = 3;
switch (seq[2]) {
/* Do not accept multiple modifiers. */
if (seq[1] == '4' || seq[1] > '5')
return FOREIGN_SEQUENCE;
#ifndef NANO_TINY
switch (seq[2]) {
case 'A': /* Esc O 5 A == Ctrl-Up on Haiku. */
return CONTROL_UP;
case 'B': /* Esc O 5 B == Ctrl-Down on Haiku. */
@ -393,18 +390,12 @@ int convert_sequence(const int *seq, size_t length, int *consumed)
return CONTROL_RIGHT;
case 'D': /* Esc O 5 D == Ctrl-Left on Haiku. */
return CONTROL_LEFT;
#endif
case 'M': /* Esc O . M == modified Enter on keypad. */
return KEY_ENTER;
case 'j': /* Esc O . j == modified '*' on keypad. */
return '*';
case 'k': /* Esc O . k == modified '+' on keypad. */
return '+';
case 'm': /* Esc O . m == modified '-' on keypad. */
return '-';
case 'o': /* Esc O . o == modified '/' on keypad. */
return '/';
}
#endif
/* Translate Shift+digit on the keypad to the digit
* (Esc O 2 p == Shift-0, ...), modifier+operator to
* the operator, and modifier+Enter to CR. */
return (seq[2] - 0x40);
}
break;
case 'A': /* Esc O A == Up on VT100/VT320. */