From 45dfc5a074e2ceae11a6d4aeae597bee1e028503 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2014 22:29:25 +0000 Subject: Instead of setting up the default keys by building the key struct directly with a helper function in the cmd_entry, include a table of bind-key commands and pass them through the command parser and a temporary cmd_q. As well as being smaller, this will allow default bindings to be command sequences which will probably be needed soon. --- cmd-list-keys.c | 1 - 1 file changed, 1 deletion(-) (limited to 'cmd-list-keys.c') diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 65e4469e..0d64f1be 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -34,7 +34,6 @@ const struct cmd_entry cmd_list_keys_entry = { "t:", 0, 0, "[-t key-table]", 0, - NULL, cmd_list_keys_exec }; -- cgit From f5bc85591a1f7c26bf030f5781d63985b2ee4d23 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2014 22:44:30 +0000 Subject: Move list-commands into list-keys. --- cmd-list-keys.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cmd-list-keys.c') diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 0d64f1be..6fbaf14d 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -27,7 +27,9 @@ */ 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 *, struct cmd_q *); const struct cmd_entry cmd_list_keys_entry = { "list-keys", "lsk", @@ -37,6 +39,14 @@ const struct cmd_entry cmd_list_keys_entry = { cmd_list_keys_exec }; +const struct cmd_entry cmd_list_commands_entry = { + "list-commands", "lscm", + "", 0, 0, + "", + 0, + cmd_list_keys_exec +}; + enum cmd_retval cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) { @@ -47,6 +57,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) size_t used; int width, 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)); @@ -147,3 +160,22 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } + +enum cmd_retval +cmd_list_keys_commands(unused struct cmd *self, struct cmd_q *cmdq) +{ + const struct cmd_entry **entryp; + 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); +} -- cgit From 900f6fc17e6764377a8e293ce742fb41f1add9bd Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2014 23:27:14 +0000 Subject: Tidy up some includes. --- cmd-list-keys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd-list-keys.c') diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 6fbaf14d..0733ee28 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -165,7 +165,7 @@ enum cmd_retval cmd_list_keys_commands(unused struct cmd *self, struct cmd_q *cmdq) { const struct cmd_entry **entryp; - struct cmd_entry *entry; + const struct cmd_entry *entry; for (entryp = cmd_table; *entryp != NULL; entryp++) { entry = *entryp; -- cgit