aboutsummaryrefslogtreecommitdiff
path: root/cmd-command-prompt.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-23 22:25:58 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-23 22:25:58 +0000
commit3964309c67a683e5132662e38b5ff932af5cbeea (patch)
treef8566b756787ef7ceeed61e63f61b2a0ece4c751 /cmd-command-prompt.c
parent357da035b9d052b4cba8db806c6237272ade6673 (diff)
downloadrtmux-3964309c67a683e5132662e38b5ff932af5cbeea.tar.gz
rtmux-3964309c67a683e5132662e38b5ff932af5cbeea.tar.bz2
rtmux-3964309c67a683e5132662e38b5ff932af5cbeea.zip
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 'cmd-command-prompt.c')
-rw-r--r--cmd-command-prompt.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index 97284898..3bb79ed9 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -31,7 +31,7 @@
void cmd_command_prompt_key_binding(struct cmd *, int);
int cmd_command_prompt_check(struct args *);
-enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
+enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
int cmd_command_prompt_callback(void *, const char *);
void cmd_command_prompt_free(void *);
@@ -85,7 +85,7 @@ cmd_command_prompt_key_binding(struct cmd *self, int key)
}
enum cmd_retval
-cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
+cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *inputs, *prompts;
@@ -94,7 +94,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
char *prompt, *ptr, *input = NULL;
size_t n;
- if ((c = cmd_find_client(ctx, args_get(args, 't'), 0)) == NULL)
+ if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (c->prompt_string != NULL)
@@ -150,7 +150,6 @@ cmd_command_prompt_callback(void *data, const char *s)
struct cmd_command_prompt_cdata *cdata = data;
struct client *c = cdata->c;
struct cmd_list *cmdlist;
- struct cmd_ctx *ctx;
char *cause, *new_template, *prompt, *ptr;
char *input = NULL;
@@ -175,7 +174,7 @@ cmd_command_prompt_callback(void *data, const char *s)
return (1);
}
- if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
+ if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(c, "%s", cause);
@@ -184,14 +183,8 @@ cmd_command_prompt_callback(void *data, const char *s)
return (0);
}
- ctx = cmd_get_ctx(NULL, c);
- ctx->error = key_bindings_error;
- ctx->print = key_bindings_print;
- ctx->info = key_bindings_info;
-
- cmd_list_exec(cmdlist, ctx);
+ cmdq_run(c->cmdq, cmdlist);
cmd_list_free(cmdlist);
- cmd_free_ctx(ctx);
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
return (1);