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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
|
#!/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 subprocess
import sys
import tempfile
from harness import BIN, 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')
BARE = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_chrome false\n')
# With tab_bar_chrome (the default) the frame takes a column each side and a
# row top and bottom: content runs x 1..16, and gap 1 + frame 1 + pad 0 puts
# the first tab on row 2. CX/CW/Y0 are that content box, so a geometry change
# is one edit here rather than thirty coordinates below.
CX, CW, Y0 = 1, W - 2, 2
# The default newtab_pad: one blank row between the last tab and the `+`, so
# a pointer one row low misses the button instead of making a tab.
NT_PAD = 1
SH = ["/bin/sh", "-c", "stty raw -echo; cat"]
# An unnamed tab borrows the basename of its focused pane's cwd, so every row
# below would otherwise read differently depending on where the suite was run
# from -- `tests` under `make test`, `slosh` from the repository root. These
# checks are about padding, alignment and the index, not about that
# derivation, so they name the tab and assert against the name they gave it.
TAB = "tests"
def _named(s):
"""Pin the label, so a row's contents do not depend on the cwd.
By id, because `set-name` takes 0 for the focused *pane* only -- a tab is
named by naming a tab.
"""
s.api("set-name", id=s.tabs()[0]["id"], name=TAB)
def _row(snap, y):
"""The sidebar's content on a row, without the frame either side."""
return snap.line(y)[CX : CX + CW]
def test_left_sidebar_reserves_columns():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
snap = s.snapshot()
check(
"the first tab is a row in the sidebar",
snap.hit_at(CX, Y0) == "tab:1",
str(snap.hit_at(CX, Y0)),
)
check(
"the whole row is the target, not just the label",
snap.hit_at(CX + CW - 1, Y0) == "tab:1",
str(snap.hit_at(CX + CW - 1, Y0)),
)
check(
"the + sits below the last tab, a pad row clear of it",
snap.hit_at(CX, Y0 + 1 + NT_PAD) == "newtab",
str(snap.hit_at(CX, Y0 + 1 + NT_PAD)),
)
check(
"and the air between them is nobody's target",
snap.hit_at(CX, Y0 + 1) is None,
str(snap.hit_at(CX, Y0 + 1)),
)
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 frame's bottom line on 18.
check(
"the pane count moved to the sidebar's bottom",
"1 pane" in _row(snap, 17),
repr(_row(snap, 17)),
)
def test_sidebar_rows_click_like_the_strip():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
# the + row: a new tab, which becomes the active one
s.click(CX, Y0 + 1 + NT_PAD)
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(CX, Y0 + 1) == "tab:2",
str(snap.hit_at(CX, Y0 + 1)),
)
s.click(CX, Y0) # 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 + CX, Y0) == "tab:1",
str(snap.hit_at(x0 + CX, Y0)),
)
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_pad_pushes_the_list_down():
# The default pad is 0, so Y0 is the unpadded first row and a pad of N
# moves the list exactly N rows down it.
n = 3
pad = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_pad {n}\n')
with Session(SH, cols=90, rows=20, config=pad) as s:
s.settle(30)
snap = s.snapshot()
check(
"the pad rows are not targets",
all(snap.hit_at(CX, Y0 + k) is None for k in range(n)),
str([snap.hit_at(CX, Y0 + k) for k in range(n)]),
)
check(
"the first tab starts below the pad",
snap.hit_at(CX, Y0 + n) == "tab:1",
str(snap.hit_at(CX, Y0 + n)),
)
p = s.pane(0)
check(
"the pad is paint, not layout: panes keep their rows",
p["y"] <= 2,
str(p["y"]),
)
def _status(s, text):
"""The focused pane announces a status, the way a program in it would.
`raw`, not `send`. They are different directions: `raw` writes the pane's
pty, where `cat` echoes the bytes back and the pane's own terminal parses
them -- the path a program's output takes. `send` feeds slosh's input
decoder instead, which is the path a keystroke from the outer terminal
takes, and an OSC arriving there is a reply to slosh, not output from the
program. Sent that way the sequence never reaches the pane at all: it is
swallowed by the decoder, the status stays empty, and every check below
fails against the *next tab's label* on the row it expected a status on.
"""
s.raw(rf"\e]5577;1;status;{text}\e\\")
s.settle(30)
# The sidebar's default. LEFT would do as well -- the point of these is the
# alignment, so they say which mode they mean rather than leaning on it.
RIGHT_IDX = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_index "right"\n')
PREFIX_IDX = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_index "prefix"\n')
def test_padding_is_the_air_inside_the_strip():
"""`tab_bar_padding`, the sidebar's own version of `padding` -- in cells,
because a sidebar's rows and columns are doing different jobs."""
padded = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 1 2\n')
with Session(SH, cols=90, rows=20, config=padded) as s:
s.settle(30)
_named(s)
_status(s, "building")
snap = s.snapshot()
check(
"a row of air above the first tab",
not _row(snap, Y0).strip(),
repr(_row(snap, Y0)),
)
label = _row(snap, Y0 + 1)
check("the label is indented by two", label.startswith(f" {TAB}"), repr(label))
check(
"...and the number is held off the other edge",
label.endswith("1 "),
repr(label),
)
check(
"a status keeps the column its label starts in",
_row(snap, Y0 + 2).index("building") == label.index(TAB),
repr(_row(snap, Y0 + 2)),
)
def test_padding_zero_puts_it_against_the_frame():
"""The column the labels have always carried was hard-coded, so there was
no way to ask for none of it."""
flush = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 0\n')
with Session(SH, cols=90, rows=20, config=flush) as s:
s.settle(30)
_named(s)
_status(s, "building")
snap = s.snapshot()
check(
"the name starts in the first column",
_row(snap, Y0).startswith(TAB),
repr(_row(snap, Y0)),
)
check(
"...the number ends in the last",
_row(snap, Y0).endswith("1"),
repr(_row(snap, Y0)),
)
check(
"...and the status follows it",
_row(snap, Y0 + 1).startswith("building"),
repr(_row(snap, Y0 + 1)),
)
def test_the_plate_ignores_the_padding():
"""Air *inside* the fill: the row is the click target, and a highlight that
stopped short of the frame would read as a highlighted word."""
padded = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 0 3\n')
with Session(SH, cols=90, rows=20, config=padded) as s:
s.settle(30)
edge = s.snapshot().style_at(CX, Y0)
mid = s.snapshot().style_at(CX + 4, Y0)
check(
"the active tab's fill reaches the frame",
edge and mid and edge["bg"] == mid["bg"],
f"{edge} vs {mid}",
)
check(
"and the whole row is still the door",
s.snapshot().hit_at(CX, Y0) == "tab:1",
str(s.snapshot().hit_at(CX, Y0)),
)
def test_tab_bar_pad_is_still_the_top_of_it():
"""The older name, kept working: a config that says both means the narrow
one where they overlap."""
both = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 4 1\ntab_bar_pad 1\n'
)
with Session(SH, cols=90, rows=20, config=both) as s:
s.settle(30)
_named(s)
snap = s.snapshot()
check(
"one row of air, not four",
not _row(snap, Y0).strip() and TAB in _row(snap, Y0 + 1),
f"{_row(snap, Y0)!r} / {_row(snap, Y0 + 1)!r}",
)
def test_a_bad_padding_is_a_line_and_no_more():
bad = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 1 2 3\n')
r = subprocess.run([BIN, "--check", bad], capture_output=True, text=True)
check(
"three values is refused, not guessed at",
"1, 2 or 4" in r.stderr,
r.stderr.strip(),
)
def test_the_index_sits_at_the_far_end():
"""The sidebar's default: names all start in one column, numbers line up in
another. A sidebar row is wider than the name on it, and a prefix spends
the start of every row on a number nobody reads until they want to press
it."""
with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
s.settle(30)
_named(s)
s.api("new-tab", name="api")
s.settle(30)
rows = [_row(snap := s.snapshot(), Y0), _row(snap, Y0 + 1)]
check(
"the number is against the right edge",
[r.rstrip()[-1] for r in rows] == ["1", "2"],
str(rows),
)
check(
"...and every name starts in the same column",
rows[1].index("api") == rows[0].index(TAB),
str(rows),
)
check("no prefix is left behind", "1:" not in rows[0], str(rows))
def test_a_long_name_stops_short_of_the_number():
"""Otherwise `verylongproje2` is a tab called verylongproje2, and nothing
on the row says otherwise."""
with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
s.settle(30)
s.api("new-tab", name="verylongprojectname")
s.settle(30)
row = _row(s.snapshot(), Y0 + 1)
check("the number survived the long name", row.rstrip()[-1] == "2", repr(row))
check(
"...with a cell of air before it",
row.rstrip()[-2] == " ",
repr(row),
)
check("and the row is still one plate wide", len(row) == CW, repr(row))
def test_a_narrow_row_keeps_the_prefix():
"""The name is the part you came for: at eight columns there is nothing to
align and the number goes back in front, where it costs two cells."""
narrow = _cfg('tab_bar_side "left"\ntab_bar_width 8\ntab_bar_index "right"\n')
with Session(SH, cols=90, rows=20, config=narrow) as s:
s.settle(30)
row = s.snapshot().line(Y0)[1:7]
check("the prefix is back", "1:" in row, repr(row))
def test_the_top_strip_ignores_it():
"""A strip tab is as wide as its label, so there is no far end to align
against -- and a number floating after a name it does not belong to would
be worse than the prefix it replaced."""
top = _cfg('tab_bar_index "right"\n')
with Session(SH, cols=60, rows=10, config=top) as s:
s.settle(30)
_named(s)
check(
"the strip still writes 1:name",
f"1:{TAB}" in s.snapshot().screen(),
s.snapshot().line(1),
)
def test_the_whole_row_is_still_one_door():
with Session(SH, cols=90, rows=20, config=RIGHT_IDX) as s:
s.settle(30)
s.api("new-tab", name="api")
s.settle(30)
snap = s.snapshot()
at_name = snap.hit_at(CX + 1, Y0 + 1)
at_number = snap.hit_at(CX + CW - 2, Y0 + 1)
check(
"clicking the number is clicking the tab",
at_name and at_name == at_number,
f"{at_name} vs {at_number}",
)
st = snap.style_at(CX + CW - 2, Y0 + 1)
check(
"and the number sits on the tab's own plate",
st and st["bg"] == (snap.style_at(CX + 1, Y0 + 1) or {}).get("bg"),
str(st),
)
def test_the_prefix_is_still_there_for_anyone_who_wants_it():
"""`1:name`, which is what the top strip draws and what the sidebar drew
before the alignment existed."""
with Session(SH, cols=90, rows=20, config=PREFIX_IDX) as s:
s.settle(30)
_named(s)
row = _row(s.snapshot(), Y0)
check(
"the number is in front of the name",
row.strip() == f"1:{TAB}",
repr(row),
)
def test_the_sidebar_aligns_by_default():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
row = _row(s.snapshot(), Y0)
check("no config asked for it", row.rstrip()[-1] == "1", repr(row))
check("...and no prefix came with it", "1:" not in row, repr(row))
def test_a_bad_index_mode_is_a_line_and_no_more():
bad = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_index "middle"\n')
with Session(SH, cols=90, rows=20, config=bad) as s:
s.settle(30)
row = _row(s.snapshot(), Y0)
check("the session runs, with the default", row.rstrip()[-1] == "1", repr(row))
def test_every_tab_sits_on_a_plate():
"""The tab you are in is the accent; the others are `tab_idle_bg`. The
quiet fill is what gives a tab edges -- and what the active fill is
brighter than."""
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
s.api("new-tab")
s.settle(30)
snap = s.snapshot()
idle, active = snap.style_at(CX, Y0), snap.style_at(CX, Y0 + 1)
check("the tab you are not in is filled", idle and idle["bg"], str(idle))
check(
"...in something other than the active tab's fill",
active and active["bg"] != idle["bg"],
f"{idle} vs {active}",
)
end = snap.style_at(CX + CW - 1, Y0)
check(
"and the plate is the whole row, which is the whole hit",
end and end["bg"] == idle["bg"],
str(end),
)
def test_an_old_theme_gets_an_idle_plate_in_its_own_family():
"""Same bargain as the status colours: mixed from two colours the theme
does define rather than one stock colour dropped into its palette."""
bg, idle = "#101020", "#88ff88"
old = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
f'theme {{ default_bg "{bg}"\n tab_idle "{idle}" }}\n'
)
with Session(SH, cols=90, rows=20, config=old) as s:
s.settle(30)
s.api("new-tab")
s.settle(30)
st = s.snapshot().style_at(CX, Y0)
got, a, b = _rgb(st["bg"]), _rgb(bg), _rgb(idle)
check(
"the plate is mixed from the theme's own background and label grey",
all(min(a[i], b[i]) <= got[i] <= max(a[i], b[i]) for i in range(3)),
f"{st['bg']} not between {bg} and {idle}",
)
check(
"...and nearer the background than the label",
sum(abs(got[i] - a[i]) for i in range(3))
< sum(abs(got[i] - b[i]) for i in range(3)),
st["bg"],
)
def test_a_theme_can_have_the_bare_tabs_back():
"""Naming the background is how you say "no plate" -- the knob wins over
the derivation, as every named colour does."""
bare = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
'theme { default_bg "#101020"\n tab_idle_bg "#101020" }\n'
)
with Session(SH, cols=90, rows=20, config=bare) as s:
s.settle(30)
s.api("new-tab")
s.settle(30)
st = s.snapshot().style_at(CX, Y0)
check("the named colour is the one drawn", st["bg"] == "#101020", str(st))
def test_status_rows_sit_under_their_tab():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
pane = s.pane(0)["id"]
_status(s, "building 3/7")
s.api("new-tab")
s.settle(30)
snap = s.snapshot()
check(
"a pane's OSC status is a row under its tab",
"building 3/7" in _row(snap, Y0 + 1),
repr(_row(snap, Y0 + 1)),
)
check(
"the other tab moved down to make room",
snap.hit_at(CX, Y0 + 2) == "tab:2",
str(snap.hit_at(CX, Y0 + 2)),
)
check(
"the row is a door to the pane that said it",
snap.hit_at(CX + 1, Y0 + 1) == f"find:{pane}",
str(snap.hit_at(CX + 1, Y0 + 1)),
)
# We are in tab 2: clicking the status row is a cross-tab jump.
s.click(CX + 1, Y0 + 1)
s.until(lambda _: s.tabs()[0]["active"])
check("clicking it selects that tab", s.tabs()[0]["active"], str(s.tabs()))
check(
"...and focuses that pane",
s.focused()["id"] == pane,
str(s.focused()["id"]),
)
def test_status_rows_are_told_apart_by_the_slant_not_by_an_indent():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_named(s)
_status(s, "building 3/7")
snap = s.snapshot()
label, status = _row(snap, Y0), _row(snap, Y0 + 1)
# One leading space each: a status starts in the column its tab's name
# starts in. Three columns of indent is a fifth of this sidebar.
check(
"a status is not indented under its label",
status.index("building") == label.index(TAB),
f"{status.index('building')} vs {label.index(TAB)}",
)
st = snap.style_at(CX + 1, Y0 + 1)
check("it is italic instead", "italic" in st["attrs"], str(st))
check(
"...and the label above it is not",
"italic" not in snap.style_at(CX + 1, Y0)["attrs"],
str(snap.style_at(CX + 1, Y0)),
)
def _busy(s, on=True):
s.raw('printf "\\e]5577;1;busy;%s\\x07"\\n' % ("1" if on else "0"))
def test_a_busy_status_says_so():
"""The text of a running `make test` and a finished one is the same text,
so the row says it instead: the busy colour, and a mark in the column the
padding holds blank."""
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_status(s, "make test")
snap = s.snapshot()
idle = snap.style_at(CX + 1, Y0 + 1)
check("a plain status is ambient", idle["fg"] == "#5a6a8f", str(idle))
check(
"...and nothing sits in the indent",
snap.line(Y0 + 1)[CX] == " ",
repr(_row(snap, Y0 + 1)),
)
_busy(s)
s.settle(30)
snap = s.snapshot()
hot = snap.style_at(CX + 1, Y0 + 1)
check("busy turns the row's own colour", hot["fg"] == "#7aa2f7", str(hot))
check(
"and a spinner lands in the indent",
snap.line(Y0 + 1)[CX] != " ",
repr(_row(snap, Y0 + 1)),
)
check(
"...where it moves nothing: the text is where it was",
_row(snap, Y0 + 1).index("make test") == 2,
repr(_row(snap, Y0 + 1)),
)
check(
"...with the rest of the indent as air after it",
_row(snap, Y0 + 1)[1] == " ",
repr(_row(snap, Y0 + 1)),
)
_busy(s, False)
s.settle(30)
snap = s.snapshot()
check(
"done puts it back",
snap.style_at(CX + 1, Y0 + 1)["fg"] == "#5a6a8f"
and snap.line(Y0 + 1)[CX] == " ",
repr(_row(snap, Y0 + 1)),
)
def test_the_gap_after_the_mark_is_the_rest_of_the_padding():
"""The mark takes the first column of the indent and what is left is air,
so the default's two columns are a mark and a space -- and the squashed
look is something you ask for rather than something you get."""
squashed = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 0 1\n')
with Session(SH, cols=90, rows=20, config=squashed) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
row = _row(s.snapshot(), Y0 + 1)
check("one column: mark then words", row.index("make test") == 1, repr(row))
roomy = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_padding 0 1 0 3\n')
with Session(SH, cols=90, rows=20, config=roomy) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
row = _row(s.snapshot(), Y0 + 1)
check("three: mark then two spaces", row.index("make test") == 3, repr(row))
check("...and the mark is still against the frame", row[0] != " ", repr(row))
def test_a_spinner_costs_a_frame_clock_and_a_mark_does_not():
"""Several frames turn, one frame is a mark -- and only the turning one is
worth repainting the session for, only while it is on screen."""
one = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\nbusy_mark "*"\n')
with Session(SH, cols=90, rows=20, config=one) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
check(
"the static mark is drawn",
s.snapshot().line(Y0 + 1)[CX] == "*",
repr(_row(s.snapshot(), Y0 + 1)),
)
check(
"and asks for no clock",
s.api("deadline")["ms"] == -1,
str(s.api("deadline")),
)
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_status(s, "make test")
s.settle(30)
s.snapshot()
check(
"an idle sidebar wants no clock either",
s.api("deadline")["ms"] == -1,
str(s.api("deadline")),
)
_busy(s)
s.settle(30)
# The deadline is a property of the frame that was composed, like
# `animating` itself -- so ask for a frame before asking when the next
# one is wanted.
s.snapshot()
check(
"a spinner on screen asks for one",
s.api("deadline")["ms"] > 0,
str(s.api("deadline")),
)
_busy(s, False)
s.settle(30)
s.snapshot()
check(
"...and gives it back when the work stops",
s.api("deadline")["ms"] == -1,
str(s.api("deadline")),
)
def test_no_busy_mark_leaves_the_colour_to_say_it():
quiet = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\nbusy_mark ""\n')
with Session(SH, cols=90, rows=20, config=quiet) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
snap = s.snapshot()
check("no mark", snap.line(Y0 + 1)[CX] == " ", repr(_row(snap, Y0 + 1)))
check(
"but the row still says it is running",
snap.style_at(CX + 1, Y0 + 1)["fg"] == "#7aa2f7",
str(snap.style_at(CX + 1, Y0 + 1)),
)
def test_the_busy_colour_is_the_themes_own():
themed = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
'theme { tab_status_busy "#ff00ff" }\n'
)
with Session(SH, cols=90, rows=20, config=themed) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
snap = s.snapshot()
st = snap.style_at(CX + 2, Y0 + 1)
check("named, it wins", st["fg"] == "#ff00ff", str(st))
check(
"and the mark follows the words it marks",
(snap.style_at(CX, Y0 + 1) or {}).get("fg") == "#ff00ff",
str(snap.style_at(CX, Y0 + 1)),
)
def test_the_spinner_can_be_coloured_on_its_own():
"""Its own entry because it is its own decision: the words have to stay
readable and a mark does not, so a theme can shout with the glyph and keep
the text calm."""
themed = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
'theme { tab_status_busy "#8888ff"\n tab_status_spinner "#ffcc00" }\n'
)
with Session(SH, cols=90, rows=20, config=themed) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
snap = s.snapshot()
check(
"the mark takes its own colour",
(snap.style_at(CX, Y0 + 1) or {}).get("fg") == "#ffcc00",
str(snap.style_at(CX, Y0 + 1)),
)
check(
"...and the words keep theirs",
(snap.style_at(CX + 2, Y0 + 1) or {}).get("fg") == "#8888ff",
str(snap.style_at(CX + 2, Y0 + 1)),
)
def test_an_old_theme_gets_a_spinner_colour_anyway():
"""Neither colour is in any theme in contrib, so both are mixed from what a
theme does define -- the same bargain the other status colours make."""
old = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\ntheme {{ tab_hover "#00ff88" }}\n'
)
with Session(SH, cols=90, rows=20, config=old) as s:
s.settle(30)
_status(s, "make test")
_busy(s)
s.settle(30)
snap = s.snapshot()
check(
"the row is the theme's accent",
(snap.style_at(CX + 2, Y0 + 1) or {}).get("fg") == "#00ff88",
str(snap.style_at(CX + 2, Y0 + 1)),
)
check(
"...and so is the mark",
(snap.style_at(CX, Y0 + 1) or {}).get("fg") == "#00ff88",
str(snap.style_at(CX, Y0 + 1)),
)
def test_status_rows_take_their_own_theme_colours():
themed = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
'theme { tab_status_fg "#00ff88"\n tab_status_bg "#202030" }\n'
)
with Session(SH, cols=90, rows=20, config=themed) as s:
s.settle(30)
_status(s, "building")
snap = s.snapshot()
st = snap.style_at(CX + 1, Y0 + 1)
check("the fg is the themed one", st["fg"] == "#00ff88", str(st))
end = snap.style_at(CX + CW - 1, Y0 + 1)
check(
"and the band covers the row, not just the words",
end and end["bg"] == "#202030",
str(end),
)
def _rgb(hexs):
return tuple(int(hexs[i : i + 2], 16) for i in (1, 3, 5))
def test_an_old_theme_gets_coherent_status_colours_anyway():
"""A theme written before these rows existed names its own chrome and
nothing about them. Mixing two colours it *does* define beats dropping one
stock colour into somebody else's palette."""
count, hover = "#ff8800", "#0000ff"
old = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
f'theme {{ tab_count "{count}"\n tab_hover "{hover}" }}\n'
)
with Session(SH, cols=90, rows=20, config=old) as s:
s.settle(30)
_status(s, "building")
st = s.snapshot().style_at(CX + 1, Y0 + 1)
got, a, b = _rgb(st["fg"]), _rgb(count), _rgb(hover)
check(
"the status is mixed from the theme's own two colours",
all(min(a[i], b[i]) <= got[i] <= max(a[i], b[i]) for i in range(3)),
f"{st['fg']} not between {count} and {hover}",
)
check(
"...and is neither of them outright",
st["fg"] not in (count, hover),
st["fg"],
)
def test_a_monochrome_theme_stays_monochrome():
"""The reason the distinction is a slant and the colour is mixed rather
than picked: mono has no colour to spend, and must not be given any."""
mono = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\n'
'theme { tab_count "#585858"\n tab_hover "#e4e4e4" }\n'
)
with Session(SH, cols=90, rows=20, config=mono) as s:
s.settle(30)
_status(s, "building")
st = s.snapshot().style_at(CX + 1, Y0 + 1)
r, g, b = _rgb(st["fg"])
check("no hue arrived from anywhere", r == g == b, st["fg"])
check("but it is still italic", "italic" in st["attrs"], str(st))
def test_status_cap_spends_its_last_row_on_the_ellipsis():
capped = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_status 1\n')
with Session(SH, cols=90, rows=20, config=capped) as s:
s.settle(30)
_status(s, "first")
s.api("split", dir="cols")
s.settle(30)
_status(s, "second")
snap = s.snapshot()
check(
"over the cap, the row says there was more",
_row(snap, Y0 + 1).strip() == "\u2026",
repr(_row(snap, Y0 + 1)),
)
check(
"an ellipsis is not a door",
snap.hit_at(CX + 1, Y0 + 1) is None,
str(snap.hit_at(CX + 1, Y0 + 1)),
)
check(
"and only the cap's rows were spent",
snap.hit_at(CX, Y0 + 2 + NT_PAD) == "newtab",
str(snap.hit_at(CX, Y0 + 2 + NT_PAD)),
)
def test_tab_gap_is_air_between_tabs_and_nothing_else():
"""Tabs each carrying a paragraph of status read as one column of text;
the gap is what makes them separate entries again. It belongs *between*
tabs: the space above the first is tab_bar_pad's and the space before the
button is newtab_pad's, and neither should be paid twice."""
n = 2
gapped = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_gap {n}\n')
with Session(SH, cols=90, rows=20, config=gapped) as s:
s.settle(30)
for _ in range(2):
s.api("new-tab")
s.settle(20)
snap = s.snapshot()
check(
"the first tab still starts where it always did",
snap.hit_at(CX, Y0) == "tab:1",
str(snap.hit_at(CX, Y0)),
)
check(
"the next one is that many rows lower",
snap.hit_at(CX, Y0 + 1 + n) == "tab:2",
str([snap.hit_at(CX, Y0 + 1 + k) for k in range(n + 1)]),
)
check(
"and the air between is nobody's target",
all(snap.hit_at(CX, Y0 + 1 + k) is None for k in range(n)),
str([snap.hit_at(CX, Y0 + 1 + k) for k in range(n)]),
)
# Third tab, then the button: the gap is not paid again before the `+`.
third = Y0 + 2 * (1 + n)
check(
"the button keeps its own pad, not the gap",
snap.hit_at(CX, third + 1 + NT_PAD) == "newtab",
str(snap.hit_at(CX, third + 1 + NT_PAD)),
)
p = s.pane(0)
check(
"the gap is paint, not layout: panes keep their rows",
p["y"] <= 2,
str(p["y"]),
)
def test_tab_gap_gives_way_before_a_tab_does():
"""Spacing must never be what costs you the thing it spaces: a gap too
big for the rows available shrinks, one row at a time, rather than
pushing tabs off the bottom."""
huge = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_status 0\ntab_gap 4\n'
)
with Session(SH, cols=90, rows=12, config=huge) as s:
s.settle(30)
for _ in range(4):
s.api("new-tab")
s.settle(20)
snap = s.snapshot()
targets = {h["action"] for h in snap.hits}
missing = [t["index"] for t in s.tabs() if f"tab:{t['index']}" not in targets]
check("every tab is still clickable", not missing, str(missing))
check("and the button survived too", "newtab" in targets, str(sorted(targets)))
def test_statuses_never_cost_a_tab_its_row():
"""The list is the navigation; a status is an annotation on it.
Rows used to be spent in tab order until they ran out, so talkative panes
early in the list simply consumed the rows later tabs needed: four tabs of
three announcing panes in a short terminal left the fourth with no row and
no hit at all -- not clipped, unreachable -- and took the new-tab button
with it. What gives way now is the annotation."""
cfg = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_status 3\n')
with Session(SH, cols=90, rows=16, config=cfg) as s:
s.settle(30)
for t in range(4):
if t:
s.api("new-tab")
s.settle(20)
_status(s, f"tab{t + 1} pane1")
for p in (2, 3):
s.api("split", dir="rows")
s.settle(20)
_status(s, f"tab{t + 1} pane{p}")
snap = s.snapshot()
targets = {h["action"] for h in snap.hits}
missing = [t["index"] for t in s.tabs() if f"tab:{t['index']}" not in targets]
check("every tab that exists can be clicked", not missing, str(missing))
check(
"the button was not crowded out either",
"newtab" in targets,
str(sorted(targets)),
)
# The annotation is what gave way: with four labels and a button to
# fit into sixteen rows there is no room for twelve statuses, and it
# is the last tabs' statuses that are missing rather than their rows.
# The sidebar's own columns only: the panes' frames carry these same
# words (a pane draws its status too), and would match anywhere.
bar = [_row(snap, y) for y in range(16)]
check(
"the statuses are what went",
not any("tab4" in r for r in bar),
repr([r for r in bar if r.strip()]),
)
check(
"...and the ones that fit are still there",
any("tab1 pane1" in r for r in bar),
repr([r for r in bar if r.strip()]),
)
def _two_talking(s, first, second):
"""Two panes in one tab, each announcing. Returns their ids in row order."""
a = s.pane(0)["id"]
_status(s, first)
s.api("split", dir="rows")
s.settle(25)
b = s.focused()["id"]
_status(s, second)
return a, b
LINES = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_status 8\n'
"tab_bar_status_lines 3\n"
)
def test_a_status_can_be_given_more_than_one_row():
"""Sixteen cells is not enough for a sentence, and a sentence is what a
pane has to say. Wrapped, the same column carries three times as much."""
with Session(SH, cols=90, rows=20, config=LINES) as s:
s.settle(30)
_status(s, "add a summary row to the tab bar")
snap = s.snapshot()
rows = [_row(snap, Y0 + 1 + k).strip() for k in range(3)]
check(
"the words carry on down the column",
" ".join(r for r in rows if r) == "add a summary row to the tab bar",
repr(rows),
)
check(
"and it broke at spaces, not mid-word",
all(not r.endswith("\u2026") for r in rows if r),
repr(rows),
)
def test_one_line_still_cuts_at_the_column_not_the_word():
"""The default is unchanged. With nowhere for the word to go, stopping
early would spend cells on nothing -- the reason to prefer a word boundary
only exists once there is a next row to move the word to."""
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_status(s, "unwrapped statuses fill the column")
row = _row(s.snapshot(), Y0 + 1)
check("it is one row", not _row(s.snapshot(), Y0 + 2).strip(), repr(row))
check("cut with an ellipsis", row.rstrip().endswith("\u2026"), repr(row))
check(
"and it used the whole column",
len(row.rstrip()) >= CW - 1,
f"{len(row.rstrip())} of {CW}",
)
def test_wrapped_statuses_are_striped_so_panes_stay_apart():
"""Wrapped, the rows under a tab are a paragraph per pane rather than a
line per pane, and the shape no longer says where one ends. The band does.
At one line there is nothing to tell apart, so nothing is painted and a
translucent terminal keeps its own background."""
with Session(SH, cols=90, rows=20, config=LINES) as s:
s.settle(30)
_two_talking(s, "first pane says a fairly long thing", "second pane also")
snap = s.snapshot()
bgs = [snap.style_at(CX + 1, Y0 + 1 + k)["bg"] for k in range(4)]
check("the first pane's rows share one background", bgs[0] == bgs[1], str(bgs))
check("the next pane's is a different one", bgs[3] != bgs[0], str(bgs))
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_two_talking(s, "first", "second")
snap = s.snapshot()
check(
"unwrapped, no band is painted at all",
snap.style_at(CX + 1, Y0 + 1)["bg"] is None
and snap.style_at(CX + 1, Y0 + 2)["bg"] is None,
str([snap.style_at(CX + 1, Y0 + 1 + k)["bg"] for k in range(2)]),
)
def test_every_row_of_a_status_is_the_same_door():
"""The rows are one status, so they are one target: clicking the second
line of a sentence means the pane that said the sentence."""
with Session(SH, cols=90, rows=20, config=LINES) as s:
s.settle(30)
pane = s.pane(0)["id"]
_status(s, "a status long enough to need three whole rows of the bar")
snap = s.snapshot()
hits = [snap.hit_at(CX + 1, Y0 + 1 + k) for k in range(3)]
check(
"every row points at the pane that said it",
hits == [f"find:{pane}"] * 3,
str(hits),
)
def test_wrapping_still_says_when_a_status_did_not_fit():
"""The allowance counts rows, so a wrapped status eats several of them.
What does not fit is still reported rather than silently dropped."""
tight = _cfg(
f'tab_bar_side "left"\ntab_bar_width {W}\ntab_bar_status 4\n'
"tab_bar_status_lines 3\n"
)
with Session(SH, cols=90, rows=20, config=tight) as s:
s.settle(30)
# The second needs more than the one row left over, so it is dropped
# whole: half a wrapped sentence with no mark would read as all of it.
_two_talking(
s,
"first pane says a fairly long thing here",
"second pane also says a good deal for itself",
)
snap = s.snapshot()
check(
"the row after the first status says there was more",
_row(snap, Y0 + 4).strip() == "\u2026",
repr([_row(snap, Y0 + 1 + k) for k in range(5)]),
)
check(
"an ellipsis is still not a door",
snap.hit_at(CX + 1, Y0 + 4) is None,
str(snap.hit_at(CX + 1, Y0 + 4)),
)
def test_a_long_status_is_cut_and_says_so():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(30)
_status(s, "a status far too long for the sidebar")
row = _row(s.snapshot(), Y0 + 1)
check(
"the status stops at the sidebar's text column",
row.rstrip().endswith("\u2026"),
repr(row),
)
check(
"...which is the strip's padding short of the frame",
row.endswith(" "),
repr(row),
)
def test_a_dead_pane_reports_its_exit_instead():
# Wider than the default: "exited: status 3" plus the indent is 19 cells,
# and the point here is the words, not the (already tested) truncation.
kept = _cfg('tab_bar_side "left"\ntab_bar_width 24\nkeep_dead "all"\n')
with Session(["/bin/sh", "-c", "exit 3"], cols=90, rows=20, config=kept) as s:
s.until(lambda snap: "exited" in snap.line(Y0 + 1))
row = s.snapshot().line(Y0 + 1)[CX : CX + 22]
check("how it died replaces what it last said", "status 3" in row, repr(row))
def test_an_unnamed_tab_borrows_its_directory():
cd = ["/bin/sh", "-c", "cd /tmp && stty raw -echo; cat"]
with Session(cd, cols=90, rows=20, config=LEFT) as s:
s.settle(60)
row = _row(s.snapshot(), Y0)
check(
"the label is the focused pane's dir",
row.split() == ["tmp", "1"],
repr(row),
)
def test_a_real_name_beats_the_derived_one():
lay = tempfile.NamedTemporaryFile("w", suffix=".layout", delete=False)
lay.write('layout {\n tab name="api" {\n pane\n }\n}\n')
lay.close()
with Session(SH, cols=90, rows=20, config=LEFT, layout=lay.name) as s:
s.settle(60)
row = _row(s.snapshot(), Y0)
check(
"a declared name is not second-guessed",
row.split() == ["api", "1"],
repr(row),
)
def test_the_borrowed_name_follows_a_cd():
loop = ["/bin/sh", "-c", 'cd /tmp && while IFS= read -r l; do eval "$l"; done']
with Session(loop, cols=90, rows=20, config=LEFT) as s:
s.until(lambda snap: "tmp" in snap.line(Y0))
s.send(r"cd /home\n")
s.until(lambda snap: "home" in snap.line(Y0))
row = _row(s.snapshot(), Y0)
check(
"the kernel's answer moves the label",
row.split() == ["home", "1"],
repr(row),
)
def test_the_sidebar_is_framed_like_a_pane():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(40)
snap = s.snapshot()
top, bottom = snap.line(1), snap.line(18)
check("a frame runs round the list", top[0] in "\u256d\u250c", repr(top[:W]))
check(
"...closed at the bottom, above the status line",
bottom[0] in "\u2570\u2514",
repr(bottom[:W]),
)
check(
"and the list sits inside it",
snap.line(Y0)[0] == "\u2502" and snap.line(Y0)[CX + CW] == "\u2502",
repr(snap.line(Y0)[:W]),
)
def test_compact_shares_its_lines_with_the_ring():
"""The point of the chrome: one figure, not a box beside a box.
The sidebar's inner vertical *is* the tab area's ring column, so the
stroke union turns the ring's top-left corner into a tee -- nobody
computes that, it falls out of the same machinery the dividers use.
"""
conf = _cfg(f'compact true\ntab_bar_side "left"\ntab_bar_width {W}\n')
with Session(SH, cols=90, rows=20, config=conf) as s:
s.settle(40)
snap = s.snapshot()
check(
"the sidebar meets the ring in a junction, not a corner",
snap.line(0)[W] == "\u252c",
repr(snap.line(0)[: W + 2]),
)
check(
"...and again at the bottom",
snap.line(18)[W] == "\u2534",
repr(snap.line(18)[: W + 2]),
)
def test_chrome_false_gives_the_columns_back():
with Session(SH, cols=90, rows=20, config=BARE) as s:
s.settle(40)
snap = s.snapshot()
# No frame row either, so the list starts on the gap's own row.
check(
"no frame: the list starts in the first column",
snap.hit_at(0, 1) == "tab:1",
str(snap.hit_at(0, 1)),
)
check(
"and the whole width is the target",
snap.hit_at(W - 1, 1) == "tab:1",
str(snap.hit_at(W - 1, 1)),
)
def test_the_sidebar_button_says_what_it_does():
with Session(SH, cols=90, rows=20, config=LEFT) as s:
s.settle(40)
snap = s.snapshot()
row = _row(snap, Y0 + 1 + NT_PAD)
check("a row of its own spells the verb out", "new tab" in row, repr(row))
check(
"and the whole row is the target, like a tab's",
snap.hit_at(CX + CW - 1, Y0 + 1 + NT_PAD) == "newtab",
str(snap.hit_at(CX + CW - 1, Y0 + 1 + NT_PAD)),
)
def test_newtab_pad_is_the_air_before_the_button():
"""The button is the one row in the list that does not mean "go here", and
a sidebar tab is a target the full width of the strip: flush against the
tabs, a pointer one row low makes a tab instead of switching to one. The
pad is that air, and 0 gives the old flush button back."""
n = 3
padded = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\nnewtab_pad {n}\n')
with Session(SH, cols=90, rows=20, config=padded) as s:
s.settle(30)
snap = s.snapshot()
check(
"the air is not a target",
all(snap.hit_at(CX, Y0 + 1 + k) is None for k in range(n)),
str([snap.hit_at(CX, Y0 + 1 + k) for k in range(n)]),
)
check(
"the button is that many rows down",
snap.hit_at(CX, Y0 + 1 + n) == "newtab",
str(snap.hit_at(CX, Y0 + 1 + n)),
)
p = s.pane(0)
check(
"the pad is paint, not layout: panes keep their rows",
p["y"] <= 2,
str(p["y"]),
)
flush = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\nnewtab_pad 0\n')
with Session(SH, cols=90, rows=20, config=flush) as s:
s.settle(30)
snap = s.snapshot()
check(
"0 puts it straight under the last tab",
snap.hit_at(CX, Y0 + 1) == "newtab",
str(snap.hit_at(CX, Y0 + 1)),
)
def test_newtab_button_false_removes_it_everywhere():
"""The verb keeps working from the keyboard; only the place to click it
goes. A sidebar that is missing it has no `newtab` hit anywhere on it --
including as somewhere to drop a pane."""
off = _cfg(f'tab_bar_side "left"\ntab_bar_width {W}\nnewtab_button false\n')
with Session(SH, cols=90, rows=20, config=off) as s:
s.settle(30)
snap = s.snapshot()
check(
"no button on the sidebar",
all(h["action"] != "newtab" for h in snap.hits),
str([h for h in snap.hits if h["action"] == "newtab"]),
)
check(
"nor the word that spells it out",
all("new tab" not in snap.line(y) for y in range(20)),
repr([snap.line(y) for y in range(20) if "new tab" in snap.line(y)]),
)
s.api("new-tab")
s.until(lambda _: len(s.tabs()) == 2)
check("the verb still makes tabs", len(s.tabs()) == 2, str(len(s.tabs())))
top = _cfg("newtab_button false\n")
with Session(SH, cols=90, rows=20, config=top) as s:
s.settle(30)
snap = s.snapshot()
check(
"and the top strip loses it too",
all(h["action"] != "newtab" for h in snap.hits),
str([h for h in snap.hits if h["action"] == "newtab"]),
)
def test_a_narrow_sidebar_keeps_the_bare_mark():
narrow = _cfg('tab_bar_side "left"\ntab_bar_width 10\n')
with Session(SH, cols=90, rows=20, config=narrow) as s:
s.settle(40)
snap = s.snapshot()
row = snap.line(Y0 + 1 + NT_PAD)[CX : CX + 8]
check(
"no room for the word, so it is not said", "new tab" not in row, repr(row)
)
check(
"...but the button is still there",
snap.hit_at(CX, Y0 + 1 + NT_PAD) == "newtab",
str(snap.hit_at(CX, Y0 + 1 + NT_PAD)),
)
def test_the_strip_keeps_its_bare_mark():
"""The word is a sidebar's affordance, not a new spelling everywhere: in
the strip the mark sits at the end of a row of tabs, where columns are
scarce and the company it keeps says what it is."""
with Session(SH, cols=90, rows=20) as s:
s.settle(40)
check(
"the strip is unchanged",
"new tab" not in s.snapshot().line(1),
repr(s.snapshot().line(1)),
)
def test_a_small_screen_narrows_the_sidebar_first():
"""Eighteen columns is a margin beside a ninety-column screen and a sidecar
beside a fifty-column one, so the width is a ceiling rather than a
reservation: the bar hands columns back before it hands back the edge,
keeping to a third of the screen so the panes always have the rest."""
with Session(SH, cols=50, rows=20, config=LEFT) as s:
s.settle(30)
snap = s.snapshot()
check(
"the sidebar kept its edge",
snap.hit_at(CX, Y0) == "tab:1",
str(snap.hit_at(CX, Y0)),
)
# A pane's x is its text, which starts after the gap, the bar, and the
# pane's own left border: the bar's width is that minus the two.
sw = s.pane(0)["x"] - 2
check("...by narrowing, not by moving", sw < W, str(sw))
check("no more than a third of the screen", sw <= 50 // 3, str(sw))
check("and still wide enough to read a name in", sw >= 14, str(sw))
s.resize(90, 20)
s.until(lambda _: s.pane(0)["x"] - 2 == W)
check(
"the room comes back and so does the width",
s.pane(0)["x"] - 2 == W,
str(s.pane(0)["x"] - 2),
)
def test_a_short_terminal_falls_back_to_top():
"""The sidebar spends a row per tab, so a wide but short terminal runs out
of list before it runs out of screen -- and a tab with no row is not
clipped, it is unreachable. The strip lays the same tabs along one row."""
with Session(SH, cols=90, rows=10, config=LEFT) as s:
s.settle(30)
_named(s)
check(
"one tab fits down the edge",
s.snapshot().hit_at(CX, Y0) == "tab:1",
str(s.snapshot().hit_at(CX, Y0)),
)
# Named, like the first one, because the last check needs all seven to
# fit *across* the strip: unnamed, they are labelled from the cwd, and
# a checkout called something longer than `slosh` pushes the seventh
# tab off the row and out of the hit map. The fallback itself is about
# rows, so the names do not affect what is being tested.
for i in range(6):
s.api("new-tab", name=f"t{i}")
s.settle(20)
s.until(lambda snap: snap.hit_at(5, 1) == "tab:1")
snap = s.snapshot()
check(
"seven of them do not, so the strip goes back on top",
snap.hit_at(5, 1) == "tab:1",
str(snap.hit_at(5, 1)),
)
targets = {h["action"] for h in snap.hits}
missing = [t["index"] for t in s.tabs() if f"tab:{t['index']}" not in targets]
check("and every tab is reachable again", not missing, str(missing))
def test_a_strip_that_could_not_hold_them_either_changes_nothing():
"""The fallback is only worth making while the top row is the better seat.
Tabs too many for one row are clipped there as surely as they are cut off
the bottom of a sidebar -- and the sidebar at least shows more of them --
so the configured side stands."""
with Session(SH, cols=60, rows=10, config=LEFT) as s:
s.settle(30)
for _ in range(9):
s.api("new-tab")
s.settle(20)
snap = s.snapshot()
check(
"the sidebar keeps the edge it was given",
snap.hit_at(CX, Y0) == "tab:1",
str(snap.hit_at(CX, Y0)),
)
def test_narrow_terminal_falls_back_to_top():
# 40 columns: a third of it is 13, narrower than a sidebar is worth, and
# what is left would not seat the pane the bar is chrome for either. So
# the strip goes back to the top row rather than shrink any further.
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(CX, Y0) == "tab:1")
check(
"a resize moves the bar without anyone storing state",
s.snapshot().hit_at(CX, Y0) == "tab:1",
str(s.snapshot().hit_at(CX, Y0)),
)
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_pad_pushes_the_list_down()
test_padding_is_the_air_inside_the_strip()
test_padding_zero_puts_it_against_the_frame()
test_the_plate_ignores_the_padding()
test_tab_bar_pad_is_still_the_top_of_it()
test_a_bad_padding_is_a_line_and_no_more()
test_the_index_sits_at_the_far_end()
test_the_prefix_is_still_there_for_anyone_who_wants_it()
test_the_sidebar_aligns_by_default()
test_a_long_name_stops_short_of_the_number()
test_a_narrow_row_keeps_the_prefix()
test_the_top_strip_ignores_it()
test_the_whole_row_is_still_one_door()
test_a_bad_index_mode_is_a_line_and_no_more()
test_every_tab_sits_on_a_plate()
test_an_old_theme_gets_an_idle_plate_in_its_own_family()
test_a_theme_can_have_the_bare_tabs_back()
test_status_rows_sit_under_their_tab()
test_status_rows_are_told_apart_by_the_slant_not_by_an_indent()
test_a_busy_status_says_so()
test_the_gap_after_the_mark_is_the_rest_of_the_padding()
test_a_spinner_costs_a_frame_clock_and_a_mark_does_not()
test_no_busy_mark_leaves_the_colour_to_say_it()
test_the_busy_colour_is_the_themes_own()
test_the_spinner_can_be_coloured_on_its_own()
test_an_old_theme_gets_a_spinner_colour_anyway()
test_status_rows_take_their_own_theme_colours()
test_an_old_theme_gets_coherent_status_colours_anyway()
test_a_monochrome_theme_stays_monochrome()
test_status_cap_spends_its_last_row_on_the_ellipsis()
test_a_long_status_is_cut_and_says_so()
test_a_dead_pane_reports_its_exit_instead()
test_an_unnamed_tab_borrows_its_directory()
test_a_real_name_beats_the_derived_one()
test_the_borrowed_name_follows_a_cd()
test_the_sidebar_is_framed_like_a_pane()
test_compact_shares_its_lines_with_the_ring()
test_chrome_false_gives_the_columns_back()
test_the_sidebar_button_says_what_it_does()
test_newtab_pad_is_the_air_before_the_button()
test_newtab_button_false_removes_it_everywhere()
test_tab_gap_is_air_between_tabs_and_nothing_else()
test_tab_gap_gives_way_before_a_tab_does()
test_statuses_never_cost_a_tab_its_row()
test_a_status_can_be_given_more_than_one_row()
test_one_line_still_cuts_at_the_column_not_the_word()
test_wrapped_statuses_are_striped_so_panes_stay_apart()
test_every_row_of_a_status_is_the_same_door()
test_wrapping_still_says_when_a_status_did_not_fit()
test_a_narrow_sidebar_keeps_the_bare_mark()
test_the_strip_keeps_its_bare_mark()
test_a_small_screen_narrows_the_sidebar_first()
test_a_short_terminal_falls_back_to_top()
test_a_strip_that_could_not_hold_them_either_changes_nothing()
test_narrow_terminal_falls_back_to_top()
test_growing_back_restores_the_sidebar()
sys.exit(report())
|