diff options
author | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
---|---|---|
committer | nicm <nicm> | 2016-10-16 17:55:14 +0000 |
commit | ddc4512d2e0eda6c705e002cb5dbf80719d709e1 (patch) | |
tree | cd9ff99f4b1ccb3e76ab99633d59772ae07c3092 /cmd-display-panes.c | |
parent | bfe14b531267f3762a518f98b72a3148a134396a (diff) |
Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.
This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.
A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.
Diffstat (limited to 'cmd-display-panes.c')
-rw-r--r-- | cmd-display-panes.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/cmd-display-panes.c b/cmd-display-panes.c index 2edb2eb3..471bec02 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -65,32 +65,48 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } +static enum cmd_retval +cmd_display_panes_error(struct cmd_q *cmdq, void *data) +{ + char *error = data; + + cmdq_error(cmdq, "%s", error); + free(error); + + return (CMD_RETURN_NORMAL); +} + static void cmd_display_panes_callback(struct client *c, struct window_pane *wp) { struct cmd_list *cmdlist; + struct cmd_q *new_cmdq; char *template, *cmd, *expanded, *cause; template = c->identify_callback_data; - if (wp != NULL) { - xasprintf(&expanded, "%%%u", wp->id); - cmd = cmd_template_replace(template, expanded, 1); - - if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { - if (cause != NULL) { - *cause = toupper((u_char) *cause); - status_message_set(c, "%s", cause); - free(cause); - } - } else { - cmdq_run(c->cmdq, cmdlist, NULL); - cmd_list_free(cmdlist); - } - - free(cmd); - free(expanded); + if (wp == NULL) + goto out; + xasprintf(&expanded, "%%%u", wp->id); + cmd = cmd_template_replace(template, expanded, 1); + + if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { + if (cause != NULL) { + new_cmdq = cmdq_get_callback(cmd_display_panes_error, + cause); + } else + new_cmdq = NULL; + } else { + new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); + cmd_list_free(cmdlist); } + if (new_cmdq != NULL) + cmdq_append(c, new_cmdq); + + free(cmd); + free(expanded); + +out: free(c->identify_callback_data); c->identify_callback_data = NULL; c->identify_callback = NULL; |