mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 13:37:12 +00:00
Support UTF-8 key bindings by expanding the key type from int to
uint64_t and converting UTF-8 to Unicode on input and the reverse on output. (This allows key bindings, there are still omissions - the largest being that the various prompts do not accept UTF-8.)
This commit is contained in:
38
input-keys.c
38
input-keys.c
@ -34,7 +34,7 @@
|
||||
void input_key_mouse(struct window_pane *, struct mouse_event *);
|
||||
|
||||
struct input_key_ent {
|
||||
int key;
|
||||
key_code key;
|
||||
const char *data;
|
||||
|
||||
int flags;
|
||||
@ -137,15 +137,16 @@ const struct input_key_ent input_keys[] = {
|
||||
|
||||
/* Translate a key code into an output key sequence. */
|
||||
void
|
||||
input_key(struct window_pane *wp, int key, struct mouse_event *m)
|
||||
input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
|
||||
{
|
||||
const struct input_key_ent *ike;
|
||||
u_int i;
|
||||
size_t dlen;
|
||||
char *out;
|
||||
u_char ch;
|
||||
const struct input_key_ent *ike;
|
||||
u_int i;
|
||||
size_t dlen;
|
||||
char *out;
|
||||
key_code justkey;
|
||||
struct utf8_data utf8data;
|
||||
|
||||
log_debug("writing key 0x%x (%s) to %%%u", key,
|
||||
log_debug("writing key 0x%llx (%s) to %%%u", key,
|
||||
key_string_lookup_key(key), wp->id);
|
||||
|
||||
/* If this is a mouse key, pass off to mouse function. */
|
||||
@ -157,13 +158,22 @@ input_key(struct window_pane *wp, int key, struct mouse_event *m)
|
||||
|
||||
/*
|
||||
* If this is a normal 7-bit key, just send it, with a leading escape
|
||||
* if necessary.
|
||||
* if necessary. If it is a UTF-8 key, split it and send it.
|
||||
*/
|
||||
if (key != KEYC_NONE && (key & ~KEYC_ESCAPE) < 0x100) {
|
||||
justkey = (key & ~KEYC_ESCAPE);
|
||||
if (key != KEYC_NONE && justkey < 0x7f) {
|
||||
if (key & KEYC_ESCAPE)
|
||||
bufferevent_write(wp->event, "\033", 1);
|
||||
ch = key & ~KEYC_ESCAPE;
|
||||
bufferevent_write(wp->event, &ch, 1);
|
||||
utf8data.data[0] = justkey;
|
||||
bufferevent_write(wp->event, &utf8data.data[0], 1);
|
||||
return;
|
||||
}
|
||||
if (key != KEYC_NONE && justkey > 0x7f && justkey < KEYC_BASE) {
|
||||
if (utf8_split(justkey, &utf8data) != 0)
|
||||
return;
|
||||
if (key & KEYC_ESCAPE)
|
||||
bufferevent_write(wp->event, "\033", 1);
|
||||
bufferevent_write(wp->event, utf8data.data, utf8data.size);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -196,11 +206,11 @@ input_key(struct window_pane *wp, int key, struct mouse_event *m)
|
||||
break;
|
||||
}
|
||||
if (i == nitems(input_keys)) {
|
||||
log_debug("key 0x%x missing", key);
|
||||
log_debug("key 0x%llx missing", key);
|
||||
return;
|
||||
}
|
||||
dlen = strlen(ike->data);
|
||||
log_debug("found key 0x%x: \"%s\"", key, ike->data);
|
||||
log_debug("found key 0x%llx: \"%s\"", key, ike->data);
|
||||
|
||||
/* Prefix a \033 for escape. */
|
||||
if (key & KEYC_ESCAPE)
|
||||
|
Reference in New Issue
Block a user