=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-list-keys.c,v retrieving revision 1.34 retrieving revision 1.35 diff -c -r1.34 -r1.35 *** src/usr.bin/tmux/cmd-list-keys.c 2016/01/19 15:59:12 1.34 --- src/usr.bin/tmux/cmd-list-keys.c 2016/06/15 08:54:11 1.35 *************** *** 1,4 **** ! /* $OpenBSD: cmd-list-keys.c,v 1.34 2016/01/19 15:59:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-list-keys.c,v 1.35 2016/06/15 08:54:11 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 27,36 **** * List key bindings. */ ! 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 *); const struct cmd_entry cmd_list_keys_entry = { .name = "list-keys", --- 27,36 ---- * List key bindings. */ ! static enum cmd_retval cmd_list_keys_exec(struct cmd *, 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,60 **** .name = "list-commands", .alias = "lscm", ! .args = { "", 0, 0 }, ! .usage = "", .flags = CMD_STARTSERVER, .exec = cmd_list_keys_exec }; ! enum cmd_retval cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; --- 47,60 ---- .name = "list-commands", .alias = "lscm", ! .args = { "F:", 0, 0 }, ! .usage = "[-F format]", .flags = CMD_STARTSERVER, .exec = cmd_list_keys_exec }; ! static enum cmd_retval cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; *************** *** 65,71 **** int repeat, width, tablewidth, keywidth; if (self->entry == &cmd_list_commands_entry) ! return (cmd_list_keys_commands(cmdq)); if (args_has(args, 't')) return (cmd_list_keys_table(self, cmdq)); --- 65,71 ---- int repeat, width, tablewidth, keywidth; if (self->entry == &cmd_list_commands_entry) ! return (cmd_list_keys_commands(self, cmdq)); if (args_has(args, 't')) return (cmd_list_keys_table(self, cmdq)); *************** *** 131,137 **** return (CMD_RETURN_NORMAL); } ! enum cmd_retval cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; --- 131,137 ---- return (CMD_RETURN_NORMAL); } ! static enum cmd_retval cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; *************** *** 180,200 **** return (CMD_RETURN_NORMAL); } ! enum cmd_retval ! cmd_list_keys_commands(struct cmd_q *cmdq) { const struct cmd_entry **entryp; const struct cmd_entry *entry; for (entryp = cmd_table; *entryp != NULL; entryp++) { entry = *entryp; ! if (entry->alias == NULL) { ! cmdq_print(cmdq, "%s %s", entry->name, entry->usage); ! continue; } ! cmdq_print(cmdq, "%s (%s) %s", entry->name, entry->alias, ! entry->usage); } return (CMD_RETURN_NORMAL); } --- 180,223 ---- return (CMD_RETURN_NORMAL); } ! 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; ! ! 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); ! } ! ! line = format_expand(ft, template); ! if (*line != '\0') ! cmdq_print(cmdq, "%s", line); ! free(line); } + format_free(ft); return (CMD_RETURN_NORMAL); }