diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-24 09:54:10 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-24 09:54:10 +0000 |
commit | 20636d956dd36c1f14152569a4d44a50eea9083d (patch) | |
tree | dbbbee5d7ce1e3b12c3067c305d07d2d98e39900 /key-bindings.c | |
parent | 66edb3392b234ccd9a940039936edb34258c2102 (diff) |
Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.
Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.
When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.
Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.
Diffstat (limited to 'key-bindings.c')
-rw-r--r-- | key-bindings.c | 79 |
1 files changed, 6 insertions, 73 deletions
diff --git a/key-bindings.c b/key-bindings.c index 0f944c4c..4e889b7e 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -182,11 +182,11 @@ key_bindings_init(void) RB_INIT(&key_bindings); for (i = 0; i < nitems(table); i++) { - cmdlist = xmalloc(sizeof *cmdlist); - TAILQ_INIT(&cmdlist->list); + cmdlist = xcalloc(1, sizeof *cmdlist); cmdlist->references = 1; + TAILQ_INIT(&cmdlist->list); - cmd = xmalloc(sizeof *cmd); + cmd = xcalloc(1, sizeof *cmd); cmd->entry = table[i].entry; if (cmd->entry->key_binding != NULL) cmd->entry->key_binding(cmd, table[i].key); @@ -199,88 +199,21 @@ key_bindings_init(void) } } -void printflike2 -key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - char *msg; - - if (ctx->curclient->session == NULL) - return; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); - - *msg = toupper((u_char) *msg); - status_message_set(ctx->curclient, "%s", msg); - free(msg); -} - -void printflike2 -key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...) -{ - struct winlink *wl; - va_list ap; - - if (ctx->curclient->session == NULL) - return; - - wl = ctx->curclient->session->curw; - if (wl->window->active->mode != &window_copy_mode) { - window_pane_reset_mode(wl->window->active); - window_pane_set_mode(wl->window->active, &window_copy_mode); - window_copy_init_for_output(wl->window->active); - } - - va_start(ap, fmt); - window_copy_vadd(wl->window->active, fmt, ap); - va_end(ap); -} - -void printflike2 -key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...) -{ - va_list ap; - char *msg; - - if (ctx->curclient->session == NULL) - return; - - if (options_get_number(&global_options, "quiet")) - return; - - va_start(ap, fmt); - xvasprintf(&msg, fmt, ap); - va_end(ap); - - *msg = toupper((u_char) *msg); - status_message_set(ctx->curclient, "%s", msg); - free(msg); -} - void key_bindings_dispatch(struct key_binding *bd, struct client *c) { - struct cmd_ctx *ctx; struct cmd *cmd; int readonly; - ctx = cmd_get_ctx(NULL, c); - ctx->error = key_bindings_error; - ctx->print = key_bindings_print; - ctx->info = key_bindings_info; - readonly = 1; TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) { if (!(cmd->entry->flags & CMD_READONLY)) readonly = 0; } - if (!readonly && c->flags & CLIENT_READONLY) { - key_bindings_info(ctx, "client is read-only"); + if (!readonly && (c->flags & CLIENT_READONLY)) { + cmdq_info(c->cmdq, "client is read-only"); return; } - cmd_list_exec(bd->cmdlist, ctx); - cmd_free_ctx(ctx); + cmdq_run(c->cmdq, bd->cmdlist); } |