Add a loop_index variable and use it to show last used 5 sessions on the

session menu instead of next/previous.
This commit is contained in:
nicm
2026-06-19 16:25:43 +00:00
parent f06d930445
commit 624db256c6
3 changed files with 21 additions and 33 deletions

View File

@@ -1842,15 +1842,6 @@ format_cb_keypad_flag(struct format_tree *ft)
return (NULL);
}
/* Callback for loop_last_flag. */
static void *
format_cb_loop_last_flag(struct format_tree *ft)
{
if (ft->flags & FORMAT_LAST)
return (xstrdup("1"));
return (xstrdup("0"));
}
/* Callback for mouse_all_flag. */
static void *
format_cb_mouse_all_flag(struct format_tree *ft)
@@ -3331,9 +3322,6 @@ static const struct format_table_entry format_table[] = {
{ "last_window_index", FORMAT_TABLE_STRING,
format_cb_last_window_index
},
{ "loop_last_flag", FORMAT_TABLE_STRING,
format_cb_loop_last_flag
},
{ "mouse_all_flag", FORMAT_TABLE_STRING,
format_cb_mouse_all_flag
},
@@ -4668,7 +4656,7 @@ format_loop_sessions(struct format_expand_state *es, const char *fmt)
struct evbuffer *buffer;
size_t size;
struct session *s, **l;
int i, n, last = 0;
int i, n;
if (format_choose(es, fmt, &all, &active, 0) != 0) {
all = xstrdup(fmt);
@@ -4689,9 +4677,9 @@ format_loop_sessions(struct format_expand_state *es, const char *fmt)
use = active;
else
use = all;
if (i == n - 1)
last = FORMAT_LAST;
nft = format_create(c, item, FORMAT_NONE, ft->flags|last);
nft = format_create(c, item, FORMAT_NONE, ft->flags);
format_add(nft, "loop_index", "%d", i);
format_add(nft, "loop_last_flag", "%d", i == n - 1);
format_defaults(nft, ft->c, s, NULL, NULL);
format_copy_state(&next, es, 0);
next.ft = nft;
@@ -4783,7 +4771,7 @@ format_loop_windows(struct format_expand_state *es, const char *fmt)
size_t size;
struct winlink *wl, **l;
struct window *w;
int i, n, last = 0;
int i, n;
if (ft->s == NULL) {
format_log(es, "window loop but no session");
@@ -4808,10 +4796,10 @@ format_loop_windows(struct format_expand_state *es, const char *fmt)
use = active;
else
use = all;
if (i == n - 1)
last = FORMAT_LAST;
nft = format_create(c, item, FORMAT_WINDOW|w->id,
ft->flags|last);
ft->flags);
format_add(nft, "loop_index", "%d", i);
format_add(nft, "loop_last_flag", "%d", i == n - 1);
format_defaults(nft, ft->c, ft->s, wl, NULL);
/* Add neighbor window data to the format tree. */
@@ -4858,7 +4846,7 @@ format_loop_panes(struct format_expand_state *es, const char *fmt)
struct evbuffer *buffer;
size_t size;
struct window_pane *wp, **l;
int i, n, last = 0;
int i, n;
if (ft->w == NULL) {
format_log(es, "pane loop but no window");
@@ -4882,10 +4870,10 @@ format_loop_panes(struct format_expand_state *es, const char *fmt)
use = active;
else
use = all;
if (i == n - 1)
last = FORMAT_LAST;
nft = format_create(c, item, FORMAT_PANE|wp->id,
ft->flags|last);
ft->flags);
format_add(nft, "loop_index", "%d", i);
format_add(nft, "loop_last_flag", "%d", i == n - 1);
format_defaults(nft, ft->c, ft->s, ft->wl, wp);
format_copy_state(&next, es, 0);
next.ft = nft;
@@ -4920,7 +4908,7 @@ format_loop_clients(struct format_expand_state *es, const char *fmt)
char *expanded, *value;
struct evbuffer *buffer;
size_t size;
int i, n, last = 0;
int i, n;
buffer = evbuffer_new();
if (buffer == NULL)
@@ -4930,9 +4918,9 @@ format_loop_clients(struct format_expand_state *es, const char *fmt)
for (i = 0; i < n; i++) {
c = l[i];
format_log(es, "client loop: %s", c->name);
if (i == n - 1)
last = FORMAT_LAST;
nft = format_create(c, item, 0, ft->flags|last);
nft = format_create(c, item, 0, ft->flags);
format_add(nft, "loop_index", "%d", i);
format_add(nft, "loop_last_flag", "%d", i == n - 1);
format_defaults(nft, c, ft->s, ft->wl, ft->wp);
format_copy_state(&next, es, 0);
next.ft = nft;