=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/status.c,v retrieving revision 1.154 retrieving revision 1.155 diff -c -r1.154 -r1.155 *** src/usr.bin/tmux/status.c 2016/10/12 13:03:27 1.154 --- src/usr.bin/tmux/status.c 2016/10/12 14:50:14 1.155 *************** *** 1,4 **** ! /* $OpenBSD: status.c,v 1.154 2016/10/12 13:03:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: status.c,v 1.155 2016/10/12 14:50:14 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 660,666 **** void *data, int flags) { struct format_tree *ft; - int keys; time_t t; char *tmp; --- 660,665 ---- *************** *** 685,697 **** c->prompt_hindex = 0; c->prompt_flags = flags; - keys = options_get_number(c->session->options, "status-keys"); - if (keys == MODEKEY_EMACS) - mode_key_init(&c->prompt_mdata, &mode_key_tree_emacs_edit); - else - mode_key_init(&c->prompt_mdata, &mode_key_tree_vi_edit); - c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_STATUS; --- 684,691 ---- c->prompt_hindex = 0; c->prompt_flags = flags; + c->prompt_mode = PROMPT_ENTRY; c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_STATUS; *************** *** 765,771 **** memcpy(&old_status, &c->status, sizeof old_status); screen_init(&c->status, c->tty.sx, 1, 0); ! if (c->prompt_mdata.mode == 1) style_apply(&gc, s->options, "message-command-style"); else style_apply(&gc, s->options, "message-style"); --- 759,765 ---- memcpy(&old_status, &c->status, sizeof old_status); screen_init(&c->status, c->tty.sx, 1, 0); ! if (c->prompt_mode == PROMPT_COMMAND) style_apply(&gc, s->options, "message-command-style"); else style_apply(&gc, s->options, "message-style"); *************** *** 854,859 **** --- 848,974 ---- return (*ud->data == ' '); } + /* + * Translate key from emacs to vi. Return 0 to drop key, 1 to process the key + * as an emacs key; return 2 to append to the buffer. + */ + static int + status_prompt_translate_key(struct client *c, key_code key, key_code *new_key) + { + if (c->prompt_mode == PROMPT_ENTRY) { + switch (key) { + case '\003': /* C-c */ + case '\010': /* C-h */ + case '\011': /* Tab */ + case '\025': /* C-u */ + case '\027': /* C-w */ + case '\n': + case '\r': + case KEYC_BSPACE: + case KEYC_DC: + case KEYC_DOWN: + case KEYC_END: + case KEYC_HOME: + case KEYC_LEFT: + case KEYC_RIGHT: + case KEYC_UP: + *new_key = key; + return (1); + case '\033': /* Escape */ + c->prompt_mode = PROMPT_COMMAND; + c->flags |= CLIENT_STATUS; + return (0); + } + *new_key = key; + return (2); + } + + switch (key) { + case 'A': + case 'I': + case 'C': + case 's': + case 'a': + c->prompt_mode = PROMPT_ENTRY; + c->flags |= CLIENT_STATUS; + break; /* switch mode and... */ + case 'S': + c->prompt_mode = PROMPT_ENTRY; + c->flags |= CLIENT_STATUS; + *new_key = '\025'; /* C-u */ + return (1); + case 'i': + case '\033': /* Escape */ + c->prompt_mode = PROMPT_ENTRY; + c->flags |= CLIENT_STATUS; + return (0); + } + + switch (key) { + case 'A': + case '$': + *new_key = KEYC_END; + return (1); + case 'I': + case '0': + case '^': + *new_key = KEYC_HOME; + return (1); + case 'C': + case 'D': + *new_key = '\013'; /* C-k */ + return (1); + case KEYC_BSPACE: + case 'X': + *new_key = KEYC_BSPACE; + return (1); + case 'b': + case 'B': + *new_key = 'b'|KEYC_ESCAPE; + return (1); + case 'd': + *new_key = '\025'; + return (1); + case 'e': + case 'E': + case 'w': + case 'W': + *new_key = 'f'|KEYC_ESCAPE; + return (1); + case 'p': + *new_key = '\031'; /* C-y */ + return (1); + case 's': + case KEYC_DC: + case 'x': + *new_key = KEYC_DC; + return (1); + case KEYC_DOWN: + case 'j': + *new_key = KEYC_DOWN; + return (1); + case KEYC_LEFT: + case 'h': + *new_key = KEYC_LEFT; + return (1); + case 'a': + case KEYC_RIGHT: + case 'l': + *new_key = KEYC_RIGHT; + return (1); + case KEYC_UP: + case 'k': + *new_key = KEYC_UP; + return (1); + case '\010' /* C-h */: + case '\003' /* C-c */: + case '\n': + case '\r': + return (1); + } + return (0); + } + /* Handle keys in prompt. */ int status_prompt_key(struct client *c, key_code key) *************** *** 865,870 **** --- 980,986 ---- u_char ch; size_t size, n, off, idx, bufsize, used; struct utf8_data tmp, *first, *last, *ud; + int keys; size = utf8_strlen(c->prompt_buffer); *************** *** 878,921 **** return (1); } ! switch (mode_key_lookup(&c->prompt_mdata, key)) { ! case MODEKEYEDIT_CURSORLEFT: if (c->prompt_index > 0) { c->prompt_index--; c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_SWITCHMODE: ! c->flags |= CLIENT_STATUS; ! break; ! case MODEKEYEDIT_SWITCHMODEAPPEND: ! c->flags |= CLIENT_STATUS; ! /* FALLTHROUGH */ ! case MODEKEYEDIT_CURSORRIGHT: if (c->prompt_index < size) { c->prompt_index++; c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_SWITCHMODEBEGINLINE: ! c->flags |= CLIENT_STATUS; ! /* FALLTHROUGH */ ! case MODEKEYEDIT_STARTOFLINE: if (c->prompt_index != 0) { c->prompt_index = 0; c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_SWITCHMODEAPPENDLINE: ! c->flags |= CLIENT_STATUS; ! /* FALLTHROUGH */ ! case MODEKEYEDIT_ENDOFLINE: if (c->prompt_index != size) { c->prompt_index = size; c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_COMPLETE: if (c->prompt_buffer[0].size == 0) break; --- 994,1042 ---- return (1); } ! keys = options_get_number(c->session->options, "status-keys"); ! if (keys == MODEKEY_VI) { ! switch (status_prompt_translate_key(c, key, &key)) { ! case 1: ! goto process_key; ! case 2: ! goto append_key; ! default: ! return (0); ! } ! } ! ! process_key: ! switch (key) { ! case KEYC_LEFT: ! case '\002': /* C-b */ if (c->prompt_index > 0) { c->prompt_index--; c->flags |= CLIENT_STATUS; } break; ! case KEYC_RIGHT: ! case '\006': /* C-f */ if (c->prompt_index < size) { c->prompt_index++; c->flags |= CLIENT_STATUS; } break; ! case KEYC_HOME: ! case '\001': /* C-a */ if (c->prompt_index != 0) { c->prompt_index = 0; c->flags |= CLIENT_STATUS; } break; ! case KEYC_END: ! case '\005': /* C-e */ if (c->prompt_index != size) { c->prompt_index = size; c->flags |= CLIENT_STATUS; } break; ! case '\011': /* Tab */ if (c->prompt_buffer[0].size == 0) break; *************** *** 974,980 **** c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_BACKSPACE: if (c->prompt_index != 0) { if (c->prompt_index == size) c->prompt_buffer[--c->prompt_index].size = 0; --- 1095,1102 ---- c->flags |= CLIENT_STATUS; break; ! case KEYC_BSPACE: ! case '\010': /* C-h */ if (c->prompt_index != 0) { if (c->prompt_index == size) c->prompt_buffer[--c->prompt_index].size = 0; *************** *** 988,995 **** c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_DELETE: ! case MODEKEYEDIT_SWITCHMODESUBSTITUTE: if (c->prompt_index != size) { memmove(c->prompt_buffer + c->prompt_index, c->prompt_buffer + c->prompt_index + 1, --- 1110,1117 ---- c->flags |= CLIENT_STATUS; } break; ! case KEYC_DC: ! case '\004': /* C-d */ if (c->prompt_index != size) { memmove(c->prompt_buffer + c->prompt_index, c->prompt_buffer + c->prompt_index + 1, *************** *** 998,1017 **** c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_DELETELINE: ! case MODEKEYEDIT_SWITCHMODESUBSTITUTELINE: c->prompt_buffer[0].size = 0; c->prompt_index = 0; c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_DELETETOENDOFLINE: ! case MODEKEYEDIT_SWITCHMODECHANGELINE: if (c->prompt_index < size) { c->prompt_buffer[c->prompt_index].size = 0; c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_DELETEWORD: ws = options_get_string(oo, "word-separators"); idx = c->prompt_index; --- 1120,1137 ---- c->flags |= CLIENT_STATUS; } break; ! case '\025': /* C-u */ c->prompt_buffer[0].size = 0; c->prompt_index = 0; c->flags |= CLIENT_STATUS; break; ! case '\013': /* C-k */ if (c->prompt_index < size) { c->prompt_buffer[c->prompt_index].size = 0; c->flags |= CLIENT_STATUS; } break; ! case '\027': /* C-w */ ws = options_get_string(oo, "word-separators"); idx = c->prompt_index; *************** *** 1042,1077 **** c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_NEXTSPACE: ! ws = " "; ! /* FALLTHROUGH */ ! case MODEKEYEDIT_NEXTWORD: ! if (ws == NULL) ! ws = options_get_string(oo, "word-separators"); - /* Find a separator. */ - while (c->prompt_index != size) { - idx = ++c->prompt_index; - if (status_prompt_in_list(ws, &c->prompt_buffer[idx])) - break; - } - - /* Find the word right after the separator. */ - while (c->prompt_index != size) { - idx = ++c->prompt_index; - if (!status_prompt_in_list(ws, &c->prompt_buffer[idx])) - break; - } - - c->flags |= CLIENT_STATUS; - break; - case MODEKEYEDIT_NEXTSPACEEND: - ws = " "; - /* FALLTHROUGH */ - case MODEKEYEDIT_NEXTWORDEND: - if (ws == NULL) - ws = options_get_string(oo, "word-separators"); - /* Find a word. */ while (c->prompt_index != size) { idx = ++c->prompt_index; --- 1162,1170 ---- c->flags |= CLIENT_STATUS; break; ! case 'f'|KEYC_ESCAPE: ! ws = options_get_string(oo, "word-separators"); /* Find a word. */ while (c->prompt_index != size) { idx = ++c->prompt_index; *************** *** 1093,1104 **** c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_PREVIOUSSPACE: ! ws = " "; ! /* FALLTHROUGH */ ! case MODEKEYEDIT_PREVIOUSWORD: ! if (ws == NULL) ! ws = options_get_string(oo, "word-separators"); /* Find a non-separator. */ while (c->prompt_index != 0) { --- 1186,1193 ---- c->flags |= CLIENT_STATUS; break; ! case 'b'|KEYC_ESCAPE: ! ws = options_get_string(oo, "word-separators"); /* Find a non-separator. */ while (c->prompt_index != 0) { *************** *** 1119,1125 **** c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_HISTORYUP: histstr = status_prompt_up_history(&c->prompt_hindex); if (histstr == NULL) break; --- 1208,1215 ---- c->flags |= CLIENT_STATUS; break; ! case KEYC_UP: ! case '\020': /* C-p */ histstr = status_prompt_up_history(&c->prompt_hindex); if (histstr == NULL) break; *************** *** 1128,1134 **** c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_HISTORYDOWN: histstr = status_prompt_down_history(&c->prompt_hindex); if (histstr == NULL) break; --- 1218,1225 ---- c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; ! case KEYC_DOWN: ! case '\016': /* C-n */ histstr = status_prompt_down_history(&c->prompt_hindex); if (histstr == NULL) break; *************** *** 1137,1143 **** c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_PASTE: if ((pb = paste_get_top(NULL)) == NULL) break; bufdata = paste_buffer_data(pb, &bufsize); --- 1228,1234 ---- c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; ! case '\031': /* C-y */ if ((pb = paste_get_top(NULL)) == NULL) break; bufdata = paste_buffer_data(pb, &bufsize); *************** *** 1170,1176 **** c->flags |= CLIENT_STATUS; break; ! case MODEKEYEDIT_TRANSPOSECHARS: idx = c->prompt_index; if (idx < size) idx++; --- 1261,1267 ---- c->flags |= CLIENT_STATUS; break; ! case '\024': /* C-t */ idx = c->prompt_index; if (idx < size) idx++; *************** *** 1183,1189 **** c->flags |= CLIENT_STATUS; } break; ! case MODEKEYEDIT_ENTER: s = utf8_tocstr(c->prompt_buffer); if (*s != '\0') status_prompt_add_history(s); --- 1274,1281 ---- c->flags |= CLIENT_STATUS; } break; ! case '\r': ! case '\n': s = utf8_tocstr(c->prompt_buffer); if (*s != '\0') status_prompt_add_history(s); *************** *** 1191,1204 **** status_prompt_clear(c); free(s); break; ! case MODEKEYEDIT_CANCEL: if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) status_prompt_clear(c); break; - case MODEKEY_OTHER: - break; - default: - return (0); } append_key: --- 1283,1293 ---- status_prompt_clear(c); free(s); break; ! case '\033': /* Escape */ ! case '\003': /* C-c */ if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) status_prompt_clear(c); break; } append_key: