summaryrefslogtreecommitdiffstats
path: root/cmd-choose-tree.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-09-03 09:01:16 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-09-03 09:01:16 +0000
commita679a4a7081b8efdf90445ad14e87f9c6b1fe964 (patch)
treecd965af246235f6c5b409b924f25719033f6d6ed /cmd-choose-tree.c
parent2e43372d0b2932f7abf5b16544faec3ecf214433 (diff)
Change format of choose-tree arrows slightly, from Romain Francoise.
Diffstat (limited to 'cmd-choose-tree.c')
-rw-r--r--cmd-choose-tree.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c
index e4fd267e..269b8adb 100644
--- a/cmd-choose-tree.c
+++ b/cmd-choose-tree.c
@@ -74,11 +74,14 @@ 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 tty *tty;
struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template;
- char *final_win_action, *final_win_template;
+ char *final_win_action, *cur_win_template;
+ char *final_win_template_middle;
+ char *final_win_template_last;
const char *ses_action, *win_action;
- u_int cur_win, idx_ses, win_ses;
+ u_int cur_win, idx_ses, win_ses, win_max;
u_int wflag, sflag;
ses_template = win_template = NULL;
@@ -90,6 +93,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
}
s = ctx->curclient->session;
+ tty = &ctx->curclient->tty;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
@@ -146,12 +150,14 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
* window template, otherwise just render the windows as a flat list
* without any padding.
*/
- if (wflag && sflag)
- xasprintf(&final_win_template, " --> %s", win_template);
- else if (wflag)
- final_win_template = xstrdup(win_template);
- else
- final_win_template = NULL;
+ if (wflag && sflag) {
+ xasprintf(&final_win_template_middle, " |-> %s", win_template);
+ xasprintf(&final_win_template_last, " \\-> %s", win_template);
+ } else if (wflag) {
+ final_win_template_middle = xstrdup(win_template);
+ final_win_template_last = xstrdup(win_template);
+ } else
+ final_win_template_middle = final_win_template_last = NULL;
idx_ses = cur_win = -1;
RB_FOREACH(s2, sessions, &sessions) {
@@ -169,7 +175,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);
+ ctx, s2, ses_template, (char *)ses_action, idx_ses);
/* If we're just choosing sessions, skip choosing windows. */
if (sflag && !wflag) {
@@ -178,7 +184,9 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
continue;
}
windows_only:
- win_ses = -1;
+ win_ses = win_max = -1;
+ RB_FOREACH(wm, winlinks, &s2->windows)
+ win_max++;
RB_FOREACH(wm, winlinks, &s2->windows) {
win_ses++;
if (sflag && wflag)
@@ -197,11 +205,16 @@ windows_only:
}
xasprintf(&final_win_action, "%s ; %s", win_action,
- wcd ? wcd->command : "");
+ wcd ? wcd->command : "");
+
+ if (win_ses != win_max)
+ cur_win_template = final_win_template_middle;
+ else
+ cur_win_template = final_win_template_last;
window_choose_add_window(wl->window->active,
- ctx, s2, wm, final_win_template,
- final_win_action, idx_ses);
+ ctx, s2, wm, cur_win_template,
+ final_win_action, idx_ses);
free(final_win_action);
}
@@ -212,7 +225,8 @@ windows_only:
if (wflag && !sflag)
break;
}
- free(final_win_template);
+ 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);