keyboard: recognize four escape sequences produced by iTerm2
On iTerm2 on OS X, the Option+Arrow keys produce special sequences that start with two escapes. Catch these sequences and interpret them appropriately as WordLeft / WordRight / Home / End. Signed-off-by: Mike Scalora <mike@scalora.org> Signed-off-by: Thomas Rosenau <thomasr@fantasymail.de> Signed-off-by: Benno Schulenberg <bensberg@justemail.net>master
parent
da9ea91b37
commit
d851ccdd41
29
src/winio.c
29
src/winio.c
|
@ -330,6 +330,7 @@ int get_kbinput(WINDOW *win)
|
||||||
int parse_kbinput(WINDOW *win)
|
int parse_kbinput(WINDOW *win)
|
||||||
{
|
{
|
||||||
static int escapes = 0, byte_digits = 0;
|
static int escapes = 0, byte_digits = 0;
|
||||||
|
static bool double_esc = FALSE;
|
||||||
int *kbinput, retval = ERR;
|
int *kbinput, retval = ERR;
|
||||||
|
|
||||||
meta_key = FALSE;
|
meta_key = FALSE;
|
||||||
|
@ -390,7 +391,30 @@ int parse_kbinput(WINDOW *win)
|
||||||
retval = parse_escape_sequence(win, *kbinput);
|
retval = parse_escape_sequence(win, *kbinput);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (get_key_buffer_len() == 0) {
|
if (double_esc) {
|
||||||
|
/* An "ESC ESC [ X" sequence from Option+arrow. */
|
||||||
|
switch (*kbinput) {
|
||||||
|
case 'A':
|
||||||
|
retval = KEY_HOME;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
retval = KEY_END;
|
||||||
|
break;
|
||||||
|
#ifndef NANO_TINY
|
||||||
|
case 'C':
|
||||||
|
retval = controlright;
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
retval = controlleft;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
retval = ERR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
double_esc = FALSE;
|
||||||
|
escapes = 0;
|
||||||
|
} else if (get_key_buffer_len() == 0) {
|
||||||
if (('0' <= *kbinput && *kbinput <= '2' &&
|
if (('0' <= *kbinput && *kbinput <= '2' &&
|
||||||
byte_digits == 0) || ('0' <= *kbinput &&
|
byte_digits == 0) || ('0' <= *kbinput &&
|
||||||
*kbinput <= '9' && byte_digits > 0)) {
|
*kbinput <= '9' && byte_digits > 0)) {
|
||||||
|
@ -462,6 +486,9 @@ int parse_kbinput(WINDOW *win)
|
||||||
retval = *kbinput;
|
retval = *kbinput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (*kbinput=='[') {
|
||||||
|
/* This is an iTerm2 sequence: ^[ ^[ [ X. */
|
||||||
|
double_esc = TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* Two escapes followed by a non-escape, and
|
/* Two escapes followed by a non-escape, and
|
||||||
* there are other keystrokes waiting: combined
|
* there are other keystrokes waiting: combined
|
||||||
|
|
Loading…
Reference in New Issue