From 2fef10b9ac926de223e0e88b2d77489e983f62e5 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 5 May 2017 11:59:47 +0000 Subject: [PATCH] Add some formats to look at the session window stack, suggested by Scott ROCHFORD. --- format.c | 67 +++++++++++++++++++++++++++++++++++++++----------------- tmux.1 | 2 ++ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/format.c b/format.c index 133ab779..b64af61e 100644 --- a/format.c +++ b/format.c @@ -42,25 +42,6 @@ typedef void (*format_cb)(struct format_tree *, struct format_entry *); static char *format_job_get(struct format_tree *, const char *); static void format_job_timer(int, short, void *); -static void format_cb_host(struct format_tree *, struct format_entry *); -static void format_cb_host_short(struct format_tree *, - struct format_entry *); -static void format_cb_pid(struct format_tree *, struct format_entry *); -static void format_cb_session_alerts(struct format_tree *, - struct format_entry *); -static void format_cb_window_layout(struct format_tree *, - struct format_entry *); -static void format_cb_window_visible_layout(struct format_tree *, - struct format_entry *); -static void format_cb_start_command(struct format_tree *, - struct format_entry *); -static void format_cb_current_command(struct format_tree *, - struct format_entry *); -static void format_cb_history_bytes(struct format_tree *, - struct format_entry *); -static void format_cb_pane_tabs(struct format_tree *, - struct format_entry *); - static char *format_find(struct format_tree *, const char *, int); static void format_add_cb(struct format_tree *, const char *, format_cb); static void format_add_tv(struct format_tree *, const char *, @@ -126,6 +107,7 @@ struct format_entry { /* Format entry tree. */ struct format_tree { struct window *w; + struct winlink *wl; struct session *s; struct window_pane *wp; @@ -416,7 +398,7 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe) { struct session *s = ft->s; struct winlink *wl; - char alerts[256], tmp[16]; + char alerts[1024], tmp[16]; if (s == NULL) return; @@ -440,6 +422,48 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe) fe->value = xstrdup(alerts); } +/* Callback for session_stack. */ +static void +format_cb_session_stack(struct format_tree *ft, struct format_entry *fe) +{ + struct session *s = ft->s; + struct winlink *wl; + char result[1024], tmp[16]; + + if (s == NULL) + return; + + xsnprintf(result, sizeof result, "%u", s->curw->idx); + TAILQ_FOREACH(wl, &s->lastw, sentry) { + xsnprintf(tmp, sizeof tmp, "%u", wl->idx); + + if (*result != '\0') + strlcat(result, ",", sizeof result); + strlcat(result, tmp, sizeof result); + } + fe->value = xstrdup(result); +} + +/* Callback for window_stack_index. */ +static void +format_cb_window_stack_index(struct format_tree *ft, struct format_entry *fe) +{ + struct session *s = ft->wl->session; + struct winlink *wl; + u_int idx; + + idx = 0; + TAILQ_FOREACH(wl, &s->lastw, sentry) { + idx++; + if (wl == ft->wl) + break; + } + if (wl != NULL) + xasprintf(&fe->value, "%u", idx); + else + fe->value = xstrdup("0"); +} + /* Callback for window_layout. */ static void format_cb_window_layout(struct format_tree *ft, struct format_entry *fe) @@ -1200,6 +1224,7 @@ format_defaults_session(struct format_tree *ft, struct session *s) format_add(ft, "session_many_attached", "%d", s->attached > 1); format_add_cb(ft, "session_alerts", format_cb_session_alerts); + format_add_cb(ft, "session_stack", format_cb_session_stack); } /* Set default format keys for a client. */ @@ -1286,10 +1311,12 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl) if (ft->w == NULL) ft->w = wl->window; + ft->wl = wl; format_defaults_window(ft, w); format_add(ft, "window_index", "%d", wl->idx); + format_add_cb(ft, "window_stack_index", format_cb_window_stack_index); format_add(ft, "window_flags", "%s", window_printable_flags(wl)); format_add(ft, "window_active", "%d", wl == s->curw); diff --git a/tmux.1 b/tmux.1 index 23a28a1f..39e8d0df 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3586,6 +3586,7 @@ The following variables are available, where appropriate: .It Li "session_id" Ta "" Ta "Unique session ID" .It Li "session_many_attached" Ta "" Ta "1 if multiple clients attached" .It Li "session_name" Ta "#S" Ta "Name of session" +.It Li "session_stack" Ta "" Ta "Window indexes in most recent order" .It Li "session_width" Ta "" Ta "Width of session" .It Li "session_windows" Ta "" Ta "Number of windows in session" .It Li "socket_path" Ta "" Ta "Server socket path" @@ -3605,6 +3606,7 @@ The following variables are available, where appropriate: .It Li "window_name" Ta "#W" Ta "Name of window" .It Li "window_panes" Ta "" Ta "Number of panes in window" .It Li "window_silence_flag" Ta "" Ta "1 if window has silence alert" +.It Li "window_stack_index" Ta "" Ta "Index in session most recent stack" .It Li "window_visible_layout" Ta "" Ta "Window layout description, respecting zoomed window panes" .It Li "window_width" Ta "" Ta "Width of window" .It Li "window_zoomed_flag" Ta "" Ta "1 if window is zoomed"