aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-22 13:14:24 +0200
committeruser <user@clank>2026-09-22 13:14:24 +0200
commit24bfcc26df376621ccfe1e695bb4f5e6f1807e56 (patch)
tree911a7f6f08c79d5685116f0073d428c697a32a8f
parentthemes: ask the binary where it is, not the prefix it was built for (diff)
downloadslosh-24bfcc26df376621ccfe1e695bb4f5e6f1807e56.tar.gz
slosh-24bfcc26df376621ccfe1e695bb4f5e6f1807e56.tar.xz
slosh-24bfcc26df376621ccfe1e695bb4f5e6f1807e56.zip
sidebar: the tab number at the far edge (tab_bar_index)
`1:api` puts a number at the start of every row, and in a sidebar that is a column of digits in front of the thing you are actually reading -- the names start one, two or three cells in depending on how many tabs you have, and the numbers are only wanted at the moment you reach for C-a 2. tab_bar_index "right" moves them: │ tests 1 │ │ 1:tests │ │ verylongproj 2 │ vs │ 2:verylongproje│ │ api 3 │ │ 3:api │ Every name starts in the same column and the numbers line up in one of their own, which costs a column of sidebar and buys the list a shape. "prefix" stays the default, because it is what the strip has always drawn and the strip is where most people meet it. Sidebars only, and not by omission: a tab in the top strip is exactly as wide as its label, so there is no far end to align against and a number floating after a name it does not belong to would be worse than the prefix it replaced. The setting is ignored there rather than half-honoured. A row too narrow to spare the columns (under the number plus five) also keeps the prefix, since the name is the part you came for, and the rename editor keeps the whole cell as it always did. A name long enough to reach the number stops one cell short of it, because `verylongproje2` is a tab called verylongproje2 as far as any reader can tell. The cell comes back as padding, so the plate is unbroken and the hit is still the whole row -- clicking the number is clicking the tab, and the number brightens with the label under the pointer rather than leaving half a row lit. The bell mark keeps its place between them, budgeted first as before, so a long name cannot eat either of the two things that are not the name.
-rw-r--r--config/config.kdl8
-rw-r--r--docs/config.md2
-rw-r--r--docs/panes.md19
-rw-r--r--docs/slosh.58
-rw-r--r--include/config.h16
-rw-r--r--src/app_draw.c70
-rw-r--r--src/config.c16
-rw-r--r--tests/test_tab_bar.py105
8 files changed, 233 insertions, 11 deletions
diff --git a/config/config.kdl b/config/config.kdl
index 147b709..47473f0 100644
--- a/config/config.kdl
+++ b/config/config.kdl
@@ -283,6 +283,14 @@ bell_mark "[!]"
// The one-row bar with tabs, the new-tab button and the pane count.
status_bar true
+// Where a tab's number sits. "prefix" writes it against the name (`1:api`);
+// "right" puts it at the far end of the row, so every name starts in the same
+// column and the numbers line up in one of their own -- which a sidebar has
+// room for and the top strip has not, a tab there being exactly as wide as
+// its label. Sidebars only for that reason, and a row too narrow to spare the
+// columns keeps the prefix: the name is the part you came for.
+tab_bar_index "prefix"
+
// The line along the bottom: which session and tab you are in, what the
// focused pane calls itself, and whether it is in a state worth knowing about
// - scrolled back, on an alternate screen, or not started yet. On the right it
diff --git a/docs/config.md b/docs/config.md
index 506cbff..0065781 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -134,7 +134,7 @@ whatever the file says.
| group | what is in it |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| geometry | `gap` `gap_aspect` `padding` `compact` `rounded` `title_align` `title_inset` `min_pane` `min_split` |
-| chrome | `status_bar` `status_line` `status_pad` `tab_bar_side` `tab_bar_width` `tab_bar_pad` `tab_gap` `tab_bar_status` `tab_bar_status_lines` `tab_bar_chrome` `hints` `version_banner` `pane_buttons` `bell_indicator` `newtab_button` `newtab_pad` and the marks (`zoom_mark` `zoom_on_mark` `close_mark` `min_mark` `newtab_mark` `bell_mark`) |
+| chrome | `status_bar` `status_line` `status_pad` `tab_bar_side` `tab_bar_index` `tab_bar_width` `tab_bar_pad` `tab_gap` `tab_bar_status` `tab_bar_status_lines` `tab_bar_chrome` `hints` `version_banner` `pane_buttons` `bell_indicator` `newtab_button` `newtab_pad` and the marks (`zoom_mark` `zoom_on_mark` `close_mark` `min_mark` `newtab_mark` `bell_mark`) |
| behaviour | `focus_follows_mouse` `ctrl_d_exits` `scroll_lines` `scrollback` `scrollback_bytes` `toast_ms` `splash_ms` `hover_delay_ms` `double_click_ms` `word_separators` `anim_ms` `modal_scrim` `dim_unfocused` `float_shadow` `keep_dead` `in_band_shaders` `multi_attach` `attach_indicator` `size_follows` `shell` `editor` |
| projects | `project_roots` `project_layout` (see [workspaces](workspaces.md)) |
| colour | `theme { }` |
diff --git a/docs/panes.md b/docs/panes.md
index 6062280..3a28046 100644
--- a/docs/panes.md
+++ b/docs/panes.md
@@ -55,6 +55,7 @@ The strip of tabs sits along the top by default. It does not have to:
```kdl
tab_bar_side "left" // or "right"; "top" is the default
tab_bar_width 18 // columns the sidebar takes
+tab_bar_index "right" // the tab number at the far end, not against the name
tab_bar_pad 0 // blank rows above the first tab
tab_gap 0 // ...and between one tab and the next
tab_bar_chrome true // frame it like a pane
@@ -126,6 +127,24 @@ yours wins; the band is unset by default, which leaves a translucent
terminal's own background alone. The top strip has one row and no room for any of this, which is half of
why the sidebar exists.
+**The tab number can sit at the far end of the row.** `tab_bar_index "right"`
+draws `api` on the left and `3` hard against the right edge, instead of the
+default `3:api`:
+
+```
+│ tests 1 │ │ 1:tests │
+│ verylongproj 2 │ vs │ 2:verylongproje│
+│ api 3 │ │ 3:api │
+```
+
+Every name then starts in the same column and the numbers line up in one of
+their own, which is worth a column of a sidebar and is not available to the top
+strip at all — a tab there is exactly as wide as its label, so it has no far end
+to align against, and the setting is ignored. A row too narrow to spare the
+columns goes back to the prefix, because the name is the part you came for, and
+a name long enough to reach the number always stops one cell short of it:
+`verylongproje2` is a tab called verylongproje2 as far as any reader can tell.
+
**Every tab is a plate, not a word on the background.** The one you are in is
filled with the accent (`tab_active_bg`); the rest sit on `tab_idle_bg`, 43% of
the way from the theme's background to `tab_idle`, the grey it writes their
diff --git a/docs/slosh.5 b/docs/slosh.5
index ed7c0ad..ff8b386 100644
--- a/docs/slosh.5
+++ b/docs/slosh.5
@@ -135,6 +135,14 @@ The strip's indicators move to the sidebar's bottom rows; the status line
keeps the full width. A terminal too narrow to give up the columns falls
back to \fBtop\fR until it grows.
.TP
+.BI tab_bar_index\ where
+Where a tab's number sits: \fBprefix\fR (the default) writes it against the
+name, \fB1:api\fR, and \fBright\fR puts it at the far end of the row so the
+names all start in one column and the numbers line up in another.
+Sidebars only \(em a tab in the top strip is as wide as its label, so there
+is no far end to align against \(em and a row too narrow to spare the columns
+keeps the prefix, since the name is the part you came for.
+.TP
.BI tab_bar_chrome\ bool
Frame a sidebar the way panes are framed, so it reads as part of the chrome
rather than as text floating beside it. Under
diff --git a/include/config.h b/include/config.h
index 25fcc41..92f33a1 100644
--- a/include/config.h
+++ b/include/config.h
@@ -122,6 +122,15 @@ enum {
TAB_BAR_RIGHT,
};
+/* tab_bar_index: where a tab's number sits. `prefix` is `1:api`, the number
+ * against the name; `right` puts it at the far end of the row, which only a
+ * sidebar has -- the top strip's tabs are as wide as their labels, so there
+ * is no "far end" to put anything at. */
+enum {
+ TAB_INDEX_PREFIX = 0,
+ TAB_INDEX_RIGHT,
+};
+
/* size_follows: which attached client sizes the shared screen. */
enum {
SIZE_FOLLOWS_ACTIVE = 0, /* newest attach, then last input */
@@ -349,6 +358,13 @@ typedef struct {
* untouched and keeps the full width either way. */
int tab_bar_side; /* TAB_BAR_* */
uint16_t tab_bar_width; /* columns a sidebar takes; ignored for top */
+ /* Where a tab's number goes (TAB_INDEX_*). A sidebar row is wider than the
+ * name on it, and `1:api` spends the start of every row on a number nobody
+ * reads until they want to press it -- against the right edge the names all
+ * start in the same column and the numbers line up as their own column.
+ * Ignored on the top strip, where a tab is only as wide as its label and
+ * there is no room to align anything in. */
+ int tab_bar_index;
/* Rows a sidebar leaves blank above its first tab. Air for anyone who finds
* a list starting in the very corner cramped -- or room for a terminal's
* own window buttons when the multiplexer fills a borderless window.
diff --git a/src/app_draw.c b/src/app_draw.c
index a8b40f5..85b5b6c 100644
--- a/src/app_draw.c
+++ b/src/app_draw.c
@@ -1831,28 +1831,57 @@ static uint16_t draw_tab_cell(app_t *a, screen_t *s, size_t i, uint16_t x,
/* A pane that rang in a tab you are not looking at is invisible without
* this, and that is the case the whole indicator exists for. */
bool rang = CFG.bell_indicator && tab_has_bell(t);
- if (nm[0])
- snprintf(label, sizeof label, " %zu:%s ", i + 1, nm);
- else
- snprintf(label, sizeof label, " %zu ", i + 1);
/* Renaming: the tab's own cell becomes the editor, in the editor's
* colours, so a half-typed name can never be mistaken for the tab's real
* one. The caret is part of the label, so the width below — and therefore
* the hit — is the width of what is actually drawn. */
bool editing = a->renaming == RENAME_TAB && a->rename_id == t->id;
- if (editing) snprintf(label, sizeof label, " %s\u2588 ", a->rename_buf);
- /* A pinned width cuts the label to fit -- bell budgeted first, so the mark
- * survives the longest name -- and then pads it out, so the active fill and
- * the hover read as the whole row rather than as the word on it. */
+ /* The number at the far end instead of in front of the name (`tab_bar_index
+ * "right"`). Only a sidebar has a far end -- a strip tab is as wide as its
+ * label, and there is nothing to align against -- and only when the row can
+ * spare the columns: on a narrow one the name is what you came for, so the
+ * number goes back in front where it costs two cells rather than a column.
+ * Never while renaming, where the whole cell is the editor. */
+ char idx[16] = "";
+ bool right_idx = false;
+ if (max_w && !editing && CFG.tab_bar_index == TAB_INDEX_RIGHT) {
+ snprintf(idx, sizeof idx, "%zu ", i + 1);
+ uint16_t iw = (uint16_t)cells(idx);
+ right_idx = max_w >= (uint16_t)(iw + 5);
+ if (!right_idx) idx[0] = 0;
+ }
+
+ if (editing)
+ snprintf(label, sizeof label, " %s\u2588 ", a->rename_buf);
+ else if (right_idx)
+ snprintf(label, sizeof label, " %s", nm[0] ? nm : "");
+ else if (nm[0])
+ snprintf(label, sizeof label, " %zu:%s ", i + 1, nm);
+ else
+ snprintf(label, sizeof label, " %zu ", i + 1);
+
+ /* A pinned width cuts the label to fit -- bell and number budgeted first,
+ * so neither is what a long name eats -- and then pads it out, so the
+ * active fill and the hover read as the whole row rather than as the word
+ * on it. */
if (max_w) {
uint16_t budget = max_w;
if (rang) {
uint16_t bw = (uint16_t)(cells(CFG.bell_mark) + 1);
budget = budget > bw ? (uint16_t)(budget - bw) : 0;
}
- while (label[0] && cells(label) > budget) {
+ if (right_idx) {
+ uint16_t iw = (uint16_t)cells(idx);
+ budget = budget > iw ? (uint16_t)(budget - iw) : 0;
+ }
+ /* A name long enough to reach the number has to stop one cell short of
+ * it: `verylongproje2` is a tab called verylongproje2, and the reader has
+ * no way to know otherwise. The cell comes back as padding below, so the
+ * plate is still unbroken. */
+ uint16_t cut = right_idx && budget ? (uint16_t)(budget - 1) : budget;
+ while (label[0] && cells(label) > cut) {
size_t len = strlen(label);
do len--;
while (len && (label[len] & 0xc0) == 0x80); /* whole UTF-8 sequences */
@@ -1892,10 +1921,27 @@ static uint16_t draw_tab_cell(app_t *a, screen_t *s, size_t i, uint16_t x,
active ? TAB_ACTIVE_BG : TAB_IDLE_BG,
ATTR_BOLD));
}
+ /* The number, after whatever the label and the bell took, which is where
+ * the row's right edge now is. Drawn in the tab's own colours rather than
+ * in the sidebar's counting grey: it is part of the tab, and a number in a
+ * third colour would read as a third thing on the row. */
+ if (*idx)
+ w = (uint16_t)(w + screen_text(s, (uint16_t)(x + w), y, idx,
+ active ? TAB_ACTIVE_FG : TAB_IDLE,
+ active ? TAB_ACTIVE_BG : TAB_IDLE_BG,
+ attrs));
+
uint16_t hit_w = max_w ? max_w : w;
- if (!editing && ptr_on(a, x, y, hit_w, 1))
+ if (!editing && ptr_on(a, x, y, hit_w, 1)) {
screen_text(s, x, y, label, active ? TAB_ACTIVE_HOVER_FG : TAB_HOVER,
active ? TAB_ACTIVE_BG : TAB_IDLE_BG, attrs | ATTR_BOLD);
+ /* The number brightens with the label: hovering half a row and leaving
+ * the other half dim would read as two things, one of them lit. */
+ if (*idx)
+ screen_text(s, (uint16_t)(x + hit_w - cells(idx)), y, idx,
+ active ? TAB_ACTIVE_HOVER_FG : TAB_HOVER,
+ active ? TAB_ACTIVE_BG : TAB_IDLE_BG, attrs | ATTR_BOLD);
+ }
/* While a pane is in your hand, every tab it does not already live in is
* somewhere it could go, and `ptr_on` says nothing during a drag by design --
@@ -1909,6 +1955,10 @@ static uint16_t draw_tab_cell(app_t *a, screen_t *s, size_t i, uint16_t x,
bool on = a->drag.tab_target == t->id;
screen_text(s, x, y, label, on ? TAB_ACTIVE_HOVER_FG : DROP_C,
on ? DROP_C : NO_COLOR, attrs | ATTR_BOLD);
+ if (*idx)
+ screen_text(s, (uint16_t)(x + hit_w - cells(idx)), y, idx,
+ on ? TAB_ACTIVE_HOVER_FG : DROP_C, on ? DROP_C : NO_COLOR,
+ attrs | ATTR_BOLD);
}
}
char action[48];
diff --git a/src/config.c b/src/config.c
index 4e60652..1297856 100644
--- a/src/config.c
+++ b/src/config.c
@@ -951,6 +951,7 @@ void config_defaults(config_t *c) {
c->modal_scrim = 120;
c->status_bar = true;
c->tab_bar_side = TAB_BAR_TOP;
+ c->tab_bar_index = TAB_INDEX_PREFIX;
/* Wide enough for " 12:a-real-name " plus a bell; narrow enough that a
* 100-column terminal keeps a working layout beside it. */
c->tab_bar_width = 18;
@@ -1709,6 +1710,10 @@ char *config_render(const config_t *c) {
c->tab_bar_side == TAB_BAR_LEFT ? "left"
: c->tab_bar_side == TAB_BAR_RIGHT ? "right"
: "top");
+ cb_add(&b,
+ "tab_bar_index \"%s\" // 1:name, or the number at the sidebar's far "
+ "edge\n",
+ c->tab_bar_index == TAB_INDEX_RIGHT ? "right" : "prefix");
cb_add(&b, "tab_bar_width %u // columns a sidebar takes\n",
c->tab_bar_width);
cb_add(&b, "tab_bar_pad %u // blank rows above a sidebar's tabs\n",
@@ -2195,6 +2200,7 @@ static const char *const KNOWN_TOP[] = {
"status_pad",
"tab_bar_chrome",
"tab_bar_pad",
+ "tab_bar_index",
"tab_bar_side",
"tab_bar_status",
"tab_bar_status_lines",
@@ -2593,6 +2599,16 @@ static bool load_into(config_t *c, const char *path, int depth, char *err,
c->rounded = kdl_arg_bool(kdl_child(root, "rounded"), 0, c->rounded);
c->compact = kdl_arg_bool(kdl_child(root, "compact"), 0, c->compact);
c->status_bar = kdl_arg_bool(kdl_child(root, "status_bar"), 0, c->status_bar);
+ const char *tbidx = kdl_arg(kdl_child(root, "tab_bar_index"), 0, NULL);
+ if (tbidx) {
+ if (strcmp(tbidx, "prefix") == 0)
+ c->tab_bar_index = TAB_INDEX_PREFIX;
+ else if (strcmp(tbidx, "right") == 0)
+ c->tab_bar_index = TAB_INDEX_RIGHT;
+ else
+ complain(c, err, errcap, kdl_child(root, "tab_bar_index")->line,
+ "tab_bar_index is \"prefix\" or \"right\", not \"%s\"", tbidx);
+ }
const char *tbside = kdl_arg(kdl_child(root, "tab_bar_side"), 0, NULL);
if (tbside) {
if (strcmp(tbside, "top") == 0)
diff --git a/tests/test_tab_bar.py b/tests/test_tab_bar.py
index d7ff86f..fca4742 100644
--- a/tests/test_tab_bar.py
+++ b/tests/test_tab_bar.py
@@ -158,6 +158,105 @@ def _status(s, text):
s.settle(30)
+RIGHT_IDX = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_index "right"\n')
+
+
+def test_the_index_can_sit_at_the_far_end():
+ """`tab_bar_index "right"`: names all start in one column, numbers line up
+ in another. A sidebar row is wider than the name on it, and the prefix
+ spends the start of every row on a number nobody reads until they want to
+ press it."""
+ with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
+ s.settle(30)
+ s.api("new-tab", name="api")
+ s.settle(30)
+ rows = [_row(snap := s.snapshot(), Y0), _row(snap, Y0 + 1)]
+ check(
+ "the number is against the right edge",
+ [r.rstrip()[-1] for r in rows] == ["1", "2"],
+ str(rows),
+ )
+ check(
+ "...and every name starts in the same column",
+ rows[1].index("api") == rows[0].index("tests"),
+ str(rows),
+ )
+ check("no prefix is left behind", "1:" not in rows[0], str(rows))
+
+
+def test_a_long_name_stops_short_of_the_number():
+ """Otherwise `verylongproje2` is a tab called verylongproje2, and nothing
+ on the row says otherwise."""
+ with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
+ s.settle(30)
+ s.api("new-tab", name="verylongprojectname")
+ s.settle(30)
+ row = _row(s.snapshot(), Y0 + 1)
+ check("the number survived the long name", row.rstrip()[-1] == "2", repr(row))
+ check(
+ "...with a cell of air before it",
+ row.rstrip()[-2] == " ",
+ repr(row),
+ )
+ check("and the row is still one plate wide", len(row) == CW, repr(row))
+
+
+def test_a_narrow_row_keeps_the_prefix():
+ """The name is the part you came for: at eight columns there is nothing to
+ align and the number goes back in front, where it costs two cells."""
+ narrow = _cfg('tab_bar_side "left"\ntab_bar_width 8\ntab_bar_index "right"\n')
+ with Session(SH, cols=90, rows=20, config=narrow) as s:
+ s.settle(30)
+ row = s.snapshot().line(Y0)[1:7]
+ check("the prefix is back", "1:" in row, repr(row))
+
+
+def test_the_top_strip_ignores_it():
+ """A strip tab is as wide as its label, so there is no far end to align
+ against -- and a number floating after a name it does not belong to would
+ be worse than the prefix it replaced."""
+ top = _cfg('tab_bar_index "right"\n')
+ with Session(SH, cols=60, rows=10, config=top) as s:
+ s.settle(30)
+ check(
+ "the strip still writes 1:name",
+ "1:tests" in s.snapshot().screen(),
+ s.snapshot().line(1),
+ )
+
+
+def test_the_whole_row_is_still_one_door():
+ with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
+ s.settle(30)
+ s.api("new-tab", name="api")
+ s.settle(30)
+ snap = s.snapshot()
+ at_name = snap.hit_at(CX + 1, Y0 + 1)
+ at_number = snap.hit_at(CX + CW - 2, Y0 + 1)
+ check(
+ "clicking the number is clicking the tab",
+ at_name and at_name == at_number,
+ f"{at_name} vs {at_number}",
+ )
+ st = snap.style_at(CX + CW - 2, Y0 + 1)
+ check(
+ "and the number sits on the tab's own plate",
+ st and st["bg"] == (snap.style_at(CX + 1, Y0 + 1) or {}).get("bg"),
+ str(st),
+ )
+
+
+def test_a_bad_index_mode_is_a_line_and_no_more():
+ bad = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_index "middle"\n')
+ with Session(SH, cols=90, rows=20, config=bad) as s:
+ s.settle(30)
+ check(
+ "the session runs, with the default",
+ "1:tests" in s.snapshot().screen(),
+ _row(s.snapshot(), Y0),
+ )
+
+
def test_every_tab_sits_on_a_plate():
"""The tab you are in is the accent; the others are `tab_idle_bg`. The
quiet fill is what gives a tab edges -- and what the active fill is
@@ -858,6 +957,12 @@ if __name__ == "__main__":
test_sidebar_rows_click_like_the_strip()
test_right_sidebar_takes_the_other_edge()
test_pad_pushes_the_list_down()
+ test_the_index_can_sit_at_the_far_end()
+ test_a_long_name_stops_short_of_the_number()
+ test_a_narrow_row_keeps_the_prefix()
+ test_the_top_strip_ignores_it()
+ test_the_whole_row_is_still_one_door()
+ test_a_bad_index_mode_is_a_line_and_no_more()
test_every_tab_sits_on_a_plate()
test_an_old_theme_gets_an_idle_plate_in_its_own_family()
test_a_theme_can_have_the_bare_tabs_back()