1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!/usr/bin/env python3
"""`C-a =`: every visible pane gets an even share of the rows and columns.
The interesting part is not the flat case -- three columns nudged apart and put
back is arithmetic -- but what "even" means once the tree has depth. A split is
divided between the *panes behind* each child, so one pane beside a stack of
two is a third of the width and not half of it. Weighting per child would make
"even" mean something different at every depth, which is the layout this action
exists to get away from.
"""
import sys
from harness import Session, check, report
SH = ["/bin/sh", "-c", "stty raw -echo; cat"]
def by_pos(s):
"""Panes on screen, left to right then top to bottom. A minimised pane gets
no rect at all — the strip draws it — so it is not one of these."""
return sorted((p for p in s.panes() if p["w"] > 1), key=lambda p: (p["x"], p["y"]))
def widths(s):
return [p["w"] for p in by_pos(s)]
def test_a_nudged_row_of_columns_goes_back_to_even():
with Session(SH, cols=120, rows=24) as s:
s.settle()
s.key("\\\\")
s.key("\\\\")
s.settle()
even = widths(s)
check("three columns start out even", max(even) - min(even) <= 1, str(even))
for _ in range(4):
s.key("L") # shift+l: move the boundary right
s.settle()
nudged = widths(s)
check(
"nudging the boundary makes them uneven",
max(nudged) - min(nudged) > 2,
str(nudged),
)
s.key("=")
s.settle()
back = widths(s)
check("equalize puts them back to even", max(back) - min(back) <= 1, str(back))
check("and it kept every pane", len(back) == 3, str(back))
def test_it_divides_a_split_between_the_panes_behind_it():
"""A pane beside a stack of two: a third of the width, not half of it."""
with Session(SH, cols=120, rows=30) as s:
s.settle()
s.key("\\\\") # left | right
s.key("-") # right becomes right-top / right-bottom
s.settle()
left, top, bottom = by_pos(s)
check(
"the split starts out halved per child",
abs(left["w"] - top["w"]) <= 1,
f"{left['w']} vs {top['w']}",
)
s.key("=")
s.settle()
left, top, bottom = by_pos(s)
check(
"the stack of two gets twice the lone pane's width",
abs(top["w"] - 2 * left["w"]) <= 2,
f"{left['w']} vs {top['w']}",
)
check(
"the two panes sharing that width still match",
top["w"] == bottom["w"],
f"{top['w']} vs {bottom['w']}",
)
check(
"and they still split their column in half",
abs(top["h"] - bottom["h"]) <= 1,
f"{top['h']} vs {bottom['h']}",
)
check(
"the lone pane still spans the tab",
left["h"] > top["h"],
f"{left['h']} vs {top['h']}",
)
def test_a_minimised_pane_is_not_counted():
"""It is out of the layout and costs a row in the strip, not a share: its
share would otherwise be handed to a pane nobody can see."""
with Session(SH, cols=120, rows=30) as s:
s.settle()
s.key("\\\\")
s.key("-")
s.settle()
top = by_pos(s)[1]
s.api("focus", id=top["id"])
s.key("m")
s.settle()
check("one pane is away in the strip", len(widths(s)) == 2, str(widths(s)))
s.key("=")
s.settle()
seen = widths(s)
check(
"the two on screen share the tab evenly",
max(seen) - min(seen) <= 1,
str(seen),
)
def test_one_pane_has_nothing_to_even_out():
with Session(SH, cols=80, rows=24) as s:
s.settle()
before = s.pane()
s.key("=")
s.settle()
snap = s.snapshot()
check(
"it says so rather than doing nothing quietly",
"nothing to even out" in snap.screen(),
repr(snap.screen()[-200:]),
)
after = s.pane()
check(
"and the pane is untouched",
(after["x"], after["y"], after["w"], after["h"])
== (before["x"], before["y"], before["w"], before["h"]),
str((before, after)),
)
def test_it_is_in_the_palette_and_the_cheatsheet():
# Room for the whole sheet: it is sized from the screen, and a sheet
# clipped at the bottom would make this a test of the box.
with Session(SH, cols=110, rows=40) as s:
s.settle()
s.key("?")
s.settle()
sheet = s.snapshot().screen()
check(
"the cheatsheet lists it under size, with its key",
"= even out every split" in sheet,
repr(sheet[:400]),
)
s.send("q") # any key closes the sheet
s.key("p")
s.send("equalize")
s.settle()
pal = s.snapshot()
check(
"the palette finds it by its config name",
"even out every split" in pal.screen(),
repr(pal.screen()[:400]),
)
check(
"with the key it would have skipped",
"C-a =" in pal.screen(),
repr(pal.screen()[:400]),
)
check(
"and the row runs it",
any(h["action"].startswith("run:") for h in pal.hits),
str([h["action"] for h in pal.hits][:8]),
)
if __name__ == "__main__":
test_a_nudged_row_of_columns_goes_back_to_even()
test_it_divides_a_split_between_the_panes_behind_it()
test_a_minimised_pane_is_not_counted()
test_one_pane_has_nothing_to_even_out()
test_it_is_in_the_palette_and_the_cheatsheet()
sys.exit(report())
|