version 1.39, 2016/10/14 22:14:22 |
version 1.40, 2016/10/16 19:04:05 |
|
|
* List key bindings. |
* List key bindings. |
*/ |
*/ |
|
|
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *); |
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *); |
|
|
static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *); |
static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmdq_item *); |
static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *); |
static enum cmd_retval cmd_list_keys_commands(struct cmd *, |
|
struct cmdq_item *); |
|
|
const struct cmd_entry cmd_list_keys_entry = { |
const struct cmd_entry cmd_list_keys_entry = { |
.name = "list-keys", |
.name = "list-keys", |
|
|
}; |
}; |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) |
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
struct key_table *table; |
struct key_table *table; |
|
|
int repeat, width, tablewidth, keywidth; |
int repeat, width, tablewidth, keywidth; |
|
|
if (self->entry == &cmd_list_commands_entry) |
if (self->entry == &cmd_list_commands_entry) |
return (cmd_list_keys_commands(self, cmdq)); |
return (cmd_list_keys_commands(self, item)); |
|
|
if (args_has(args, 't')) |
if (args_has(args, 't')) |
return (cmd_list_keys_table(self, cmdq)); |
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(cmdq, "table %s doesn't exist", tablename); |
cmdq_error(item, "table %s doesn't exist", tablename); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
|
|
strlcat(tmp, cp, sizeof tmp); |
strlcat(tmp, cp, sizeof tmp); |
free(cp); |
free(cp); |
|
|
cmdq_print(cmdq, "bind-key %s", tmp); |
cmdq_print(item, "bind-key %s", tmp); |
} |
} |
} |
} |
|
|
|
|
} |
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) |
cmd_list_keys_table(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
const char *tablename, *cmdstr; |
const char *tablename, *cmdstr; |
|
|
|
|
tablename = args_get(args, 't'); |
tablename = args_get(args, 't'); |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
if ((mtab = mode_key_findtable(tablename)) == NULL) { |
cmdq_error(cmdq, "unknown key table: %s", tablename); |
cmdq_error(item, "unknown key table: %s", tablename); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
|
|
RB_FOREACH(mbind, mode_key_tree, mtab->tree) { |
RB_FOREACH(mbind, mode_key_tree, mtab->tree) { |
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); |
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); |
if (cmdstr != NULL) { |
if (cmdstr != NULL) { |
cmdq_print(cmdq, "bind-key -t %s %*s %s", |
cmdq_print(item, "bind-key -t %s %*s %s", |
mtab->name, (int)keywidth, |
mtab->name, (int)keywidth, |
key_string_lookup_key(mbind->key), cmdstr); |
key_string_lookup_key(mbind->key), cmdstr); |
} |
} |
|
|
} |
} |
|
|
static enum cmd_retval |
static enum cmd_retval |
cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq) |
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
const struct cmd_entry **entryp; |
const struct cmd_entry **entryp; |
const struct cmd_entry *entry; |
const struct cmd_entry *entry; |
struct format_tree *ft; |
struct format_tree *ft; |
const char *template; |
const char *template, *s; |
char *line; |
char *line; |
|
|
if ((template = args_get(args, 'F')) == NULL) { |
if ((template = args_get(args, 'F')) == NULL) { |
|
|
"#{command_list_usage}"; |
"#{command_list_usage}"; |
} |
} |
|
|
ft = format_create(cmdq, 0); |
ft = format_create(item, 0); |
format_defaults(ft, NULL, NULL, NULL, NULL); |
format_defaults(ft, NULL, NULL, NULL, NULL); |
|
|
for (entryp = cmd_table; *entryp != NULL; entryp++) { |
for (entryp = cmd_table; *entryp != NULL; entryp++) { |
entry = *entryp; |
entry = *entryp; |
|
|
format_add(ft, "command_list_name", "%s", entry->name); |
format_add(ft, "command_list_name", "%s", entry->name); |
if (entry->alias != NULL) { |
if (entry->alias != NULL) |
format_add(ft, "command_list_alias", "%s", |
s = entry->alias; |
entry->alias); |
else |
} |
s = ""; |
if (entry->alias != NULL) { |
format_add(ft, "command_list_alias", "%s", s); |
format_add(ft, "command_list_usage", "%s", |
if (entry->usage != NULL) |
entry->usage); |
s = entry->usage; |
} |
else |
|
s = ""; |
|
format_add(ft, "command_list_usage", "%s", s); |
|
|
line = format_expand(ft, template); |
line = format_expand(ft, template); |
if (*line != '\0') |
if (*line != '\0') |
cmdq_print(cmdq, "%s", line); |
cmdq_print(item, "%s", line); |
free(line); |
free(line); |
} |
} |
|
|