version 1.40, 2016/10/16 19:04:05 |
version 1.41, 2017/01/24 21:50:22 |
|
|
|
|
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *); |
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *); |
|
|
static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmdq_item *); |
|
static enum cmd_retval cmd_list_keys_commands(struct cmd *, |
static enum cmd_retval cmd_list_keys_commands(struct cmd *, |
struct cmdq_item *); |
struct cmdq_item *); |
|
|
|
|
.name = "list-keys", |
.name = "list-keys", |
.alias = "lsk", |
.alias = "lsk", |
|
|
.args = { "t:T:", 0, 0 }, |
.args = { "T:", 0, 0 }, |
.usage = "[-t mode-table] [-T key-table]", |
.usage = "[-T key-table]", |
|
|
.flags = CMD_STARTSERVER|CMD_AFTERHOOK, |
.flags = CMD_STARTSERVER|CMD_AFTERHOOK, |
.exec = cmd_list_keys_exec |
.exec = cmd_list_keys_exec |
|
|
if (self->entry == &cmd_list_commands_entry) |
if (self->entry == &cmd_list_commands_entry) |
return (cmd_list_keys_commands(self, item)); |
return (cmd_list_keys_commands(self, item)); |
|
|
if (args_has(args, 't')) |
|
return (cmd_list_keys_table(self, item)); |
|
|
|
tablename = args_get(args, 'T'); |
tablename = args_get(args, 'T'); |
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { |
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { |
cmdq_error(item, "table %s doesn't exist", tablename); |
cmdq_error(item, "table %s doesn't exist", tablename); |
|
|
free(cp); |
free(cp); |
|
|
cmdq_print(item, "bind-key %s", tmp); |
cmdq_print(item, "bind-key %s", tmp); |
} |
|
} |
|
|
|
return (CMD_RETURN_NORMAL); |
|
} |
|
|
|
static enum cmd_retval |
|
cmd_list_keys_table(struct cmd *self, struct cmdq_item *item) |
|
{ |
|
struct args *args = self->args; |
|
const char *tablename, *cmdstr; |
|
const struct mode_key_table *mtab; |
|
struct mode_key_binding *mbind; |
|
int width, keywidth; |
|
|
|
tablename = args_get(args, 't'); |
|
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
|
cmdq_error(item, "unknown key table: %s", tablename); |
|
return (CMD_RETURN_ERROR); |
|
} |
|
|
|
keywidth = 0; |
|
RB_FOREACH(mbind, mode_key_tree, mtab->tree) { |
|
width = strlen(key_string_lookup_key(mbind->key)); |
|
if (width > keywidth) |
|
keywidth = width; |
|
} |
|
|
|
RB_FOREACH(mbind, mode_key_tree, mtab->tree) { |
|
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); |
|
if (cmdstr != NULL) { |
|
cmdq_print(item, "bind-key -t %s %*s %s", |
|
mtab->name, (int)keywidth, |
|
key_string_lookup_key(mbind->key), cmdstr); |
|
} |
} |
} |
} |
|
|