=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-list-keys.c,v retrieving revision 1.25 retrieving revision 1.26 diff -c -r1.25 -r1.26 *** src/usr.bin/tmux/cmd-list-keys.c 2014/10/20 23:27:14 1.25 --- src/usr.bin/tmux/cmd-list-keys.c 2015/04/20 15:34:56 1.26 *************** *** 1,4 **** ! /* $OpenBSD: cmd-list-keys.c,v 1.25 2014/10/20 23:27:14 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-list-keys.c,v 1.26 2015/04/20 15:34:56 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 33,40 **** const struct cmd_entry cmd_list_keys_entry = { "list-keys", "lsk", ! "t:", 0, 0, ! "[-t key-table]", 0, cmd_list_keys_exec }; --- 33,40 ---- const struct cmd_entry cmd_list_keys_entry = { "list-keys", "lsk", ! "t:T:", 0, 0, ! "[-t mode-table] [-T key-table]", 0, cmd_list_keys_exec }; *************** *** 51,61 **** cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct key_binding *bd; ! const char *key; ! char tmp[BUFSIZ], flags[8]; size_t used; ! int width, keywidth; if (self->entry == &cmd_list_commands_entry) return (cmd_list_keys_commands(self, cmdq)); --- 51,62 ---- cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; + struct key_table *table; struct key_binding *bd; ! const char *key, *tablename, *r; ! char tmp[BUFSIZ]; size_t used; ! int repeat, width, tablewidth, keywidth; if (self->entry == &cmd_list_commands_entry) return (cmd_list_keys_commands(self, cmdq)); *************** *** 63,108 **** if (args_has(args, 't')) return (cmd_list_keys_table(self, cmdq)); ! width = 0; ! RB_FOREACH(bd, key_bindings, &key_bindings) { ! key = key_string_lookup_key(bd->key & ~KEYC_PREFIX); ! if (key == NULL) continue; - keywidth = strlen(key); - if (!(bd->key & KEYC_PREFIX)) { if (bd->can_repeat) ! keywidth += 4; ! else ! keywidth += 3; ! } else if (bd->can_repeat) ! keywidth += 3; ! if (keywidth > width) ! width = keywidth; } ! RB_FOREACH(bd, key_bindings, &key_bindings) { ! key = key_string_lookup_key(bd->key & ~KEYC_PREFIX); ! if (key == NULL) continue; ! *flags = '\0'; ! if (!(bd->key & KEYC_PREFIX)) { ! if (bd->can_repeat) ! xsnprintf(flags, sizeof flags, "-rn "); else ! xsnprintf(flags, sizeof flags, "-n "); ! } else if (bd->can_repeat) ! xsnprintf(flags, sizeof flags, "-r "); ! used = xsnprintf(tmp, sizeof tmp, "%s%*s ", ! flags, (int) (width - strlen(flags)), key); ! if (used >= sizeof tmp) ! continue; ! ! cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used); ! cmdq_print(cmdq, "bind-key %s", tmp); } return (CMD_RETURN_NORMAL); --- 64,120 ---- if (args_has(args, 't')) return (cmd_list_keys_table(self, cmdq)); ! tablename = args_get(args, 'T'); ! if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { ! cmdq_error(cmdq, "table %s doesn't exist", tablename); ! return (CMD_RETURN_ERROR); ! } ! repeat = 0; ! tablewidth = keywidth = 0; ! RB_FOREACH(table, key_tables, &key_tables) { ! if (tablename != NULL && strcmp(table->name, tablename) != 0) continue; + RB_FOREACH(bd, key_bindings, &table->key_bindings) { + key = key_string_lookup_key(bd->key); + if (key == NULL) + continue; if (bd->can_repeat) ! repeat = 1; ! ! width = strlen(table->name); ! if (width > tablewidth) ! tablewidth =width; ! width = strlen(key); ! if (width > keywidth) ! keywidth = width; ! } } ! RB_FOREACH(table, key_tables, &key_tables) { ! if (tablename != NULL && strcmp(table->name, tablename) != 0) continue; + RB_FOREACH(bd, key_bindings, &table->key_bindings) { + key = key_string_lookup_key(bd->key); + if (key == NULL) + continue; ! if (!repeat) ! r = ""; ! else if (bd->can_repeat) ! r = "-r "; else ! r = " "; ! used = xsnprintf(tmp, sizeof tmp, "%s-T %-*s %-*s ", r, ! (int)tablewidth, table->name, (int)keywidth, key); ! if (used < sizeof tmp) { ! cmd_list_print(bd->cmdlist, tmp + used, ! (sizeof tmp) - used); ! } ! cmdq_print(cmdq, "bind-key %s", tmp); ! } } return (CMD_RETURN_NORMAL);