This teaches the list/choose windows command to accept -F, and in doing so,
add #{window_panes} to return the total number of panes for a window.
---
 trunk/cmd-choose-window.c |   41 ++++++++++++++++++-----------------------
 trunk/cmd-list-windows.c  |   12 ++----------
 trunk/format.c            |    1 +
 3 files changed, 21 insertions(+), 33 deletions(-)

diff --git a/trunk/cmd-choose-window.c b/trunk/cmd-choose-window.c
index c89425a..9b82c5a 100644
--- a/trunk/cmd-choose-window.c
+++ b/trunk/cmd-choose-window.c
@@ -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]",
+       "t:F:", 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);
diff --git a/trunk/cmd-list-windows.c b/trunk/cmd-list-windows.c
index 0da6dfe..e745f2d 100644
--- a/trunk/cmd-list-windows.c
+++ b/trunk/cmd-list-windows.c
@@ -84,18 +84,10 @@ cmd_list_windows_session(
        if (template == NULL) {
                switch (type) {
                case 0:
-                       template = "#{window_index}: "
-                           "#{window_name} "
-                           "[#{window_width}x#{window_height}] "
-                           "[layout #{window_layout}] #{window_id}"
-                           "#{?window_active, (active),}";
+                       template = DEFAULT_WINDOW_TEMPLATE;
                        break;
                case 1:
-                       template = "#{session_name}:#{window_index}: "
-                           "#{window_name} "
-                           "[#{window_width}x#{window_height}] "
-                           "[layout #{window_layout}] #{window_id}"
-                           "#{?window_active, (active),}";
+                       template = "#{session_name}:" DEFAULT_WINDOW_TEMPLATE;
                        break;
                }
        }
diff --git a/trunk/format.c b/trunk/format.c
index eb32be0..b6c5858 100644
--- a/trunk/format.c
+++ b/trunk/format.c
@@ -349,6 +349,7 @@ format_winlink(struct format_tree *ft, struct session *s, 
struct winlink *wl)
        format_add(ft, "window_flags", "%s", flags);
        format_add(ft, "window_layout", "%s", layout);
        format_add(ft, "window_active", "%d", wl == s->curw);
+       format_add(ft, "window_panes", "%u", window_count_panes(w));
 
        xfree(flags);
        xfree(layout);
-- 
1.7.10


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to