summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/input-keys.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-03-01 12:02:08 +0000
committernicm <nicm@openbsd.org>2016-03-01 12:02:08 +0000
commitf5015ed68bd7214ea853a6d82b6b9325205c79bb (patch)
tree35e70123f23bcbb5438047bfe68e5b7e2dc54dd6 /usr.bin/tmux/input-keys.c
parentFix break-pane synopsis and some other tmux.1 bits. (diff)
downloadwireguard-openbsd-f5015ed68bd7214ea853a6d82b6b9325205c79bb.tar.xz
wireguard-openbsd-f5015ed68bd7214ea853a6d82b6b9325205c79bb.zip
Use system wcwidth() instead of carrying around UTF-8 width tables.
Diffstat (limited to 'usr.bin/tmux/input-keys.c')
-rw-r--r--usr.bin/tmux/input-keys.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c
index f94ac7dc1f7..854be5ad18d 100644
--- a/usr.bin/tmux/input-keys.c
+++ b/usr.bin/tmux/input-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input-keys.c,v 1.53 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: input-keys.c,v 1.54 2016/03/01 12:02:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -135,6 +135,19 @@ const struct input_key_ent input_keys[] = {
{ KEYC_KP_PERIOD, ".", 0 },
};
+/* Split a character into two UTF-8 bytes. */
+static size_t
+input_split2(u_int c, u_char *dst)
+{
+ if (c > 0x7f) {
+ dst[0] = (c >> 6) | 0xc0;
+ dst[1] = (c & 0x3f) | 0x80;
+ return (2);
+ }
+ dst[0] = c;
+ return (1);
+}
+
/* Translate a key code into an output key sequence. */
void
input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
@@ -251,9 +264,9 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
m->sgr_b, x + 1, y + 1, m->sgr_type);
} else if (wp->screen->mode & MODE_MOUSE_UTF8) {
len = xsnprintf(buf, sizeof buf, "\033[M");
- len += utf8_split2(m->b + 32, &buf[len]);
- len += utf8_split2(x + 33, &buf[len]);
- len += utf8_split2(y + 33, &buf[len]);
+ len += input_split2(m->b + 32, &buf[len]);
+ len += input_split2(x + 33, &buf[len]);
+ len += input_split2(y + 33, &buf[len]);
} else {
if (m->b > 223)
return;