diff options
author | nicm <nicm> | 2016-06-15 08:54:11 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-06-15 08:54:11 +0000 |
commit | 068b8b03ad06abf1082e288ed7496970cccd7678 (patch) | |
tree | 0aea704d9e4901d92914defc1bb34cdac33dec9e /cmd-list-keys.c | |
parent | 17e474445983ce4fd28cf181829657f1b8ff6ad1 (diff) | |
download | rtmux-068b8b03ad06abf1082e288ed7496970cccd7678.tar.gz rtmux-068b8b03ad06abf1082e288ed7496970cccd7678.tar.bz2 rtmux-068b8b03ad06abf1082e288ed7496970cccd7678.zip |
Add -F to list-commands.
Diffstat (limited to 'cmd-list-keys.c')
-rw-r--r-- | cmd-list-keys.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/cmd-list-keys.c b/cmd-list-keys.c index c3ace8de..06f0e8c5 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -27,10 +27,10 @@ * List key bindings. */ -enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_list_keys_commands(struct cmd_q *); +static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_list_keys_entry = { .name = "list-keys", @@ -47,14 +47,14 @@ const struct cmd_entry cmd_list_commands_entry = { .name = "list-commands", .alias = "lscm", - .args = { "", 0, 0 }, - .usage = "", + .args = { "F:", 0, 0 }, + .usage = "[-F format]", .flags = CMD_STARTSERVER, .exec = cmd_list_keys_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -65,7 +65,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) int repeat, width, tablewidth, keywidth; if (self->entry == &cmd_list_commands_entry) - return (cmd_list_keys_commands(cmdq)); + return (cmd_list_keys_commands(self, cmdq)); if (args_has(args, 't')) return (cmd_list_keys_table(self, cmdq)); @@ -131,7 +131,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -180,21 +180,44 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -enum cmd_retval -cmd_list_keys_commands(struct cmd_q *cmdq) +static enum cmd_retval +cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq) { + struct args *args = self->args; const struct cmd_entry **entryp; const struct cmd_entry *entry; + struct format_tree *ft; + const char *template; + char *line; + + if ((template = args_get(args, 'F')) == NULL) { + template = "#{command_list_name}" + "#{?command_list_alias, (#{command_list_alias}),} " + "#{command_list_usage}"; + } + + ft = format_create(cmdq, 0); + format_defaults(ft, NULL, NULL, NULL, NULL); for (entryp = cmd_table; *entryp != NULL; entryp++) { entry = *entryp; - if (entry->alias == NULL) { - cmdq_print(cmdq, "%s %s", entry->name, entry->usage); - continue; + + format_add(ft, "command_list_name", "%s", entry->name); + if (entry->alias != NULL) { + format_add(ft, "command_list_alias", "%s", + entry->alias); + } + if (entry->alias != NULL) { + format_add(ft, "command_list_usage", "%s", + entry->usage); } - cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias, - entry->usage); + + line = format_expand(ft, template); + if (*line != '\0') + cmdq_print(cmdq, "%s", line); + free(line); } + format_free(ft); return (CMD_RETURN_NORMAL); } |