mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 13:37:12 +00:00
Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix problems with using some commands in a command sequence. Most of the work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.
This commit is contained in:
34
cmd-list.c
34
cmd-list.c
@ -79,12 +79,13 @@ bad:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int
|
||||
enum cmd_retval
|
||||
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct client *c = ctx->curclient;
|
||||
struct cmd *cmd;
|
||||
int n, retval, guards;
|
||||
enum cmd_retval retval;
|
||||
int guards, n;
|
||||
|
||||
guards = 0;
|
||||
if (c != NULL && c->session != NULL)
|
||||
@ -98,21 +99,17 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
if (guards)
|
||||
ctx->print(ctx, "%%end");
|
||||
|
||||
/* Return of -1 is an error. */
|
||||
if (n == -1)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* A 1 return value means the command client is being attached
|
||||
* (sent MSG_READY).
|
||||
*/
|
||||
if (n == 1) {
|
||||
retval = 1;
|
||||
switch (n)
|
||||
{
|
||||
case CMD_RETURN_ERROR:
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_RETURN_ATTACH:
|
||||
/* Client is being attached (send MSG_READY). */
|
||||
retval = CMD_RETURN_ATTACH;
|
||||
|
||||
/*
|
||||
* The command client has been attached, so mangle the
|
||||
* context to treat any following commands as if they
|
||||
* were called from inside.
|
||||
* Mangle the context to treat any following commands
|
||||
* as if they were called from inside.
|
||||
*/
|
||||
if (ctx->curclient == NULL) {
|
||||
ctx->curclient = ctx->cmdclient;
|
||||
@ -122,6 +119,13 @@ cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
|
||||
ctx->print = key_bindings_print;
|
||||
ctx->info = key_bindings_info;
|
||||
}
|
||||
break;
|
||||
case CMD_RETURN_YIELD:
|
||||
if (retval == CMD_RETURN_NORMAL)
|
||||
retval = CMD_RETURN_YIELD;
|
||||
break;
|
||||
case CMD_RETURN_NORMAL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (retval);
|
||||
|
Reference in New Issue
Block a user