diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-05-22 11:35:38 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-05-22 11:35:38 +0000 |
commit | 78cd304b7b07161637cb18551d43b87d7e1f7be4 (patch) | |
tree | ad6f80162d80948362de9d2484e783186a92d6e0 /usr.bin/tmux/cmd-choose-window.c | |
parent | 1a47989e1c6a692ac3c72e02286e5f1fcafc90da (diff) |
Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.
Diffstat (limited to 'usr.bin/tmux/cmd-choose-window.c')
-rw-r--r-- | usr.bin/tmux/cmd-choose-window.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/usr.bin/tmux/cmd-choose-window.c b/usr.bin/tmux/cmd-choose-window.c index e6d09b8acc8..f20c82ac4fd 100644 --- a/usr.bin/tmux/cmd-choose-window.c +++ b/usr.bin/tmux/cmd-choose-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-window.c,v 1.18 2011/01/04 00:42:46 nicm Exp $ */ +/* $OpenBSD: cmd-choose-window.c,v 1.19 2012/05/22 11:35:37 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -33,8 +33,8 @@ void cmd_choose_window_free(void *); const struct cmd_entry cmd_choose_window_entry = { "choose-window", NULL, - "t:", 0, 1, - CMD_TARGET_WINDOW_USAGE " [template]", + "F:t:", 0, 1, + CMD_TARGET_WINDOW_USAGE " [-F format] [template]", 0, NULL, NULL, @@ -54,10 +54,10 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct cmd_choose_window_data *cdata; struct session *s; struct winlink *wl, *wm; - struct window *w; + struct format_tree *ft; + const char *template; + char *line; u_int idx, cur; - char *flags, *title; - const char *left, *right; if (ctx->curclient == NULL) { ctx->error(ctx, "must be run interactively"); @@ -71,30 +71,25 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) return (0); + if ((template = args_get(args, 'F')) == NULL) + template = DEFAULT_WINDOW_TEMPLATE; + cur = idx = 0; RB_FOREACH(wm, winlinks, &s->windows) { - w = wm->window; - if (wm == s->curw) cur = idx; idx++; - flags = window_printable_flags(s, wm); - title = w->active->screen->title; - if (wm == wl) - title = w->active->base.title; - left = " \""; - right = "\""; - if (*title == '\0') - left = right = ""; - - window_choose_add(wl->window->active, - wm->idx, "%3d: %s%s [%ux%u] (%u panes%s)%s%s%s", - wm->idx, w->name, flags, w->sx, w->sy, window_count_panes(w), - w->active->fd == -1 ? ", dead" : "", - left, title, right); - - xfree(flags); + ft = format_create(); + format_add(ft, "line", "%u", idx); + format_session(ft, s); + format_winlink(ft, s, wm); + + line = format_expand(ft, template); + window_choose_add(wl->window->active, idx, "%s", line); + + xfree(line); + format_free(ft); } cdata = xmalloc(sizeof *cdata); |