mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +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:
@ -30,8 +30,8 @@
|
||||
* Create a new session and attach to the current terminal unless -d is given.
|
||||
*/
|
||||
|
||||
int cmd_new_session_check(struct args *);
|
||||
int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
enum cmd_retval cmd_new_session_check(struct args *);
|
||||
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
|
||||
|
||||
const struct cmd_entry cmd_new_session_entry = {
|
||||
"new-session", "new",
|
||||
@ -44,15 +44,15 @@ const struct cmd_entry cmd_new_session_entry = {
|
||||
cmd_new_session_exec
|
||||
};
|
||||
|
||||
int
|
||||
enum cmd_retval
|
||||
cmd_new_session_check(struct args *args)
|
||||
{
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
|
||||
return (-1);
|
||||
return (0);
|
||||
return (CMD_RETURN_ERROR);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
int
|
||||
enum cmd_retval
|
||||
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
@ -71,11 +71,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (newname != NULL) {
|
||||
if (!session_check_name(newname)) {
|
||||
ctx->error(ctx, "bad session name: %s", newname);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
ctx->error(ctx, "duplicate session: %s", newname);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (target != NULL) {
|
||||
groupwith = cmd_find_session(ctx, target, 0);
|
||||
if (groupwith == NULL)
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
} else
|
||||
groupwith = NULL;
|
||||
|
||||
@ -131,7 +131,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
|
||||
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "width %s", errstr);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
@ -171,7 +171,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
ctx->error(ctx, "height %s", errstr);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,7 +202,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
free(cause);
|
||||
return (-1);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_free(&env);
|
||||
|
||||
@ -269,5 +269,5 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
ARRAY_FREE(&cfg_causes);
|
||||
}
|
||||
|
||||
return (!detached); /* 1 means don't tell command client to exit */
|
||||
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
|
||||
}
|
||||
|
Reference in New Issue
Block a user