aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-14 12:14:17 +0200
committeruser <user@clank>2026-08-14 12:14:17 +0200
commit1ceafa4d82bdc37449c174a75fcd38b4be880080 (patch)
tree33c2904620ac1e5477eb1b8d387bff00ba3f2157 /tests
parentsl0ppty: one-shot --headless printed a blank screen (diff)
downloadslosh-1ceafa4d82bdc37449c174a75fcd38b4be880080.tar.gz
slosh-1ceafa4d82bdc37449c174a75fcd38b4be880080.tar.xz
slosh-1ceafa4d82bdc37449c174a75fcd38b4be880080.zip
sl0ppty: the pane title is a name — double-click it to rename
The top row was both the frame's drag handle and its top edge: resting on it armed the split guide, and a click that never moved split upward. That is right for a border and wrong for the cells the title sits on, because it left no gesture free for naming a pane — a double-click there split twice. So the title text carves its own hit region out of the top row. It is registered after the row's handle and after the title is painted, which is what makes it correct: hit_test scans backwards, so the region that wins is the one whose glyphs the user can actually see, and its width comes from screen_text's return so a title of wide characters claims the cells it drew. Resting there arms nothing (draw_split_guide matches "title:" exactly), and a press takes no side, so the click-splits path — now guarded on a side being set — does nothing. Dragging still moves the pane: that reads as grabbing it by its name. Everything else on the top row still splits upward. Renaming happens in the title cell itself. There is no dialog to place, nothing to dismiss, and the pane it belongs to cannot be in doubt. It is the finder's shape: state on app_t, a key handler that owns the keyboard while it is open, drawn by the pass that draws the frame. Enter keeps the name, Escape abandons it, clicking away keeps it the way leaving a field does. A typed name shadows the program's title rather than overwriting it. The program's OSC 2 keeps arriving underneath, so a shell that rewrites its title cannot undo a rename, and clearing the name gives the pane back to what the program calls itself *now* rather than to whatever it happened to say when the rename began. That is the whole reason pane_t grew a second string instead of a flag. Backspace deletes a character rather than a byte — a title is whatever a program could set, and half a UTF-8 sequence is not a name — and a name too long for the frame scrolls its head off, because the caret is the one thing that has to stay visible. double_click_ms (400) joins hover_delay_ms in the config. The tests keep a control beside each behaviour, since most of these could pass by breaking something else: two slow clicks must open no editor, the top edge must still split, keystrokes must not reach the shell, and a pane closing mid-rename must give the keyboard back.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pane_title.py339
1 files changed, 339 insertions, 0 deletions
diff --git a/tests/test_pane_title.py b/tests/test_pane_title.py
new file mode 100644
index 0000000..07ec1ce
--- /dev/null
+++ b/tests/test_pane_title.py
@@ -0,0 +1,339 @@
+#!/usr/bin/env python3
+"""The pane title is a name, not an edge.
+
+The top row is the frame's drag handle *and* its top edge: resting on it arms
+a split guide and clicking it splits upward. That is right for the border, and
+wrong for the cells the title is painted on — a double-click there is meant to
+rename the pane, and it would split twice on its way to the rename.
+
+So the title text carves its own region out of the top row. It still drags and
+still focuses; it just no longer suggests or performs a split. Everything the
+rest of the top row does must keep working, which is most of what is checked
+here.
+"""
+import sys
+import time
+
+from harness import Session, check, report
+
+SH = ["/bin/sh", "-c", 'printf "\\033]2;shell\\007"; stty raw -echo; cat']
+
+HEAVY = "\u2501" # the armed top edge of the split guide
+CURSOR = "\u2588" # the rename editor's caret
+
+
+def hover(s, x, y):
+ s.send(rf"\e[<35;{x + 1};{y + 1}M")
+
+
+def rest(s, x, y):
+ """The guide arms on dwell (250ms), not on contact."""
+ hover(s, x, y)
+ time.sleep(0.35)
+
+
+def click(s, x, y):
+ s.send(rf"\e[<0;{x + 1};{y + 1}M")
+ s.send(rf"\e[<0;{x + 1};{y + 1}m")
+
+
+def title_span(snap, pane):
+ """(first, last, middle) columns of the title text on the pane's top row."""
+ row = snap.line(pane["y"])
+ x = row.find(" shell ")
+ assert x >= 0, f"no title in top row: {row!r}"
+ return x, x + 6, x + 3
+
+
+def off_title(pane):
+ """A top-row cell the centered title cannot reach."""
+ return pane["x"] + 2
+
+
+def col_of(snap, pane, text):
+ """Middle column of `text` on the pane's top row."""
+ row = snap.line(pane["y"])
+ x = row.find(text)
+ assert x >= 0, f"{text!r} not in {row!r}"
+ return x + len(text) // 2
+
+
+def dbl(s, x, y):
+ s.click(x, y)
+ s.click(x, y)
+
+
+def open_editor(s, pane, text="shell"):
+ dbl(s, col_of(s.snapshot(), pane, text), pane["y"])
+ s.settle(80)
+
+
+def backspace(s, n):
+ for _ in range(n):
+ s.send(r"\x7f")
+
+
+def titles(s):
+ return [p["title"] for p in s.panes()]
+
+
+def test_the_title_text_is_its_own_region():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ snap = s.snapshot()
+ first, last, mid = title_span(snap, p)
+
+ check("the title text hit-tests as the pane's name",
+ snap.hit_at(mid, p["y"]) == f"panetitle:{p['id']}",
+ str(snap.hit_at(mid, p["y"])))
+ check("both its ends do too",
+ snap.hit_at(first, p["y"]) == f"panetitle:{p['id']}"
+ and snap.hit_at(last, p["y"]) == f"panetitle:{p['id']}",
+ f"{snap.hit_at(first, p['y'])} .. {snap.hit_at(last, p['y'])}")
+ check("the cell just outside it is still the top edge",
+ snap.hit_at(first - 1, p["y"]) == f"title:{p['id']}",
+ str(snap.hit_at(first - 1, p["y"])))
+ check("and so is the rest of the top row",
+ snap.hit_at(off_title(p), p["y"]) == f"title:{p['id']}",
+ str(snap.hit_at(off_title(p), p["y"])))
+
+
+def test_resting_on_the_title_arms_no_guide():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ _, _, mid = title_span(s.snapshot(), p)
+
+ rest(s, mid, p["y"])
+ s.settle(60)
+ check("resting on the title suggests no split",
+ HEAVY not in s.snapshot().line(p["y"]),
+ repr(s.snapshot().line(p["y"])))
+
+ # The control: the same dwell two cells away must still arm it, or the
+ # check above would pass simply because the guide is broken.
+ rest(s, off_title(p), p["y"])
+ s.settle(60)
+ check("resting on the top edge still does",
+ HEAVY in s.snapshot().line(p["y"]),
+ repr(s.snapshot().line(p["y"])))
+
+
+def test_clicking_the_title_does_not_split():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ _, _, mid = title_span(s.snapshot(), p)
+
+ click(s, mid, p["y"])
+ s.settle(80)
+ check("clicking the title splits nothing", len(s.panes()) == 1,
+ str(len(s.panes())))
+
+ click(s, off_title(p), p["y"])
+ s.settle(80)
+ check("clicking the top edge still splits up", len(s.panes()) == 2,
+ str(len(s.panes())))
+
+
+def test_double_clicking_the_title_does_not_split():
+ """The gesture the exclusion exists for: it must survive both halves."""
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ _, _, mid = title_span(s.snapshot(), p)
+
+ click(s, mid, p["y"])
+ click(s, mid, p["y"])
+ s.settle(80)
+ check("a double-click on the title leaves one pane",
+ len(s.panes()) == 1, str(len(s.panes())))
+
+
+def test_the_title_still_drags_the_pane():
+ with Session(SH, cols=70, rows=16) as s:
+ s.settle()
+ s.key("\\\\")
+ s.settle()
+ left, right = s.panes()
+ _, _, mid = title_span(s.snapshot(), left)
+
+ # press on the left pane's *title text*, move onto the right pane
+ s.send(rf"\e[<0;{mid + 1};{left['y'] + 1}M")
+ s.send(rf"\e[<32;{right['x'] + 5};{right['y'] + 3}M")
+ s.settle(60)
+ s.send(rf"\e[<0;{right['x'] + 5};{right['y'] + 3}m")
+ s.settle()
+
+ panes = {p["id"]: p for p in s.panes()}
+ check("dragging by the title still moves the pane",
+ len(panes) == 2
+ and panes[left["id"]]["x"] > panes[right["id"]]["x"],
+ str([(p["id"], p["x"]) for p in s.panes()]))
+
+
+def test_hovering_the_title_still_focuses():
+ with Session(SH, cols=70, rows=16) as s:
+ s.settle()
+ s.key("\\\\")
+ s.settle()
+ left, right = s.panes()
+ focused = s.focused()["id"]
+ other = left if focused == right["id"] else right
+ _, _, mid = title_span(s.snapshot(), other)
+
+ hover(s, mid, other["y"])
+ s.settle(60)
+ check("hovering the title still focuses its pane",
+ s.focused()["id"] == other["id"],
+ f"{s.focused()['id']} != {other['id']}")
+
+
+def test_double_click_opens_an_editor_seeded_with_the_name():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ row = s.snapshot().line(p["y"])
+ check("double-clicking the title opens an editor", CURSOR in row,
+ repr(row))
+ check("seeded with the current name, so a rename is an edit",
+ "shell" + CURSOR in row, repr(row))
+
+
+def test_enter_keeps_the_new_name():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ backspace(s, 5)
+ s.send("api")
+ s.send(r"\r")
+ s.settle(80)
+ check("Enter commits the new name", titles(s) == ["api"], str(titles(s)))
+ check("and the editor is gone",
+ CURSOR not in s.snapshot().line(p["y"]),
+ repr(s.snapshot().line(p["y"])))
+
+
+def test_escape_abandons_it():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ backspace(s, 5)
+ s.send("discarded")
+ s.send(r"\e")
+ s.settle(80)
+ check("Escape leaves the old name alone", titles(s) == ["shell"],
+ str(titles(s)))
+ check("and closes the editor",
+ CURSOR not in s.snapshot().line(p["y"]),
+ repr(s.snapshot().line(p["y"])))
+
+
+def test_clicking_away_keeps_the_name():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ backspace(s, 5)
+ s.send("elsewhere")
+ s.click(p["content_x"] + 2, p["content_y"] + 1)
+ s.settle(80)
+ check("clicking away commits, the way leaving a field does",
+ titles(s) == ["elsewhere"], str(titles(s)))
+
+
+def test_a_typed_name_outranks_the_program():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ backspace(s, 5)
+ s.send("mine")
+ s.send(r"\r")
+ s.settle(80)
+
+ s.raw(r"\e]2;prog-later\x07")
+ s.settle(120)
+ check("the program retitling itself does not undo a rename",
+ titles(s) == ["mine"], str(titles(s)))
+
+ # Clearing the name hands the pane back — to what the program calls
+ # itself *now*, not what it said when the rename began.
+ open_editor(s, p, "mine")
+ backspace(s, 8)
+ s.send(r"\r")
+ s.settle(80)
+ check("an empty name returns the pane to its program's title",
+ titles(s) == ["prog-later"], str(titles(s)))
+
+
+def test_slow_clicks_are_not_a_double_click():
+ """The control for the gesture: two clicks are not automatically a rename."""
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ x = col_of(s.snapshot(), p, "shell")
+ s.click(x, p["y"])
+ s.settle(80)
+ time.sleep(0.6) # default double_click_ms is 400
+ s.click(x, p["y"])
+ s.settle(80)
+ row = s.snapshot().line(p["y"])
+ check("two slow clicks open no editor", CURSOR not in row, repr(row))
+ check("and still split nothing", len(s.panes()) == 1,
+ str(len(s.panes())))
+
+
+def test_typing_a_name_does_not_reach_the_pane():
+ with Session(SH, cols=60, rows=14) as s:
+ s.settle()
+ p = s.pane()
+ open_editor(s, p)
+ backspace(s, 5)
+ s.send("zzz")
+ s.send(r"\r")
+ s.settle(120)
+ body = s.snapshot().pane_text(s.pane())
+ check("the editor owns the keyboard: nothing leaked to the shell",
+ "zzz" not in body, repr(body))
+
+
+def test_closing_the_pane_does_not_wedge_the_keyboard():
+ with Session(SH, cols=70, rows=16) as s:
+ s.settle()
+ s.key("\\\\")
+ s.settle()
+ left, right = s.panes()
+ target = left if not left["focused"] else right
+ open_editor(s, target)
+ s.api("close", id=target["id"])
+ s.settle(80)
+ check("the pane is gone", len(s.panes()) == 1, str(len(s.panes())))
+ # If the rename still owned the keyboard, this would be swallowed.
+ s.send("after")
+ s.settle(120)
+ body = s.snapshot().pane_text(s.pane())
+ check("and the keyboard went back to the surviving pane",
+ "after" in body, repr(body))
+
+
+if __name__ == "__main__":
+ test_the_title_text_is_its_own_region()
+ test_resting_on_the_title_arms_no_guide()
+ test_clicking_the_title_does_not_split()
+ test_double_clicking_the_title_does_not_split()
+ test_the_title_still_drags_the_pane()
+ test_hovering_the_title_still_focuses()
+ test_double_click_opens_an_editor_seeded_with_the_name()
+ test_enter_keeps_the_new_name()
+ test_escape_abandons_it()
+ test_clicking_away_keeps_the_name()
+ test_a_typed_name_outranks_the_program()
+ test_slow_clicks_are_not_a_double_click()
+ test_typing_a_name_does_not_reach_the_pane()
+ test_closing_the_pane_does_not_wedge_the_keyboard()
+ sys.exit(report())