tweaks: split a function into two, one for "Esc O" and one for "Esc ["
Этот коммит содержится в:
родитель
2c8c061e67
Коммит
c14e77ce9e
32
src/winio.c
32
src/winio.c
@ -328,15 +328,9 @@ int arrow_from_ABCD(int letter)
|
|||||||
return (letter == 'D' ? KEY_LEFT : KEY_RIGHT);
|
return (letter == 'D' ? KEY_LEFT : KEY_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate escape sequences, most of which correspond to extended
|
/* Translate a sequence that began with "Esc O" to its corresponding key code. */
|
||||||
* keypad values, into their corresponding key values. These sequences
|
int convert_SS3_sequence(const int *seq, size_t length, int *consumed)
|
||||||
* are generated when the keypad doesn't support the needed keys.
|
|
||||||
* Assume that Escape has already been read in. */
|
|
||||||
int convert_sequence(int first, const int *seq, size_t length, int *consumed)
|
|
||||||
{
|
{
|
||||||
*consumed = 1;
|
|
||||||
|
|
||||||
if (first == 'O') {
|
|
||||||
switch (seq[0]) {
|
switch (seq[0]) {
|
||||||
case '1':
|
case '1':
|
||||||
if (length > 3 && seq[1] == ';') {
|
if (length > 3 && seq[1] == ';') {
|
||||||
@ -464,7 +458,13 @@ int convert_sequence(int first, const int *seq, size_t length, int *consumed)
|
|||||||
case 'y': /* Esc O y == PageUp (9) on the same. */
|
case 'y': /* Esc O y == PageUp (9) on the same. */
|
||||||
return KEY_PPAGE;
|
return KEY_PPAGE;
|
||||||
}
|
}
|
||||||
} else if (first == '[') {
|
|
||||||
|
return FOREIGN_SEQUENCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Translate a sequence that began with "Esc [" to its corresponding key code. */
|
||||||
|
int convert_CSI_sequence(const int *seq, size_t length, int *consumed)
|
||||||
|
{
|
||||||
if (seq[0] < '9')
|
if (seq[0] < '9')
|
||||||
*consumed = 2;
|
*consumed = 2;
|
||||||
switch (seq[0]) {
|
switch (seq[0]) {
|
||||||
@ -806,7 +806,6 @@ int convert_sequence(int first, const int *seq, size_t length, int *consumed)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return FOREIGN_SEQUENCE;
|
return FOREIGN_SEQUENCE;
|
||||||
}
|
}
|
||||||
@ -814,16 +813,23 @@ int convert_sequence(int first, const int *seq, size_t length, int *consumed)
|
|||||||
/* Interpret the escape sequence in the keystroke buffer, the first
|
/* Interpret the escape sequence in the keystroke buffer, the first
|
||||||
* character of which is kbinput. Assume that the keystroke buffer
|
* character of which is kbinput. Assume that the keystroke buffer
|
||||||
* isn't empty, and that the initial escape has already been read in. */
|
* isn't empty, and that the initial escape has already been read in. */
|
||||||
int parse_escape_sequence(int firstbyte)
|
int parse_escape_sequence(int starter)
|
||||||
{
|
{
|
||||||
int *sequence, length, consumed, keycode;
|
int *sequence, length;
|
||||||
|
int consumed = 1;
|
||||||
|
int keycode = 0;
|
||||||
|
|
||||||
/* Grab at most five integers (the longest possible escape sequence
|
/* Grab at most five integers (the longest possible escape sequence
|
||||||
* minus its first element) from the keybuffer. */
|
* minus its first element) from the keybuffer. */
|
||||||
length = (key_buffer_len < 5 ? key_buffer_len : 5);
|
length = (key_buffer_len < 5 ? key_buffer_len : 5);
|
||||||
sequence = get_input(NULL, length);
|
sequence = get_input(NULL, length);
|
||||||
|
|
||||||
keycode = convert_sequence(firstbyte, sequence, length, &consumed);
|
if (starter == 'O')
|
||||||
|
keycode = convert_SS3_sequence(sequence, length, &consumed);
|
||||||
|
else if (starter == '[')
|
||||||
|
keycode = convert_CSI_sequence(sequence, length, &consumed);
|
||||||
|
else
|
||||||
|
die("Bad sequence starter -- please report a bug\n");
|
||||||
|
|
||||||
/* If not all grabbed integers were consumed, put the leftovers back. */
|
/* If not all grabbed integers were consumed, put the leftovers back. */
|
||||||
for (int i = length - 1; i >= consumed; i--)
|
for (int i = length - 1; i >= consumed; i--)
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user