From 180faf73afe07d35e6002993a70d5fe63549ffce Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 21 Mar 2013 16:09:59 +0000 Subject: Allow choose commands to be used outside tmux, so long as at least one client is attached. --- cmd-choose-tree.c | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) (limited to 'cmd-choose-tree.c') diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index b274d561..a111bc07 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -34,9 +34,6 @@ enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *); -void cmd_choose_tree_callback(struct window_choose_data *); -void cmd_choose_tree_free(struct window_choose_data *); - const struct cmd_entry cmd_choose_tree_entry = { "choose-tree", NULL, "S:W:swub:c:t:", 0, 1, @@ -74,6 +71,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl, *wm; struct session *s, *s2; + struct client *c; struct window_choose_data *wcd = NULL; const char *ses_template, *win_template; char *final_win_action, *cur_win_template; @@ -86,12 +84,13 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) ses_template = win_template = NULL; ses_action = win_action = NULL; - if (ctx->curclient == NULL) { - ctx->error(ctx, "must be run interactively"); + if ((c = cmd_current_client(ctx)) == NULL) { + ctx->error(ctx, "no client available"); return (CMD_RETURN_ERROR); } - s = ctx->curclient->session; + if ((s = c->session) == NULL) + return (CMD_RETURN_ERROR); if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); @@ -175,7 +174,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) } wcd = window_choose_add_session(wl->window->active, - ctx, s2, ses_template, (char *)ses_action, idx_ses); + c, s2, ses_template, (char *)ses_action, idx_ses); /* If we're just choosing sessions, skip choosing windows. */ if (sflag && !wflag) { @@ -213,7 +212,7 @@ windows_only: cur_win_template = final_win_template_last; window_choose_add_window(wl->window->active, - ctx, s2, wm, cur_win_template, + c, s2, wm, cur_win_template, final_win_action, (wflag && !sflag) ? win_ses : idx_ses); @@ -230,35 +229,10 @@ windows_only: free(final_win_template_middle); free(final_win_template_last); - window_choose_ready(wl->window->active, cur_win, - cmd_choose_tree_callback, cmd_choose_tree_free); + window_choose_ready(wl->window->active, cur_win, NULL); if (args_has(args, 'u')) window_choose_expand_all(wl->window->active); return (CMD_RETURN_NORMAL); } - -void -cmd_choose_tree_callback(struct window_choose_data *cdata) -{ - if (cdata == NULL) - return; - - if (cdata->client->flags & CLIENT_DEAD) - return; - - window_choose_ctx(cdata); -} - -void -cmd_choose_tree_free(struct window_choose_data *cdata) -{ - cdata->session->references--; - cdata->client->references--; - - free(cdata->ft_template); - free(cdata->command); - format_free(cdata->ft); - free(cdata); -} -- cgit From 66414029a12af55f4e6b4a421d5e193c2561e30c Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 21 Mar 2013 16:23:07 +0000 Subject: Run session command before window in choose-tree. --- cmd-choose-tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cmd-choose-tree.c') diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index a111bc07..1e6bba71 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -37,7 +37,7 @@ enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_choose_tree_entry = { "choose-tree", NULL, "S:W:swub:c:t:", 0, 1, - "[-swu] [-b session-template] [-c window template] [-S format] " \ + "[-suw] [-b session-template] [-c window template] [-S format] " \ "[-W format] " CMD_TARGET_WINDOW_USAGE, 0, NULL, @@ -174,7 +174,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) } wcd = window_choose_add_session(wl->window->active, - c, s2, ses_template, (char *)ses_action, idx_ses); + c, s2, ses_template, ses_action, idx_ses); /* If we're just choosing sessions, skip choosing windows. */ if (sflag && !wflag) { @@ -203,8 +203,8 @@ windows_only: cur_win = idx_ses; } - xasprintf(&final_win_action, "%s ; %s", win_action, - wcd ? wcd->command : ""); + xasprintf(&final_win_action, "%s ; %s", + wcd ? wcd->command : "", win_action); if (win_ses != win_max) cur_win_template = final_win_template_middle; -- cgit From 48291f0eeb9c376f821c746ca1ab6b88fcb62db2 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 21 Mar 2013 16:53:12 +0000 Subject: Make choose-tree actually work again. --- cmd-choose-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cmd-choose-tree.c') diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index 1e6bba71..af85a3bf 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -203,8 +203,9 @@ windows_only: cur_win = idx_ses; } - xasprintf(&final_win_action, "%s ; %s", - wcd ? wcd->command : "", win_action); + xasprintf(&final_win_action, "%s %s %s", + wcd != NULL ? wcd->command : "", + wcd != NULL ? ";" : "", win_action); if (win_ses != win_max) cur_win_template = final_win_template_middle; -- cgit From 20636d956dd36c1f14152569a4d44a50eea9083d Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 24 Mar 2013 09:54:10 +0000 Subject: 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. --- cmd-choose-tree.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cmd-choose-tree.c') diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index af85a3bf..f22f17c2 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -32,7 +32,7 @@ * Enter choice mode to choose a session and/or window. */ -enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *); +enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_choose_tree_entry = { "choose-tree", NULL, @@ -66,7 +66,7 @@ const struct cmd_entry cmd_choose_window_entry = { }; enum cmd_retval -cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) +cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct winlink *wl, *wm; @@ -84,15 +84,15 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) ses_template = win_template = NULL; ses_action = win_action = NULL; - if ((c = cmd_current_client(ctx)) == NULL) { - ctx->error(ctx, "no client available"); + if ((c = cmd_current_client(cmdq)) == NULL) { + cmdq_error(cmdq, "no client available"); return (CMD_RETURN_ERROR); } if ((s = c->session) == NULL) return (CMD_RETURN_ERROR); - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) + if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) -- cgit