mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	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.
This commit is contained in:
		@@ -26,7 +26,7 @@
 | 
			
		||||
 * Create a new window.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
enum cmd_retval	cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
 | 
			
		||||
enum cmd_retval	cmd_new_window_exec(struct cmd *, struct cmd_q *);
 | 
			
		||||
 | 
			
		||||
const struct cmd_entry cmd_new_window_entry = {
 | 
			
		||||
	"new-window", "neww",
 | 
			
		||||
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_new_window_entry = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum cmd_retval
 | 
			
		||||
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
 | 
			
		||||
{
 | 
			
		||||
	struct args		*args = self->args;
 | 
			
		||||
	struct session		*s;
 | 
			
		||||
@@ -54,7 +54,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
	char			*cp;
 | 
			
		||||
 | 
			
		||||
	if (args_has(args, 'a')) {
 | 
			
		||||
		wl = cmd_find_window(ctx, args_get(args, 't'), &s);
 | 
			
		||||
		wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
 | 
			
		||||
		if (wl == NULL)
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		idx = wl->idx + 1;
 | 
			
		||||
@@ -65,7 +65,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
		if (last == INT_MAX) {
 | 
			
		||||
			ctx->error(ctx, "no free window indexes");
 | 
			
		||||
			cmdq_error(cmdq, "no free window indexes");
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -76,7 +76,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
			server_unlink_window(s, wl);
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
 | 
			
		||||
		if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
 | 
			
		||||
			return (CMD_RETURN_ERROR);
 | 
			
		||||
	}
 | 
			
		||||
	detached = args_has(args, 'd');
 | 
			
		||||
@@ -105,13 +105,13 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
		cmd = options_get_string(&s->options, "default-command");
 | 
			
		||||
	else
 | 
			
		||||
		cmd = args->argv[0];
 | 
			
		||||
	cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
 | 
			
		||||
	cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
 | 
			
		||||
 | 
			
		||||
	if (idx == -1)
 | 
			
		||||
		idx = -1 - options_get_number(&s->options, "base-index");
 | 
			
		||||
	wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
 | 
			
		||||
	if (wl == NULL) {
 | 
			
		||||
		ctx->error(ctx, "create window failed: %s", cause);
 | 
			
		||||
		cmdq_error(cmdq, "create window failed: %s", cause);
 | 
			
		||||
		free(cause);
 | 
			
		||||
		return (CMD_RETURN_ERROR);
 | 
			
		||||
	}
 | 
			
		||||
@@ -126,14 +126,14 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
			
		||||
			template = NEW_WINDOW_TEMPLATE;
 | 
			
		||||
 | 
			
		||||
		ft = format_create();
 | 
			
		||||
		if ((c = cmd_find_client(ctx, NULL, 1)) != NULL)
 | 
			
		||||
		    format_client(ft, c);
 | 
			
		||||
		if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
 | 
			
		||||
			format_client(ft, c);
 | 
			
		||||
		format_session(ft, s);
 | 
			
		||||
		format_winlink(ft, s, wl);
 | 
			
		||||
		format_window_pane(ft, wl->window->active);
 | 
			
		||||
 | 
			
		||||
		cp = format_expand(ft, template);
 | 
			
		||||
		ctx->print(ctx, "%s", cp);
 | 
			
		||||
		cmdq_print(cmdq, "%s", cp);
 | 
			
		||||
		free(cp);
 | 
			
		||||
 | 
			
		||||
		format_free(ft);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user