mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-30 12:04:38 +01:00
Handle partial xterm function key sequences.
This commit is contained in:
parent
2182e1badc
commit
29a5931c6a
2
tmux.h
2
tmux.h
@ -1647,7 +1647,7 @@ void input_mouse(struct window_pane *, struct mouse_event *);
|
|||||||
|
|
||||||
/* xterm-keys.c */
|
/* xterm-keys.c */
|
||||||
char *xterm_keys_lookup(int);
|
char *xterm_keys_lookup(int);
|
||||||
int xterm_keys_find(const char *, size_t, size_t *);
|
int xterm_keys_find(const char *, size_t, size_t *, int *);
|
||||||
|
|
||||||
/* colour.c */
|
/* colour.c */
|
||||||
void colour_set_fg(struct grid_cell *, int);
|
void colour_set_fg(struct grid_cell *, int);
|
||||||
|
@ -472,12 +472,15 @@ tty_keys_next(struct tty *tty)
|
|||||||
goto partial_key;
|
goto partial_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Not found. Try to parse a key with an xterm-style modifier. */
|
/* Not found. Try to parse a key with an xterm-style modifier. */
|
||||||
key = xterm_keys_find(buf, len, &size);
|
switch (xterm_keys_find(buf, len, &size, &key)) {
|
||||||
if (key != KEYC_NONE) {
|
case 0: /* found */
|
||||||
evbuffer_drain(tty->event->input, size);
|
evbuffer_drain(tty->event->input, size);
|
||||||
goto handle_key;
|
goto handle_key;
|
||||||
|
case -1: /* not found */
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
goto partial_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the escape. */
|
/* Skip the escape. */
|
||||||
|
35
xterm-keys.c
35
xterm-keys.c
@ -85,22 +85,28 @@ struct xterm_keys_entry xterm_keys_table[] = {
|
|||||||
{ KEYC_DC, "\033[3;_~" },
|
{ KEYC_DC, "\033[3;_~" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Match key against buffer, treating _ as a wildcard. */
|
/*
|
||||||
|
* Match key against buffer, treating _ as a wildcard. Return -1 for no match,
|
||||||
|
* 0 for match, 1 if the end of the buffer is reached (need more data).
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
xterm_keys_match(const char *template, const char *buf, size_t len)
|
xterm_keys_match(const char *template, const char *buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
if (len == 0 || len < strlen(template))
|
if (len == 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
do {
|
do {
|
||||||
if (*template != '_' && buf[pos] != *template)
|
if (*template != '_' && buf[pos] != *template)
|
||||||
return (0);
|
return (-1);
|
||||||
} while (pos++ != len && *++template != '\0');
|
} while (pos++ != len && *++template != '\0');
|
||||||
|
|
||||||
|
if (*template != '\0') /* partial */
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find modifiers based on template. */
|
/* Find modifiers based on template. */
|
||||||
@ -131,22 +137,29 @@ xterm_keys_modifiers(const char *template, const char *buf, size_t len)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup key from buffer against table. */
|
/*
|
||||||
|
* Lookup key from a buffer against the table. Returns 0 for found (and the
|
||||||
|
* key), -1 for not found, 1 for partial match.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
xterm_keys_find(const char *buf, size_t len, size_t *size)
|
xterm_keys_find(const char *buf, size_t len, size_t *size, int *key)
|
||||||
{
|
{
|
||||||
struct xterm_keys_entry *entry;
|
struct xterm_keys_entry *entry;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
for (i = 0; i < nitems(xterm_keys_table); i++) {
|
for (i = 0; i < nitems(xterm_keys_table); i++) {
|
||||||
entry = &xterm_keys_table[i];
|
entry = &xterm_keys_table[i];
|
||||||
if (xterm_keys_match(entry->template, buf, len))
|
switch (xterm_keys_match(entry->template, buf, len)) {
|
||||||
break;
|
case 0:
|
||||||
}
|
|
||||||
if (i == nitems(xterm_keys_table))
|
|
||||||
return (KEYC_NONE);
|
|
||||||
*size = strlen(entry->template);
|
*size = strlen(entry->template);
|
||||||
return (entry->key | xterm_keys_modifiers(entry->template, buf, len));
|
*key = entry->key;
|
||||||
|
*key |= xterm_keys_modifiers(entry->template, buf, len);
|
||||||
|
return (0);
|
||||||
|
case 1:
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup a key number from the table. */
|
/* Lookup a key number from the table. */
|
||||||
|
Loading…
Reference in New Issue
Block a user