diff options
author | Thomas Adam <thomas@xteddy.org> | 2015-11-12 12:01:17 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2015-11-12 12:01:17 +0000 |
commit | 5f483499f3a7b98da9ac67cd62ed91034a5949ed (patch) | |
tree | de84187f104010233d96acc68bb9cc91d173c243 | |
parent | 333da3b64b4ce8c0343f082c3923473205ab2b27 (diff) | |
parent | 0cc812ae342d1a71c0337db8ffb4d7701668cb38 (diff) |
Merge branch 'obsd-master'
-rw-r--r-- | cmd-bind-key.c | 7 | ||||
-rw-r--r-- | cmd-choose-buffer.c | 4 | ||||
-rw-r--r-- | cmd-list-buffers.c | 2 | ||||
-rw-r--r-- | cmd-list-keys.c | 13 | ||||
-rw-r--r-- | cmd-load-buffer.c | 7 | ||||
-rw-r--r-- | cmd-queue.c | 19 | ||||
-rw-r--r-- | cmd-send-keys.c | 3 | ||||
-rw-r--r-- | cmd-set-option.c | 2 | ||||
-rw-r--r-- | cmd-unbind-key.c | 9 | ||||
-rw-r--r-- | format.c | 7 | ||||
-rw-r--r-- | input-keys.c | 38 | ||||
-rw-r--r-- | input.c | 5 | ||||
-rw-r--r-- | key-bindings.c | 10 | ||||
-rw-r--r-- | key-string.c | 63 | ||||
-rw-r--r-- | mode-key.c | 16 | ||||
-rw-r--r-- | options-table.c | 10 | ||||
-rw-r--r-- | paste.c | 7 | ||||
-rw-r--r-- | screen-write.c | 35 | ||||
-rw-r--r-- | server-client.c | 42 | ||||
-rw-r--r-- | status.c | 66 | ||||
-rw-r--r-- | tmux.1 | 41 | ||||
-rw-r--r-- | tmux.c | 44 | ||||
-rw-r--r-- | tmux.h | 117 | ||||
-rw-r--r-- | tty-keys.c | 62 | ||||
-rw-r--r-- | utf8.c | 78 | ||||
-rw-r--r-- | window-choose.c | 28 | ||||
-rw-r--r-- | window-clock.c | 5 | ||||
-rw-r--r-- | window-copy.c | 30 | ||||
-rw-r--r-- | window.c | 2 | ||||
-rw-r--r-- | xterm-keys.c | 21 |
30 files changed, 452 insertions, 341 deletions
diff --git a/cmd-bind-key.c b/cmd-bind-key.c index fda39efc..1867e814 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -29,7 +29,8 @@ enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, int); +enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, + key_code); const struct cmd_entry cmd_bind_key_entry = { "bind-key", "bind", @@ -45,7 +46,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) struct args *args = self->args; char *cause; struct cmd_list *cmdlist; - int key; + key_code key; const char *tablename; if (args_has(args, 't')) { @@ -89,7 +90,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) } enum cmd_retval -cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key) +cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) { struct args *args = self->args; const char *tablename; diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c index e790de6b..dbb20fc4 100644 --- a/cmd-choose-buffer.c +++ b/cmd-choose-buffer.c @@ -51,7 +51,6 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) char *action, *action_data; const char *template; u_int idx; - int utf8flag; if ((c = cmd_find_client(cmdq, NULL, 1)) == NULL) { cmdq_error(cmdq, "no client available"); @@ -63,7 +62,6 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); - utf8flag = options_get_number(wl->window->options, "utf8"); if (paste_get_top(NULL) == NULL) return (CMD_RETURN_NORMAL); @@ -83,7 +81,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) cdata->idx = idx; cdata->ft_template = xstrdup(template); - format_defaults_paste_buffer(cdata->ft, pb, utf8flag); + format_defaults_paste_buffer(cdata->ft, pb); xasprintf(&action_data, "%s", paste_buffer_name(pb)); cdata->command = cmd_template_replace(action, action_data, 1); diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index 37571b80..3a8a790a 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -55,7 +55,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq) pb = NULL; while ((pb = paste_walk(pb)) != NULL) { ft = format_create(); - format_defaults_paste_buffer(ft, pb, 0); + format_defaults_paste_buffer(ft, pb); line = format_expand(ft, template); cmdq_print(cmdq, "%s", line); diff --git a/cmd-list-keys.c b/cmd-list-keys.c index d26486bd..c76f9f47 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -57,6 +57,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) char tmp[BUFSIZ]; size_t used; int repeat, width, tablewidth, keywidth; + u_int i; if (self->entry == &cmd_list_commands_entry) return (cmd_list_keys_commands(self, cmdq)); @@ -83,8 +84,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) width = strlen(table->name); if (width > tablewidth) - tablewidth =width; - width = strlen(key); + tablewidth = width; + width = utf8_cstrwidth(key); if (width > keywidth) keywidth = width; } @@ -102,8 +103,12 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) r = "-r "; else r = " "; - used = xsnprintf(tmp, sizeof tmp, "%s-T %-*s %-*s ", r, - (int)tablewidth, table->name, (int)keywidth, key); + used = xsnprintf(tmp, sizeof tmp, "%s-T %-*s %s", r, + (int)tablewidth, table->name, key); + for (i = 0; i < keywidth - utf8_cstrwidth(key); i++) { + if (strlcat(tmp, " ", sizeof tmp) < sizeof tmp) + used++; + } if (used < sizeof tmp) { cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used); diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index 9352cbe5..40bea9b7 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -133,7 +133,7 @@ void cmd_load_buffer_callback(struct client *c, int closed, void *data) { const char *bufname = data; - char *pdata, *cause; + char *pdata, *cause, *saved; size_t psize; if (!closed) @@ -154,6 +154,11 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data) if (paste_set(pdata, psize, bufname, &cause) != 0) { /* No context so can't use server_client_msg_error. */ + if (~c->flags & CLIENT_UTF8) { + saved = cause; + cause = utf8_sanitize(saved); + free(saved); + } evbuffer_add_printf(c->stderr_data, "%s", cause); server_push_stderr(c); free(pdata); diff --git a/cmd-queue.c b/cmd-queue.c index ff8c69cb..5015981c 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -69,14 +69,21 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...) struct client *c = cmdq->client; struct window *w; va_list ap; + char *tmp, *msg; va_start(ap, fmt); if (c == NULL) /* nothing */; else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { - evbuffer_add_vprintf(c->stdout_data, fmt, ap); - + if (~c->flags & CLIENT_UTF8) { + vasprintf(&tmp, fmt, ap); + msg = utf8_sanitize(tmp); + free(tmp); + evbuffer_add(c->stdout_data, msg, strlen(msg)); + free(msg); + } else + evbuffer_add_vprintf(c->stdout_data, fmt, ap); evbuffer_add(c->stdout_data, "\n", 1); server_push_stdout(c); } else { @@ -101,6 +108,7 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) va_list ap; char *msg; size_t msglen; + char *tmp; va_start(ap, fmt); msglen = xvasprintf(&msg, fmt, ap); @@ -109,9 +117,14 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) if (c == NULL) cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg); else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { + if (~c->flags & CLIENT_UTF8) { + tmp = msg; + msg = utf8_sanitize(tmp); + free(tmp); + msglen = strlen(msg); + } evbuffer_add(c->stderr_data, msg, msglen); evbuffer_add(c->stderr_data, "\n", 1); - server_push_stderr(c); c->retval = 1; } else { diff --git a/cmd-send-keys.c b/cmd-send-keys.c index dd796d60..73a308ae 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -53,7 +53,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) struct window_pane *wp; struct session *s; const u_char *str; - int i, key; + int i; + key_code key; if (args_has(args, 'M')) { wp = cmd_mouse_pane(m, &s, NULL); diff --git a/cmd-set-option.c b/cmd-set-option.c index 6762e6ad..c5a77b45 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -394,7 +394,7 @@ cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { - int key; + key_code key; if ((key = key_string_lookup_string(value)) == KEYC_NONE) { cmdq_error(cmdq, "bad key: %s", value); diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index 493f6dde..cec538c0 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -26,8 +26,9 @@ * Unbind key from command. */ -enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, int); +enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); +enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, + key_code); const struct cmd_entry cmd_unbind_key_entry = { "unbind-key", "unbind", @@ -41,7 +42,7 @@ enum cmd_retval cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; - int key; + key_code key; const char *tablename; if (!args_has(args, 'a')) { @@ -95,7 +96,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) } enum cmd_retval -cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key) +cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) { struct args *args = self->args; const char *tablename; @@ -1156,16 +1156,13 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) !!(wp->base.mode & MODE_MOUSE_STANDARD)); format_add(ft, "mouse_button_flag", "%d", !!(wp->base.mode & MODE_MOUSE_BUTTON)); - format_add(ft, "mouse_utf8_flag", "%d", - !!(wp->base.mode & MODE_MOUSE_UTF8)); format_add_cb(ft, "pane_tabs", format_cb_pane_tabs); } /* Set default format keys for paste buffer. */ void -format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb, - int utf8flag) +format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb) { size_t bufsize; char *s; @@ -1174,7 +1171,7 @@ format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb, format_add(ft, "buffer_size", "%zu", bufsize); format_add(ft, "buffer_name", "%s", paste_buffer_name(pb)); - s = paste_make_sample(pb, utf8flag); + s = paste_make_sample(pb); format_add(ft, "buffer_sample", "%s", s); free(s); } diff --git a/input-keys.c b/input-keys.c index f629dd5b..160d58da 100644 --- a/input-keys.c +++ b/input-keys.c @@ -33,7 +33,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; @@ -136,15 +136,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. */ @@ -156,13 +157,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; } @@ -195,11 +205,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) @@ -1921,11 +1921,6 @@ input_exit_rename(struct input_ctx *ictx) int input_utf8_open(struct input_ctx *ictx) { - if (!options_get_number(ictx->wp->window->options, "utf8")) { - /* Print, and do not switch state. */ - input_print(ictx); - return (-1); - } log_debug("%s", __func__); utf8_open(&ictx->utf8data, ictx->ch); diff --git a/key-bindings.c b/key-bindings.c index 83b94ac1..47a7d867 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -37,7 +37,11 @@ key_table_cmp(struct key_table *e1, struct key_table *e2) int key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2) { - return (bd1->key - bd2->key); + if (bd1->key < bd2->key) + return (-1); + if (bd1->key > bd2->key) + return (1); + return (0); } struct key_table * @@ -80,7 +84,7 @@ key_bindings_unref_table(struct key_table *table) } void -key_bindings_add(const char *name, int key, int can_repeat, +key_bindings_add(const char *name, key_code key, int can_repeat, struct cmd_list *cmdlist) { struct key_table *table; @@ -105,7 +109,7 @@ key_bindings_add(const char *name, int key, int can_repeat, } void -key_bindings_remove(const char *name, int key) +key_bindings_remove(const char *name, key_code key) { struct key_table *table; struct key_binding bd_find, *bd; diff --git a/key-string.c b/key-string.c index 88cd2a32..4285e129 100644 --- a/key-string.c +++ b/key-string.c @@ -22,12 +22,12 @@ #include "tmux.h" -int key_string_search_table(const char *); -int key_string_get_modifiers(const char **); +key_code key_string_search_table(const char *); +key_code key_string_get_modifiers(const char **); const struct { const char *string; - int key; + key_code key; } key_string_table[] = { /* Function keys. */ { "F1", KEYC_F1 }, @@ -98,7 +98,7 @@ const struct { }; /* Find key string in table. */ -int +key_code key_string_search_table(const char *string) { u_int i; @@ -111,10 +111,10 @@ key_string_search_table(const char *string) } /* Find modifiers. */ -int +key_code key_string_get_modifiers(const char **string) { - int modifiers; + key_code modifiers; modifiers = 0; while (((*string)[0] != '\0') && (*string)[1] == '-') { @@ -138,13 +138,16 @@ key_string_get_modifiers(const char **string) } /* Lookup a string and convert to a key value. */ -int +key_code key_string_lookup_string(const char *string) { static const char *other = "!#()+,-.0123456789:;<=>?'\r\t"; - int key, modifiers; + key_code key; u_short u; int size; + key_code modifiers; + struct utf8_data utf8data; + u_int i; /* Is this a hexadecimal value? */ if (string[0] == '0' && string[1] == 'x') { @@ -164,11 +167,21 @@ key_string_lookup_string(const char *string) return (KEYC_NONE); /* Is this a standard ASCII key? */ - if (string[1] == '\0') { - key = (u_char) string[0]; - if (key < 32 || key == 127 || key > 255) + if (string[1] == '\0' && (u_char)string[0] <= 127) { + key = (u_char)string[0]; + if (key < 32 || key == 127) return (KEYC_NONE); } else { + /* Try as a UTF-8 key. */ + if (utf8_open(&utf8data, (u_char)*string)) { + if (strlen(string) != utf8data.size) + return (KEYC_NONE); + for (i = 1; i < utf8data.size; i++) + utf8_append(&utf8data, (u_char)string[i]); + key = utf8_combine(&utf8data); + return (key | modifiers); + } + /* Otherwise look the key up in the table. */ key = key_string_search_table(string); if (key == KEYC_NONE) @@ -195,11 +208,12 @@ key_string_lookup_string(const char *string) /* Convert a key code into string format, with prefix if necessary. */ const char * -key_string_lookup_key(int key) +key_string_lookup_key(key_code key) { - static char out[24]; - char tmp[8]; - u_int i; + static char out[24]; + char tmp[8]; + u_int i; + struct utf8_data utf8data; *out = '\0'; @@ -237,23 +251,32 @@ key_string_lookup_key(int key) return (out); } + /* Is this a UTF-8 key? */ + if (key > 127 && key < KEYC_BASE) { + if (utf8_split(key, &utf8data) == 0) { + memcpy(out, utf8data.data, utf8data.size); + out[utf8data.size] = '\0'; + return (out); + } + } + /* Invalid keys are errors. */ if (key == 127 || key > 255) { - snprintf(out, sizeof out, "<INVALID#%04x>", key); + snprintf(out, sizeof out, "<INVALID#%llx>", key); return (out); } /* Check for standard or control key. */ - if (key >= 0 && key <= 32) { + if (key <= 32) { if (key == 0 || key > 26) - xsnprintf(tmp, sizeof tmp, "C-%c", 64 + key); + xsnprintf(tmp, sizeof tmp, "C-%c", (int)(64 + key)); else - xsnprintf(tmp, sizeof tmp, "C-%c", 96 + key); + xsnprintf(tmp, sizeof tmp, "C-%c", (int)(96 + key)); } else if (key >= 32 && key <= 126) { tmp[0] = key; tmp[1] = '\0'; } else if (key >= 128) - xsnprintf(tmp, sizeof tmp, "\\%o", key); + xsnprintf(tmp, sizeof tmp, "\\%llo", key); strlcat(out, tmp, sizeof out); return (out); @@ -40,7 +40,7 @@ /* Entry in the default mode key tables. */ struct mode_key_entry { - int key; + key_code key; /* * Editing mode for vi: 0 is edit mode, keys not in the table are @@ -523,9 +523,15 @@ RB_GENERATE(mode_key_tree, mode_key_binding, entry, mode_key_cmp); int mode_key_cmp(struct mode_key_binding *mbind1, struct mode_key_binding *mbind2) { - if (mbind1->mode != mbind2->mode) - return (mbind1->mode - mbind2->mode); - return (mbind1->key - mbind2->key); + if (mbind1->mode < mbind2->mode) + return (-1); + if (mbind1->mode > mbind2->mode) + return (1); + if (mbind1->key < mbind2->key) + return (-1); + if (mbind1->key > mbind2->key) + return (1); + return (0); } const char * @@ -588,7 +594,7 @@ mode_key_init(struct mode_key_data *mdata, struct mode_key_tree *mtree) } enum mode_key_cmd -mode_key_lookup(struct mode_key_data *mdata, int key, const char **arg) +mode_key_lookup(struct mode_key_data *mdata, key_code key, const char **arg) { struct mode_key_binding *mbind, mtmp; diff --git a/options-table.c b/options-table.c index 6a11d00f..d4a05aed 100644 --- a/options-table.c +++ b/options-table.c @@ -415,11 +415,6 @@ const struct options_table_entry session_options_table[] = { .default_str = "bg=green,fg=black" }, - { .name = "status-utf8", - .type = OPTIONS_TABLE_FLAG, - .default_num = 0 /* overridden in main() */ - }, - { .name = "update-environment", .type = OPTIONS_TABLE_STRING, .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID " @@ -623,11 +618,6 @@ const struct options_table_entry window_options_table[] = { .default_num = 0 }, - { .name = "utf8", - .type = OPTIONS_TABLE_FLAG, - .default_num = 0 /* overridden in main() */ - }, - { .name = "window-active-style", .type = OPTIONS_TABLE_STYLE, .default_str = "default" @@ -274,7 +274,7 @@ paste_set(char *data, size_t size, const char *name, char **cause) /* Convert start of buffer into a nice string. */ char * -paste_make_sample(struct paste_buffer *pb, int utf8flag) +paste_make_sample(struct paste_buffer *pb) { char *buf; size_t len, used; @@ -286,10 +286,7 @@ paste_make_sample(struct paste_buffer *pb, int utf8flag) len = width; buf = xreallocarray(NULL, len, 4 + 4); - if (utf8flag) - used = utf8_strvis(buf, pb->data, len, flags); - else - used = strvisx(buf, pb->data, len, flags); + used = utf8_strvis(buf, pb->data, len, flags); if (pb->size > width || used > width) strlcpy(buf + width, "...", 4); return (buf); diff --git a/screen-write.c b/screen-write.c index f80048b6..6286d21f 100644 --- a/screen-write.c +++ b/screen-write.c @@ -73,7 +73,7 @@ screen_write_putc(struct screen_write_ctx *ctx, struct grid_cell *gc, /* Calculate string length, with embedded formatting. */ size_t -screen_write_cstrlen(int utf8flag, const char *fmt, ...) +screen_write_cstrlen(const char *fmt, ...) { va_list ap; char *msg, *msg2, *ptr, *ptr2; @@ -98,7 +98,7 @@ screen_write_cstrlen(int utf8flag, const char *fmt, ...) } *ptr2 = '\0'; - size = screen_write_strlen(utf8flag, "%s", msg2); + size = screen_write_strlen("%s", msg2); free(msg); free(msg2); @@ -108,7 +108,7 @@ screen_write_cstrlen(int utf8flag, const char *fmt, ...) /* Calculate string length. */ size_t -screen_write_strlen(int utf8flag, const char *fmt, ...) +screen_write_strlen(const char *fmt, ...) { va_list ap; char *msg; @@ -122,7 +122,7 @@ screen_write_strlen(int utf8flag, const char *fmt, ...) ptr = msg; while (*ptr != '\0') { - if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { ptr++; left = strlen(ptr); @@ -134,7 +134,8 @@ screen_write_strlen(int utf8flag, const char *fmt, ...) size += utf8data.width; } else { - size++; + if (*ptr > 0x1f && *ptr < 0x7f) + size++; ptr++; } } @@ -151,25 +152,25 @@ screen_write_puts(struct screen_write_ctx *ctx, struct grid_cell *gc, va_list ap; va_start(ap, fmt); - screen_write_vnputs(ctx, -1, gc, 0, fmt, ap); + screen_write_vnputs(ctx, -1, gc, fmt, ap); va_end(ap); } /* Write string with length limit (-1 for unlimited). */ void screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen, - struct grid_cell *gc, int utf8flag, const char *fmt, ...) + struct grid_cell *gc, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - screen_write_vnputs(ctx, maxlen, gc, utf8flag, fmt, ap); + screen_write_vnputs(ctx, maxlen, gc, fmt, ap); va_end(ap); } void screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, - struct grid_cell *gc, int utf8flag, const char *fmt, va_list ap) + struct grid_cell *gc, const char *fmt, va_list ap) { char *msg; struct utf8_data utf8data; @@ -180,7 +181,7 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, ptr = msg; while (*ptr != '\0') { - if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { ptr++; left = strlen(ptr); @@ -208,7 +209,7 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, if (*ptr == '\001') gc->attr ^= GRID_ATTR_CHARSET; - else { + else if (*ptr > 0x1f && *ptr < 0x7f) { size++; screen_write_putc(ctx, gc, *ptr); } @@ -221,8 +222,8 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, /* Write string, similar to nputs, but with embedded formatting (#[]). */ void -screen_write_cnputs(struct screen_write_ctx *ctx, - ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...) +screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen, + struct grid_cell *gc, const char *fmt, ...) { struct grid_cell lgc; struct utf8_data utf8data; @@ -253,7 +254,7 @@ screen_write_cnputs(struct screen_write_ctx *ctx, continue; } - if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) { + if (*ptr > 0x7f && utf8_open(&utf8data, *ptr)) { ptr++; left = strlen(ptr); @@ -279,8 +280,10 @@ screen_write_cnputs(struct screen_write_ctx *ctx, if (maxlen > 0 && size + 1 > (size_t) maxlen) break; - size++; - screen_write_putc(ctx, &lgc, *ptr); + if (*ptr > 0x1f && *ptr < 0x7f) { + size++; + screen_write_putc(ctx, &lgc, *ptr); + } ptr++; } } diff --git a/server-client.c b/server-client.c index 0c6ed9d0..3e900afa 100644 --- a/server-client.c +++ b/server-client.c @@ -30,22 +30,22 @@ #include "tmux.h" -void server_client_key_table(struct client *, const char *); -void server_client_free(int, short, void *); -void server_client_check_focus(struct window_pane *); -void server_client_check_resize(struct window_pane *); -int server_client_check_mouse(struct client *); -void server_client_repeat_timer(int, short, void *); -void server_client_check_exit(struct client *); -void server_client_check_redraw(struct client *); -void server_client_set_title(struct client *); -void server_client_reset_state(struct client *); -int server_client_assume_paste(struct session *); - -void server_client_dispatch(struct imsg *, void *); -void server_client_dispatch_command(struct client *, struct imsg *); -void server_client_dispatch_identify(struct client *, struct imsg *); -void server_client_dispatch_shell(struct client *); +void server_client_key_table(struct client *, const char *); +void server_client_free(int, short, void *); +void server_client_check_focus(struct window_pane *); +void server_client_check_resize(struct window_pane *); +key_code server_client_check_mouse(struct client *); +void server_client_repeat_timer(int, short, void *); +void server_client_check_exit(struct client *); +void server_client_check_redraw(struct client *); +void server_client_set_title(struct client *); +void server_client_reset_state(struct client *); +int server_client_assume_paste(struct session *); + +void server_client_dispatch(struct imsg *, void *); +void server_client_dispatch_command(struct client *, struct imsg *); +void server_client_dispatch_identify(struct client *, struct imsg *); +void server_client_dispatch_shell(struct client *); /* Check if this client is inside this server. */ int @@ -255,7 +255,7 @@ server_client_free(unused int fd, unused short events, void *arg) } /* Check for mouse keys. */ -int +key_code server_client_check_mouse(struct client *c) { struct session *s = c->session; @@ -265,7 +265,7 @@ server_client_check_mouse(struct client *c) enum { NOTYPE, DOWN, UP, DRAG, WHEEL } type = NOTYPE; enum { NOWHERE, PANE, STATUS, BORDER } where = NOWHERE; u_int x, y, b; - int key; + key_code key; log_debug("mouse %02x at %u,%u (last %u,%u) (%d)", m->b, m->x, m->y, m->lx, m->ly, c->tty.mouse_drag_flag); @@ -499,7 +499,7 @@ server_client_assume_paste(struct session *s) /* Handle data key input from client. */ void -server_client_handle_key(struct client *c, int key) +server_client_handle_key(struct client *c, key_code key) { struct mouse_event *m = &c->tty.mouse; struct session *s = c->session; @@ -633,8 +633,8 @@ retry: * No match, but in the root table. Prefix switches to the prefix table * and everything else is passed through. */ - if (key == options_get_number(s->options, "prefix") || - key == options_get_number(s->options, "prefix2")) { + if (key == (key_code)options_get_number(s->options, "prefix") || + key == (key_code)options_get_number(s->options, "prefix2")) { server_client_key_table(c, "prefix"); server_status_client(c); return; @@ -29,10 +29,10 @@ #include "tmux.h" -char *status_redraw_get_left(st |