diff options
| author | user <user@clank> | 2026-09-10 15:40:09 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-09-10 15:40:09 +0200 |
| commit | 9c5b3319ac4d9a63404fe0cf0d55320754c982ba (patch) | |
| tree | 28e0020a92a55512120467d698bcc09a95e8e17a /tests | |
| parent | build: a vendor bump rebuilds libghostty-vt, everywhere it is consumed (diff) | |
| download | slosh-9c5b3319ac4d9a63404fe0cf0d55320754c982ba.tar.gz slosh-9c5b3319ac4d9a63404fe0cf0d55320754c982ba.tar.xz slosh-9c5b3319ac4d9a63404fe0cf0d55320754c982ba.zip | |
tabs: the strip can stand on its side (tab_bar_side left/right)
A sidebar lists one tab per row down the chosen edge, tab_bar_width
columns wide; the panes trade the strip's row for the sidebar's columns
in tab_area(), the one place that arithmetic lives. The per-tab cell
drawing is extracted from draw_tab_strip (label, rename editor, bell,
hover, drop states, hit) and shared, so every mouse verb -- click,
double-click rename, drag to a tab, drop on + -- works in both shapes
because the hits move with the cells.
The strip's indicators (pane count, prefix badge) take the sidebar's
bottom rows, reserved first under the same budgeting rule the strip
applies from the right. The status line below keeps the full width. A
terminal too narrow to give up the columns falls back to top, re-derived
per frame, so a resize moves the bar without anyone storing state.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_tab_bar.py | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/test_tab_bar.py b/tests/test_tab_bar.py new file mode 100644 index 0000000..5f466e1 --- /dev/null +++ b/tests/test_tab_bar.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +"""The tab bar on its side: tab_bar_side left / right. + +A sidebar lists one tab per row down the chosen edge and the panes give up +its columns instead of the top row. The strip's indicators (pane count, the +prefix badge) move to the sidebar's bottom rows, the `+` sits on the row +after the last tab, and every mouse verb keeps working because the hits move +with the cells. A terminal too narrow to give up the columns falls back to +the top strip until it grows. +""" + +import sys +import tempfile + +from harness import Session, check, report + + +def _cfg(text): + f = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False) + f.write(text) + f.close() + return f.name + + +W = 18 +LEFT = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\n') +RIGHT = _cfg(f'tab_bar_side "right"\ntab_bar_width {W}\n') + +SH = ["/bin/sh", "-c", "stty raw -echo; cat"] + + +def test_left_sidebar_reserves_columns(): + with Session(SH, cols=90, rows=20, config=LEFT) as s: + s.settle(30) + snap = s.snapshot() + # gap 1 (the default): the sidebar's first row is row 1, like the strip. + check( + "the first tab is a row in the sidebar", + snap.hit_at(1, 1) == "tab:1", + str(snap.hit_at(1, 1)), + ) + check( + "the whole row is the target, not just the label", + snap.hit_at(W - 1, 1) == "tab:1", + str(snap.hit_at(W - 1, 1)), + ) + check( + "the + sits on the row after the last tab", + snap.hit_at(1, 2) == "newtab", + str(snap.hit_at(1, 2)), + ) + p = s.pane(0) + check("panes give up the sidebar's columns", p["x"] >= W, str(p["x"])) + # rows 20, status line on 19: the count takes the sidebar's last row. + check( + "the pane count moved to the sidebar's bottom", + "1 pane" in snap.line(18)[:W], + repr(snap.line(18)[:W]), + ) + + +def test_sidebar_rows_click_like_the_strip(): + with Session(SH, cols=90, rows=20, config=LEFT) as s: + s.settle(30) + s.click(1, 2) # the + row: a new tab, which becomes the active one + s.until(lambda _: len(s.tabs()) == 2) + check("the + row makes a tab", len(s.tabs()) == 2, str(len(s.tabs()))) + check("...and it is the one you are in", s.tabs()[1]["active"], str(s.tabs())) + snap = s.snapshot() + check( + "the new tab is the next row down", + snap.hit_at(1, 2) == "tab:2", + str(snap.hit_at(1, 2)), + ) + s.click(1, 1) # the first tab's row + s.until(lambda _: s.tabs()[0]["active"]) + check("clicking a row selects that tab", s.tabs()[0]["active"], str(s.tabs())) + + +def test_right_sidebar_takes_the_other_edge(): + with Session(SH, cols=90, rows=20, config=RIGHT) as s: + s.settle(30) + snap = s.snapshot() + x0 = 90 - W + check( + "the first tab is a row on the right edge", + snap.hit_at(x0 + 1, 1) == "tab:1", + str(snap.hit_at(x0 + 1, 1)), + ) + p = s.pane(0) + check( + "panes stop where the sidebar starts", + p["x"] + p["w"] <= x0, + f"{p['x']}+{p['w']} vs {x0}", + ) + + +def test_narrow_terminal_falls_back_to_top(): + # 40 < width + min_pane cols + 4: the sidebar would leave no room for the + # pane it is chrome for, so the strip goes back to the top row. + with Session(SH, cols=40, rows=20, config=LEFT) as s: + s.settle(30) + snap = s.snapshot() + check( + "the strip is a top row again", + snap.hit_at(5, 1) == "tab:1", + str(snap.hit_at(5, 1)), + ) + p = s.pane(0) + check("and the panes keep the columns", p["x"] < W, str(p["x"])) + + +def test_growing_back_restores_the_sidebar(): + with Session(SH, cols=40, rows=20, config=LEFT) as s: + s.settle(30) + s.resize(90, 20) + s.until(lambda snap: snap.hit_at(1, 1) == "tab:1") + check( + "a resize moves the bar without anyone storing state", + s.snapshot().hit_at(1, 1) == "tab:1", + str(s.snapshot().hit_at(1, 1)), + ) + p = s.pane(0) + check("and the panes give the columns back", p["x"] >= W, str(p["x"])) + + +if __name__ == "__main__": + test_left_sidebar_reserves_columns() + test_sidebar_rows_click_like_the_strip() + test_right_sidebar_takes_the_other_edge() + test_narrow_terminal_falls_back_to_top() + test_growing_back_restores_the_sidebar() + sys.exit(report()) |
