diff options
| author | user <user@clank> | 2026-08-16 20:34:29 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-16 20:34:29 +0200 |
| commit | 967d8521c2b021457f33bf87ef762100a5e2a74c (patch) | |
| tree | e1d0d4b7214e2595c37d06d70d4590cfaf6e26af /tests | |
| parent | sl0ppty: layouts are `*.layout.kdl`, and each loader says which it got (diff) | |
| download | slosh-967d8521c2b021457f33bf87ef762100a5e2a74c.tar.gz slosh-967d8521c2b021457f33bf87ef762100a5e2a74c.tar.xz slosh-967d8521c2b021457f33bf87ef762100a5e2a74c.zip | |
sl0ppty: `C-a Enter` splits the longer way
One key for "I want a pane and I have no opinion about where". It cuts across the
pane's longer side, so the two halves come out as square as the pane allows, and
pressing it four times on a 100x30 terminal tiles the tab the way you would have
done it by hand: a column, then rows inside the new column, then rows again, then
a word saying there is no room left.
"Longer" is a question about what you can *see*. A cell is about twice as tall as
it is wide, so 80x24 is a wide pane (80 against 48) while 40x24 is not (40 against
48). `gap_aspect` is already this program's answer to how many columns a row is
worth, so that is the number used rather than a second constant meaning the same
thing -- and a config that says cells are square gets a square answer. There is a
test at 74x44, the size where the two readings disagree: square cells split it into
columns, the default splits it into rows.
The fallback is the other half of "sensible". A pane that is wide but ten rows tall
wants cutting across; if `split_fits` says that will not fit, the other axis is
tried before giving up. And it says which way it went -- `split right` or `split
down`, the same two words the border click already uses -- because one key that can
do two things has to tell you which it did.
**`split_fits` had a hole this action made obvious.** It only ever asked about the
dimension being divided, so a pane four rows tall on a short terminal "had room" for
two columns: the width was fine, and the two panes it produced were immediately
collapsed into a list by the layout. The border was offering that, and both split
keys were doing it. It now also requires the axis it does *not* divide to clear the
floor, because splitting cannot improve that one -- the same hole `layout_node`
closed at the leaf, one level up. On a 100x8 terminal all three now say "no room to
split" instead of undoing the arrangement.
Verified: nine checks in `tests/test_split_ux.py` -- the axis chosen for wide and
for tall panes, the aspect deciding at 74x44, both fallback directions, the refusal
and that the explicit keys refuse the same way, and that it appears on the
cheatsheet under `enter` and in the palette by name. The existing 65 checks about
what the border offers still pass, which is what I was most worried about.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_split_ux.py | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/tests/test_split_ux.py b/tests/test_split_ux.py index e1b9942..398ca7e 100644 --- a/tests/test_split_ux.py +++ b/tests/test_split_ux.py @@ -402,6 +402,143 @@ def test_the_arrow_sits_on_the_new_boundary(): pos is not None and pos[0] == p["x"] + p["w"] // 2, str(pos)) +# ---- `C-a Enter`: split whichever way there is room for ----------------------- + + +def geometry(s): + return [(p["x"], p["y"], p["w"], p["h"]) + for p in sorted(s.panes(), key=lambda q: (q["y"], q["x"]))] + + +def toast_line(s): + got = [l.strip() for l in s.snapshot().text + if "split right" in l or "split down" in l or "no room" in l] + return got[-1] if got else "" + + +def test_it_splits_across_the_longer_side(): + """Longer as you *see* it: a cell is about twice as tall as it is wide, so a + 100x24 terminal is a wide pane and wants cutting into columns, while 60x40 is a + tall one and wants rows. `gap_aspect` is the number that says so.""" + with Session(SH, cols=100, rows=24) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("a wide pane splits into columns", len(g) == 2 and g[0][1] == g[1][1], + str(g)) + check("side by side, evenly", g[0][2] == g[1][2], str(g)) + check("and it says which way it went", toast_line(s) == "split right", + repr(toast_line(s))) + + with Session(SH, cols=60, rows=40) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("a tall pane splits into rows", len(g) == 2 and g[0][0] == g[1][0], + str(g)) + check("one above the other", g[1][1] > g[0][1], str(g)) + check("and says so", toast_line(s) == "split down", repr(toast_line(s))) + + +def test_the_aspect_is_the_configured_one(): + """`gap_aspect` is already this program's answer to how many columns a row is + worth, so it is the number that decides "longer" -- one knob, one answer, rather + than a second constant meaning the same thing. + + 74x44 is the case that proves it: the pane is about 72x40, which is wider than it + is tall in *cells* and taller than it is wide once a row counts double. Square + cells split it into columns; the default splits it into rows. + """ + square = cfg("gap_aspect 1\n") + with Session(SH, cols=74, rows=44, config=square) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("with square cells, 72x40 splits into columns", + len(g) == 2 and g[0][1] == g[1][1], str(g)) + with Session(SH, cols=74, rows=44) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("...and with the default aspect, the same pane splits into rows", + len(g) == 2 and g[0][0] == g[1][0], str(g)) + os.unlink(square) + + +def test_it_falls_back_to_the_axis_that_fits(): + """The point of the action: on a pane that is wide but short the longer side is + across, and if that does not fit the other one is tried before giving up.""" + # 150x14: the pane is 146x10 -- wide, so columns are preferred, and two columns + # of 73 clear `min_split cols=32`. Rows would not (10 rows cannot make two of 8). + with Session(SH, cols=150, rows=14) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("wide and short splits into columns", g[0][1] == g[1][1], str(g)) + + # 40x50: the pane is 36x46 -- tall, so rows, and 46 makes two of 8 easily while + # 36 columns cannot make two of 32. + with Session(SH, cols=40, rows=50) as s: + s.settle() + s.key(r"\r") + s.settle(60) + g = geometry(s) + check("narrow and tall splits into rows", g[0][0] == g[1][0], str(g)) + check("...even though columns is what a naive cell count would pick", + g[1][1] > g[0][1], str(g)) + + +def test_no_room_says_so_rather_than_collapsing_the_tab(): + """A pane already under the floor cannot be split into two panes worth having by + either axis -- and `split_fits` used to say yes, because it only asked about the + dimension it was dividing. The answer was two panes the layout immediately + collapsed into a list, from an action that was offered.""" + with Session(SH, cols=100, rows=8) as s: + s.settle() + before = geometry(s) + s.key(r"\r") + s.settle(60) + check("nothing was split", geometry(s) == before, + "%s -> %s" % (before, geometry(s))) + check("and it says why", toast_line(s) == "no room to split", + repr(toast_line(s))) + + # The explicit keys answer the same way, because whether there is room cannot + # depend on which key you asked with. + with Session(SH, cols=100, rows=8) as s: + s.settle() + before = geometry(s) + s.key("\\\\") + s.settle(60) + check("`C-a \\` refuses it too", geometry(s) == before, str(geometry(s))) + check("...in its own words", "no room to split across" in s.snapshot().screen(), + repr(s.snapshot().screen()[-100:])) + + +def test_it_is_on_the_sheet_and_in_the_palette(): + with Session(SH, cols=100, rows=30) as s: + s.settle() + s.send(r"\x01?") + s.settle(60) + sheet = s.snapshot().screen() + check("the sheet lists it", "split the longer way" in sheet, + repr([l.strip() for l in s.snapshot().text if "longer" in l])) + check("under Enter", "enter" in sheet.lower(), "") + s.send(r"\e") + s.settle(40) + s.send(r"\x01p") + s.settle(40) + s.send("longer") + s.settle(60) + check("and the palette finds it", "split the longer way" in s.snapshot().screen(), + repr([l.strip() for l in s.snapshot().text if "longer" in l])) + + if __name__ == "__main__": test_no_more_plus() test_each_border_splits_toward_itself() @@ -418,4 +555,9 @@ if __name__ == "__main__": test_the_keyboard_obeys_the_same_floor() test_the_guide_says_which_way_it_goes() test_the_arrow_sits_on_the_new_boundary() + test_it_splits_across_the_longer_side() + test_the_aspect_is_the_configured_one() + test_it_falls_back_to_the_axis_that_fits() + test_no_room_says_so_rather_than_collapsing_the_tab() + test_it_is_on_the_sheet_and_in_the_palette() sys.exit(report()) |
