aboutsummaryrefslogtreecommitdiff
path: root/cmd-choose-session.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2012-07-04 11:03:20 +0000
committerTiago Cunha <tcunha@gmx.com>2012-07-04 11:03:20 +0000
commit7e02d2f459531107770e925bebf1fbc548719de0 (patch)
treebbad76367cef32639ece94dad81b70167140657a /cmd-choose-session.c
parent5761712799beb830ba18e27b3300aaa248ff83d4 (diff)
downloadrtmux-7e02d2f459531107770e925bebf1fbc548719de0.tar.gz
rtmux-7e02d2f459531107770e925bebf1fbc548719de0.tar.bz2
rtmux-7e02d2f459531107770e925bebf1fbc548719de0.zip
Sync OpenBSD patchset 1143:
Provide common helper function for adding windows and sessions to choose lists and expand %% in command before using it rather than at callback time. From Thomas Adam.
Diffstat (limited to 'cmd-choose-session.c')
-rw-r--r--cmd-choose-session.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/cmd-choose-session.c b/cmd-choose-session.c
index 2c859d9e..18d4fbfd 100644
--- a/cmd-choose-session.c
+++ b/cmd-choose-session.c
@@ -45,9 +45,9 @@ int
cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
- struct window_choose_data *cdata;
struct winlink *wl;
struct session *s;
+ char *action;
const char *template;
u_int idx, cur;
@@ -65,28 +65,21 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if ((template = args_get(args, 'F')) == NULL)
template = DEFAULT_SESSION_TEMPLATE;
+ if (args->argc != 0)
+ action = xstrdup(args->argv[0]);
+ else
+ action = xstrdup("switch-client -t '%%'");
+
cur = idx = 0;
RB_FOREACH(s, sessions, &sessions) {
if (s == ctx->curclient->session)
cur = idx;
idx++;
- cdata = window_choose_data_create(ctx);
- if (args->argc != 0)
- cdata->action = xstrdup(args->argv[0]);
- else
- cdata->action = xstrdup("switch-client -t '%%'");
- cdata->idx = s->idx;
-
- cdata->client->references++;
- cdata->session->references++;
-
- cdata->ft_template = xstrdup(template);
- format_add(cdata->ft, "line", "%u", idx);
- format_session(cdata->ft, s);
-
- window_choose_add(wl->window->active, cdata);
+ window_choose_add_session(wl->window->active,
+ ctx, s, template, action, idx);
}
+ xfree(action);
window_choose_ready(wl->window->active,
cur, cmd_choose_session_callback, cmd_choose_session_free);
@@ -97,18 +90,11 @@ cmd_choose_session_exec(struct cmd *self, struct cmd_ctx *ctx)
void
cmd_choose_session_callback(struct window_choose_data *cdata)
{
- struct session *s;
-
if (cdata == NULL)
return;
if (cdata->client->flags & CLIENT_DEAD)
return;
- s = session_find_by_index(cdata->idx);
- if (s == NULL)
- return;
-
- cdata->raw_format = xstrdup(s->name);
window_choose_ctx(cdata);
}
@@ -121,8 +107,8 @@ cmd_choose_session_free(struct window_choose_data *cdata)
cdata->client->references--;
cdata->session->references--;
+ xfree(cdata->command);
xfree(cdata->ft_template);
- xfree(cdata->action);
format_free(cdata->ft);
xfree(cdata);
}