version 1.19, 2016/10/03 22:52:11 |
version 1.20, 2017/01/25 14:24:54 |
|
|
const char *template; |
const char *template; |
}; |
}; |
|
|
static const struct xterm_keys_entry xterm_keys_table[] = { |
static const struct xterm_keys_entry xterm_keys_standard[] = { |
|
{ KEYC_HOME, "\033[H" }, |
|
{ KEYC_END, "\033[F" }, |
|
}; |
|
|
|
static const struct xterm_keys_entry xterm_keys_cursor[] = { |
|
{ KEYC_HOME, "\033OH" }, |
|
{ KEYC_END, "\033OF" }, |
|
}; |
|
|
|
static const struct xterm_keys_entry xterm_keys_modified[] = { |
{ KEYC_F1, "\033[1;_P" }, |
{ KEYC_F1, "\033[1;_P" }, |
{ KEYC_F1, "\033O1;_P" }, |
{ KEYC_F1, "\033O1;_P" }, |
{ KEYC_F1, "\033O_P" }, |
{ KEYC_F1, "\033O_P" }, |
|
|
int matched; |
int matched; |
key_code modifiers; |
key_code modifiers; |
|
|
for (i = 0; i < nitems(xterm_keys_table); i++) { |
for (i = 0; i < nitems(xterm_keys_modified); i++) { |
entry = &xterm_keys_table[i]; |
entry = &xterm_keys_modified[i]; |
|
|
matched = xterm_keys_match(entry->template, buf, len, size, |
matched = xterm_keys_match(entry->template, buf, len, size, |
&modifiers); |
&modifiers); |
|
|
|
|
/* Lookup a key number from the table. */ |
/* Lookup a key number from the table. */ |
char * |
char * |
xterm_keys_lookup(key_code key) |
xterm_keys_lookup(key_code key, int mode) |
{ |
{ |
const struct xterm_keys_entry *entry; |
const struct xterm_keys_entry *table, *entry; |
u_int i; |
u_int items, i; |
key_code modifiers; |
key_code modifiers; |
char *out; |
char *out; |
|
|
|
|
* If the key has no modifiers, return NULL and let it fall through to |
* If the key has no modifiers, return NULL and let it fall through to |
* the normal lookup. |
* the normal lookup. |
*/ |
*/ |
if (modifiers == 1) |
if (modifiers != 1) { |
return (NULL); |
table = xterm_keys_modified; |
|
items = nitems(xterm_keys_modified); |
|
} else { |
|
if (mode & MODE_KCURSOR) { |
|
table = xterm_keys_cursor; |
|
items = nitems(xterm_keys_cursor); |
|
} else { |
|
table = xterm_keys_standard; |
|
items = nitems(xterm_keys_standard); |
|
} |
|
} |
|
|
/* Otherwise, find the key in the table. */ |
/* Otherwise, find the key in the table. */ |
key &= ~(KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL); |
key &= ~(KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL); |
for (i = 0; i < nitems(xterm_keys_table); i++) { |
for (i = 0; i < items; i++) { |
entry = &xterm_keys_table[i]; |
entry = &table[i]; |
if (key == entry->key) |
if (key == entry->key) |
break; |
break; |
} |
} |
if (i == nitems(xterm_keys_table)) |
if (i == items) |
return (NULL); |
return (NULL); |
|
|
/* Copy the template and replace the modifier. */ |
/* Copy the template and replace the modifier. */ |
out = xstrdup(entry->template); |
out = xstrdup(entry->template); |
out[strcspn(out, "_")] = '0' + modifiers; |
if (modifiers != 1) |
|
out[strcspn(out, "_")] = '0' + modifiers; |
return (out); |
return (out); |
} |
} |