aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-16 19:25:52 +0200
committeruser <user@clank>2026-08-16 19:25:52 +0200
commit503b309187eaf0bc7282dd09e93c695dba11abb5 (patch)
tree420112d1b9ea8416375b7f0cd0b4777ee8137599 /tests
parentsl0ppty: a pane can change tabs (diff)
downloadslosh-503b309187eaf0bc7282dd09e93c695dba11abb5.tar.gz
slosh-503b309187eaf0bc7282dd09e93c695dba11abb5.tar.xz
slosh-503b309187eaf0bc7282dd09e93c695dba11abb5.zip
sl0ppty: `C-a >` sends this pane to the next tab
C-a > push it to the tab after C-a b into a tab of its own C-a < push it to the tab before Three actions rather than three special cases in the key handler, which is what puts them in the cheatsheet and the palette without another line of code -- and the palette is where you find a thing you did not know to look for. You do not follow the pane, and a toast says where it went: "moved to tab 2 (api)". A key you might press twice needs to say what it did, and following would take you away from what you were doing. The tab's *name* is read before the move and its *number* after: emptying this tab removes it and shifts everything along, so the number read first is not the number anybody will see. When the tab you were in is the one that goes, you arrive in the survivor because there is nowhere to stay. `>` and `<` are the shifted period and comma, and the defaults bind both halves -- a terminal does not report shift for punctuation, so `>` arrives as a bare period the way `?` arrives as a bare slash. The config loader already did this for a chord you write by hand; the defaults had to do it themselves. The cost is that `.` and `,` are spoken for, which is the cost `/` already pays for `?`. `b` is for break out, the word tmux taught everybody for this. **Two things the tests caught, both mine.** `panes` reported a pane's tab as an index while every command that takes a tab wants an id -- and my own test conflated them, passing only because the two agree until a tab is removed, which is half of what these keys do. There is now a `tab_id` beside the `tab`: one is where it sits in the strip, the other is what you pass back. And three more rows overflowed the cheatsheet: `modal_frame` clamps the box to the screen, so at 56x44 the `session` group was simply not drawn. The sheet now says `+7 more, in docs/keys.md` when it cannot show everything -- counted by walking the rows it skipped, because arithmetic on two uneven columns claimed six were hidden on a screen showing all of them. A list that quietly stops is worse than a short one: the reader cannot tell that the key they wanted was on it. Reflowing to two columns when the height forces it would be better than a footnote, and is not this commit. Verified: `tests/test_move_pane.py` at 38 checks -- the keys in both directions, breaking out, the refusal when there is only one tab, pushing the last pane out and landing in the survivor, and that the sheet prints `>` rather than the bare period it also answers to while the palette finds it by label. `tests/test_help.py` gained the short-terminal case and lost an assumption about its own fixture height.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_help.py5
-rwxr-xr-xtests/test_move_pane.py133
2 files changed, 129 insertions, 9 deletions
diff --git a/tests/test_help.py b/tests/test_help.py
index d4300bd..765bff2 100644
--- a/tests/test_help.py
+++ b/tests/test_help.py
@@ -78,7 +78,10 @@ def modal_top(snap):
def test_sections_are_separated_by_a_blank_line():
"""Five short lists rather than one wall of rows. The line above a heading
is blank -- except the first, which the caption already separates."""
- with Session(SH, cols=56, rows=44) as s: # narrow: one column, easy to read
+ # Narrow, so one column and easy to read -- and tall enough for all of it,
+ # because this is about the spacing between groups and not about what a short
+ # terminal does with the overflow (which is checked below).
+ with Session(SH, cols=56, rows=56) as s:
s.settle()
snap = open_help(s)
text = [l for l in snap.text if "│" in l]
diff --git a/tests/test_move_pane.py b/tests/test_move_pane.py
index d77e18b..fda17ab 100755
--- a/tests/test_move_pane.py
+++ b/tests/test_move_pane.py
@@ -26,10 +26,14 @@ def cfg(text):
def by_tab(s):
- """Which panes are in which tab, by id."""
+ """Which panes are in which tab, by tab **id**.
+
+ `tab_id`, not `tab`: the latter is where the tab sits in the strip, and the two
+ stop agreeing the moment a tab is removed -- which is half of what this file is
+ about."""
out = {t["id"]: [] for t in s.tabs()}
for p in s.panes():
- out.setdefault(p["tab"], []).append(p["id"])
+ out.setdefault(p["tab_id"], []).append(p["id"])
return {k: sorted(v) for k, v in out.items()}
@@ -89,7 +93,7 @@ def test_it_lands_beside_the_destination_focus():
s.api("select-tab", id=tabs[1])
s.settle(60)
rects = {p["id"]: (p["x"], p["y"], p["w"], p["h"]) for p in s.panes()
- if p["tab"] == tabs[1]}
+ if p["tab_id"] == tabs[1]}
check("both panes are in the destination", len(rects) == 2, str(rects))
check("side by side, the arrival on the right",
rects[mover][0] > rects[host][0], str(rects))
@@ -101,7 +105,7 @@ def test_it_lands_beside_the_destination_focus():
s.api("select-tab", id=tabs[0])
s.settle(60)
rects = {p["id"]: (p["x"], p["y"], p["w"], p["h"]) for p in s.panes()
- if p["tab"] == tabs[0]}
+ if p["tab_id"] == tabs[0]}
check("`rows` puts it underneath",
rects[mover][1] > min(r[1] for r in rects.values()), str(rects))
@@ -194,8 +198,8 @@ def test_a_move_drops_what_the_old_tab_thought():
pane = [p for p in s.panes() if p["id"] == mover][0]
check("it arrives laid out, not filed away", pane["h"] > 1, str(pane))
check("and the tab it left is not zoomed onto a pane that has gone",
- all(p["h"] > 1 for p in s.panes() if p["tab"] == tabs[0]),
- str([p for p in s.panes() if p["tab"] == tabs[0]]))
+ all(p["h"] > 1 for p in s.panes() if p["tab_id"] == tabs[0]),
+ str([p for p in s.panes() if p["tab_id"] == tabs[0]]))
def test_the_layout_survives_a_move():
@@ -208,14 +212,14 @@ def test_the_layout_survives_a_move():
s.settle(40)
for target in (tabs[1], tabs[0], tabs[1]):
- movable = [p["id"] for p in s.panes() if p["tab"] != target]
+ movable = [p["id"] for p in s.panes() if p["tab_id"] != target]
if not movable:
continue
s.api("move-pane", id=movable[0], tab=target)
s.settle(60)
rs = [(p["x"], p["y"], p["w"], p["h"]) for p in s.panes()
- if p["tab"] == [t["id"] for t in s.tabs() if t.get("active")][0]]
+ if p["tab_id"] == [t["id"] for t in s.tabs() if t.get("active")][0]]
for i in range(len(rs)):
for j in range(i + 1, len(rs)):
ax, ay, aw, ah = rs[i]
@@ -237,6 +241,114 @@ def test_the_layout_survives_a_move():
os.unlink(path)
+def test_the_keys_push_a_pane_a_tab_along():
+ """`C-a >` and `C-a <`, and a word about where it went -- you do not follow it,
+ and a key that might have done nothing is a key you press again."""
+ with Session(ECHO, cols=90, rows=16) as s:
+ tabs = two_tabs(s)
+ s.until_text("alive")
+ s.api("select-tab", id=tabs[0])
+ s.settle(40)
+ watching = [t["id"] for t in s.tabs() if t.get("active")]
+ moved = [p["id"] for p in s.panes()
+ if p["tab_id"] == tabs[0] and p["focused"]][0]
+
+ s.key(">")
+ s.settle(60)
+ check("`C-a >` moves the focused pane to the next tab",
+ moved in by_tab(s)[tabs[1]], str(by_tab(s)))
+ check("and says where it went", "moved to tab" in s.snapshot().screen(),
+ repr(s.snapshot().screen()[-120:]))
+ check("without following it",
+ [t["id"] for t in s.tabs() if t.get("active")] == watching,
+ str([t["id"] for t in s.tabs() if t.get("active")]))
+
+ s.api("select-tab", id=tabs[1])
+ s.api("focus", id=moved)
+ s.settle(40)
+ s.key("<")
+ s.settle(60)
+ check("`C-a <` sends it back the other way",
+ moved in by_tab(s)[tabs[0]], str(by_tab(s)))
+
+
+def test_the_key_for_a_tab_of_its_own():
+ with Session(ECHO, cols=90, rows=16) as s:
+ tabs = two_tabs(s)
+ s.until_text("alive")
+ s.api("select-tab", id=tabs[0])
+ s.settle(40)
+ moved = [p["id"] for p in s.panes()
+ if p["tab_id"] == tabs[0] and p["focused"]][0]
+
+ s.key("b")
+ s.settle(60)
+ made = [t["id"] for t in s.tabs() if t["id"] not in tabs]
+ check("`C-a b` breaks it out into a new tab", len(made) == 1, str(s.tabs()))
+ check("with the pane in it", by_tab(s).get(made[0]) == [moved],
+ str(by_tab(s)))
+ check("and says so", "tab of its own" in s.snapshot().screen(),
+ repr(s.snapshot().screen()[-120:]))
+
+
+def test_one_tab_has_nowhere_to_push_to():
+ """Refused with a word rather than silently: the only tab is the one it is in."""
+ with Session(ECHO, cols=80, rows=14) as s:
+ s.settle()
+ s.key("\\\\")
+ s.settle(40)
+ before = by_tab(s)
+ s.key(">")
+ s.settle(60)
+ check("nothing moved", by_tab(s) == before, "%s -> %s" % (before, by_tab(s)))
+ check("and it says why", "only one tab" in s.snapshot().screen(),
+ repr(s.snapshot().screen()[-120:]))
+
+
+def test_pushing_the_last_pane_out_takes_the_tab_with_it():
+ """The tab you were looking at can be the one that goes. There is nowhere to
+ stay, so you arrive in the tab that survived -- and the toast reads the
+ destination's number *after* the removal, which is the number on screen."""
+ with Session(ECHO, cols=90, rows=16) as s:
+ tabs = two_tabs(s)
+ s.until_text("alive")
+ s.api("select-tab", id=tabs[1]) # the tab with one pane in it
+ s.settle(40)
+ s.key(">")
+ s.settle(60)
+ check("the tab it emptied is gone",
+ [t["id"] for t in s.tabs()] == [tabs[0]], str(s.tabs()))
+ check("all three panes are in the survivor",
+ len(by_tab(s)[tabs[0]]) == 3, str(by_tab(s)))
+ check("and that is what we are looking at",
+ [t["id"] for t in s.tabs() if t.get("active")] == [tabs[0]],
+ str(s.tabs()))
+
+
+def test_the_sheet_and_the_palette_know_about_them():
+ """The palette comes free with an action, which is the reason to make these
+ actions rather than special cases in the key handler. And the cheatsheet has to
+ print `>`, not the bare period it also answers to -- what you would type."""
+ with Session(ECHO, cols=100, rows=30) as s:
+ s.settle()
+ s.key("?")
+ s.settle(60)
+ sheet = s.snapshot().screen()
+ check("the sheet lists pushing a pane along", "tab after" in sheet,
+ repr([l.strip() for l in s.snapshot().text if "tab after" in l]))
+ check("under the key you would type", ">" in sheet, "")
+ s.send("\\x1b")
+ s.settle(40)
+
+ s.key("p")
+ s.settle(40)
+ s.send("tab of its own")
+ s.settle(60)
+ pal = s.snapshot().screen()
+ check("and the palette finds it by its label", "tab of its own" in pal,
+ repr([l.strip() for l in s.snapshot().text if "own" in l]))
+
+
if __name__ == "__main__":
test_a_pane_moves_and_keeps_running()
test_it_lands_beside_the_destination_focus()
@@ -245,4 +357,9 @@ if __name__ == "__main__":
test_the_refusals()
test_a_move_drops_what_the_old_tab_thought()
test_the_layout_survives_a_move()
+ test_the_keys_push_a_pane_a_tab_along()
+ test_the_key_for_a_tab_of_its_own()
+ test_one_tab_has_nowhere_to_push_to()
+ test_pushing_the_last_pane_out_takes_the_tab_with_it()
+ test_the_sheet_and_the_palette_know_about_them()
sys.exit(report())