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
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
|
//! The tty frontend's own cases (test/tty.zig), editing: modes, selections, look, search, the language client, diffs.
const std = @import("std");
const Tty = @import("../tty.zig").Tty;
pub const cases = .{
.{ "tty editing: edit", edit },
.{ "tty editing: fileedit", fileedit },
.{ "tty editing: modal", modal },
.{ "tty editing: multicursor", multicursor },
.{ "tty editing: selregex", selregex },
.{ "tty editing: yankpaste", yankpaste },
.{ "tty editing: pipe", pipe },
.{ "tty editing: chordcut", chordcut },
.{ "tty editing: selarg", selarg },
.{ "tty editing: find", find },
.{ "tty editing: fsearch", fsearch },
.{ "tty editing: grep", grep },
.{ "tty editing: stepgrain", stepgrain },
.{ "tty editing: look-center", look_center },
.{ "tty editing: look-file", look_file },
.{ "tty editing: look-file-1col", look_file_1col },
.{ "tty editing: lookloaded", lookloaded },
.{ "tty editing: lookpanes", lookpanes },
.{ "tty editing: lookrange", lookrange },
.{ "tty editing: jumps", jumps },
.{ "tty editing: cmdword", cmdword },
.{ "tty editing: lsp", lsp },
.{ "tty editing: lsp-client", lsp_client },
.{ "tty editing: lsp-client-edit", lsp_client_edit },
.{ "tty editing: lspcomplete", lspcomplete },
.{ "tty editing: lspcompletemoved", lspcompletemoved },
.{ "tty editing: lspdebug", lspdebug },
.{ "tty editing: lsprelpath", lsprelpath },
.{ "tty editing: lsp-rename", lsp_rename },
.{ "tty editing: lsp-rename-files", lsp_rename_files },
.{ "tty editing: callstack", callstack },
.{ "tty editing: diffview", diffview },
.{ "tty editing: dirpane", dirpane },
.{ "tty editing: scrolloff", scrolloff },
.{ "tty editing: wrap", wrap },
.{ "tty editing: hscroll", hscroll },
.{ "tty editing: follow", follow },
.{ "tty editing: tagcmd", tagcmd },
.{ "tty editing: tagnav", tagnav },
.{ "tty editing: tagpath", tagpath },
.{ "tty editing: tag", tag },
};
// insert-mode splice: click into a body row, type, escape back to normal
fn edit(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "edit");
defer t.deinit();
try t.file("e.txt", "x");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "e.txt");
try t.stable(700, 20000);
try t.press("left", "5", 11);
try t.release("left", "5", 11);
try t.stable(400, 8000);
try t.key("i");
try t.send("hello-insert");
try t.key("esc");
try t.settle(100);
try t.stable(500, 8000);
try t.snap("inserted");
try t.style("inserted");
try t.done();
}
// file panes: modal editing on real content, undo, Save writes to disk
fn fileedit(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "fileedit");
defer t.deinit();
try t.lines("f.txt", 20, "");
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "f.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("f.txt");
try t.key("esc");
try t.settle(100);
try t.press("right", "6", 9);
try t.release("right", "6", 9);
try t.wait(10000, "line 3");
try t.stable(700, 15000);
// edit line 1: click it, insert, esc
try t.press("left", "10", 8);
try t.release("left", "10", 8);
try t.stable(400, 5000);
try t.key("i");
try t.send("EDIT''ME");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("edited");
// x-select line 2 and delete it
try t.key("j g h");
try t.stable(400, 5000);
try t.key("x d");
try t.stable(400, 5000);
try t.snap("deleted");
try t.key("u");
try t.stable(400, 5000);
try t.snap("undone");
// Save through the file pane's own tag: `:` focuses that same tag and `w`
// selects Save before the ordinary execute key runs it.
try t.key(":");
try t.stable(400, 5000);
try t.key("w tab");
try t.stable(600, 8000);
try t.snapFile("saved", "/tmp/pardes-snap/fileedit/cwd/f.txt");
try t.done();
}
// helix-modal normal mode: motions, x/v selections, y/d, insert, undo/redo
fn modal(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "modal");
defer t.deinit();
try t.file("words.txt", "alpha beta");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "words.txt");
try t.stable(700, 20000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("printf 'one two three\\nfour five six\\nseven eight nine\\n'");
try t.key("enter");
try t.wait(8000, "seven");
try t.stable(700, 10000);
try t.key("c-b");
try t.stable(600, 8000);
try t.press("left", "5", 7);
try t.release("left", "5", 7);
try t.stable(400, 5000);
try t.key("g g");
try t.stable(400, 5000);
try t.snap("top");
try t.key("j j w");
try t.stable(400, 5000);
try t.snap("moved");
try t.key("x");
try t.stable(400, 5000);
try t.snap("xsel");
try t.style("xsel");
try t.key("x");
try t.stable(400, 5000);
try t.snap("xsel2");
try t.key("y");
try t.stable(400, 5000);
try t.snap("yanked");
try t.key("v j l");
try t.stable(400, 5000);
try t.snap("vsel");
try t.style("vsel");
try t.key("esc");
try t.settle(100);
try t.key("i");
try t.send("TYPED");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("typed");
try t.key("u");
try t.stable(400, 5000);
try t.snap("undone");
try t.key("U");
try t.stable(400, 5000);
try t.snap("redone");
try t.key("g e");
try t.stable(400, 5000);
try t.snap("bottom");
try t.done();
}
// MULTIPLE CURSORS on a real file pane. The differential suite (hxdiff) proves
// the model against a real helix but is headless, so this is the part it cannot
// see: that every range is actually on screen, that the primary reads
// differently from the others, and that ONE keystroke edits at all of them.
fn multicursor(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "multicursor");
defer t.deinit();
try t.lines("f.txt", 12, "");
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "f.txt");
try t.stable(700, 20000);
// open f.txt in the left pane (type its name, right-click to Look)
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("f.txt");
try t.key("esc");
try t.settle(100);
try t.press("right", "6", 9);
try t.release("right", "6", 9);
try t.wait(10000, "line 3");
try t.stable(700, 15000);
// top of the file, then C C: three cursors, one per line, primary on line 3
try t.key("g g");
try t.stable(400, 5000);
try t.key("C C");
try t.stable(400, 5000);
try t.snap("three-cursors");
// the colours ARE the feature here: the primary's cell against the two dimmer
// ones, each with its own bright cursor cell
try t.style("three-cursors");
// one keystroke, three edits
try t.key("i");
try t.send(">>");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("edited-at-three");
// a selection per cursor: e selects to the end of the first word at each
try t.key("g h w");
try t.stable(400, 5000);
try t.snap("three-selections");
try t.style("three-selections");
// `,` drops back to the primary alone; the two dim highlights must vanish
try t.key(",");
try t.stable(400, 5000);
try t.snap("keep-primary");
try t.style("keep-primary");
try t.done();
}
// Interactive regex selection (`s` / `S`) and the comment toggle, on a real
// file pane. hxdiff pins what they DO against a real helix, but it is headless,
// so this is the half it cannot see: the prompt living in the TAG rather than a
// popup, the matches lighting up under a pattern as it is typed, Esc putting
// back what was there, and Ctrl-c using the token this file's EXTENSION asks
// for — `//`, where a buffer with no language would get `#`.
fn selregex(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "selregex");
defer t.deinit();
try t.file("m.zig", "const one = 1;\nconst two = 2;\nconst three = 3;\n");
// wide on purpose: the whole point of this script is a tag long enough to hold
// the marker AND the pattern, and a narrow pane simply truncates it away
try t.start(25, 160, &.{"m.zig"});
try t.wait(8000, "m.zig");
try t.stable(700, 20000);
try t.key("g g");
try t.stable(400, 5000);
// `%` takes the whole file, `s` arms the regex input: the marker goes into the
// tag tail after the path, and the pane is in insert mode ON THE TAG — the
// same one-line editor `/` and Find use, and nothing has moved in the body yet.
try t.key("%");
try t.key("s");
try t.stable(400, 5000);
try t.snap("prompt-armed");
// ...and now the point: the selection follows the pattern as it is typed. Three
// `const` runs light up with Enter nowhere near, and the colours ARE the
// feature — the primary bright, the other two dim, each with its own cursor.
try t.send("const");
try t.stable(400, 5000);
try t.snap("preview");
try t.style("preview");
try t.key("enter");
try t.stable(400, 5000);
try t.snap("three-selected");
try t.style("three-selected");
// a second `s` narrows the three to one `t` apiece...
try t.key("s");
try t.send("t");
try t.stable(400, 5000);
try t.snap("narrowed");
// the grid text cannot show a selection, so this is where the styles carry the
// whole point: three one-cell ranges here, three five-cell ones after the Esc
try t.style("narrowed");
// ...and Esc throws that away for the selection the prompt opened on, which is
// free: the preview is re-derived from that snapshot on every keystroke, so
// cancelling is just applying the empty pattern.
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("esc-restores");
try t.style("esc-restores");
// Ctrl-c comments every line the three cursors touch — one decision for the
// whole selection, not one per cursor — and again to take it back off.
try t.key("c-c");
try t.stable(400, 5000);
try t.snap("commented");
try t.key("c-c");
try t.stable(400, 5000);
try t.snap("uncommented");
try t.done();
}
// y -> p round-trips through the core's own yank register (regression: p used
// to request the SYSTEM clipboard via OSC 52, which plain terminals — and this
// harness — never answer, so paste silently no-oped). Pins helix placement:
// a linewise yank (x) pastes as whole lines below (p) / above (P), a charwise
// yank (v) splices inline after the selection.
fn yankpaste(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "yankpaste");
defer t.deinit();
try t.lines("f.txt", 5, "");
try t.start(31, 100, &.{"f.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "line 5");
try t.stable(700, 20000);
// linewise: x-select line 2, yank, move down, paste below line 3
try t.press("left", "8", 5);
try t.release("left", "8", 5);
try t.stable(400, 5000);
try t.key("x y j p");
try t.stable(400, 5000);
try t.snap("linewise-below");
// P from the pasted line: its copy lands above
try t.key("x y P");
try t.stable(400, 5000);
try t.snap("linewise-above");
// charwise: v-select two chars of line 1, yank, paste splices after them
try t.press("left", "8", 4);
try t.release("left", "8", 4);
try t.stable(400, 5000);
try t.key("v l y p");
try t.stable(400, 5000);
try t.snap("charwise-inline");
// a BLANK line yanks as a bare "\n": the block is empty, lineCount says 0
// lines, and every `n - 1` in the linewise paste used to underflow — panic on
// y then p. It pastes as one empty line.
try t.key("o");
try t.key("esc");
try t.settle(100);
try t.key("y p");
try t.stable(400, 5000);
try t.snap("blankline");
try t.done();
}
// `|`: visible tag prompt, native async shell filter, and one-step undo.
fn pipe(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "pipe");
defer t.deinit();
try t.file("pipe.txt", "alpha beta\ngamma delta");
try t.start(13, 180, &.{"pipe.txt"});
try t.wait(8000, "alpha beta");
try t.stable(700, 20000);
try t.key("x |");
try t.send("tr a-z A-Z");
try t.stable(300, 5000);
try t.snap("prompt");
try t.key("enter");
try t.wait(8000, "ALPHA BETA");
try t.stable(500, 8000);
try t.snap("filtered");
try t.key("u");
try t.stable(400, 5000);
try t.snap("undone");
try t.done();
}
// acme 1-2/1-3 chords in a file pane: with the left button holding a drag
// selection, tapping middle Cuts it into the snarf (yank) register; tapping
// right Pastes the register (replacing the selection, or splicing at a bare
// click point); cut then paste in ONE hold nets out to copy/Snarf. The left
// release after a chord is inert (the cursor stays where the op left it).
// Also the cancel chords: tapping right during a middle (execute) drag or
// left during a right (look) drag cancels the gesture entirely.
fn chordcut(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "chordcut");
defer t.deinit();
try t.lines("f.txt", 5, "");
try t.lines("g.txt", 2, "");
// The narrow-window fallback splits below the source shell and leaves the
// unrelated right column untouched. Give the caller enough cells that the selected
// `echo B''OO g.txt` remains one displayed row; this test is about chords, not
// soft-wrap traversal.
try t.start(31, 120, &.{ "-n", "3" });
try t.wait(8000, "f.txt");
try t.stable(700, 20000);
// open f.txt: click a body spot, type the name, look it
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("f.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "6", 9);
try t.release("right", "6", 9);
try t.wait(10000, "line 3");
try t.stable(700, 15000);
try t.snap("opened");
// 1-2 Cut: left-drag over "line" on line 2, tap middle while holding
try t.press("left", "8", 10);
try t.drag("left", "11", 10);
try t.press("middle", "11", 10);
try t.release("middle", "11", 10);
try t.release("left", "11", 10);
try t.stable(400, 5000);
try t.snap("cut");
// 1-2 then 1-3 in one hold = copy: line 3 keeps its text, register loaded
try t.press("left", "8", 11);
try t.drag("left", "11", 11);
try t.press("middle", "11", 11);
try t.release("middle", "11", 11);
try t.press("right", "11", 11);
try t.release("right", "11", 11);
try t.release("left", "11", 11);
try t.stable(400, 5000);
try t.snap("copied");
// 1-3 at a bare click point: hold left past the end of line 4, tap right —
// the register splices in at the click
try t.press("left", "14", 12);
try t.press("right", "14", 12);
try t.release("right", "14", 12);
try t.release("left", "14", 12);
try t.stable(400, 5000);
try t.snap("pointpaste");
// 1-3 over a fresh selection replaces it with the register
try t.press("left", "9", 13);
try t.drag("left", "11", 13);
try t.press("right", "11", 13);
try t.release("right", "11", 13);
try t.release("left", "11", 13);
try t.stable(400, 5000);
try t.snap("replaced");
// arm the cancel tests: append `echo B''OO g.txt` to line 2
try t.press("left", "10", 10);
try t.release("left", "10", 10);
try t.stable(400, 5000);
try t.key("i");
try t.send("echo B''OO g.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
// 2-3 cancel (acme textselect2): tap right during the middle execute-drag
// over `echo B''OO` — the command never runs (no BOO anywhere)
try t.press("middle", "10", 10);
try t.drag("middle", "19", 10);
try t.press("right", "19", 10);
try t.release("right", "19", 10);
try t.release("middle", "19", 10);
try t.stable(700, 8000);
try t.snap("cancelexec");
// the same drag released clean proves the word was live: BOO appears
try t.press("middle", "10", 10);
try t.drag("middle", "19", 10);
try t.release("middle", "19", 10);
try t.wait(10000, "BOO");
try t.stable(700, 10000);
try t.snap("execafter");
// 3-1 cancel (acme textselect3): tap left during the right look-drag over
// g.txt — no pane opens
try t.press("right", "21", 10);
try t.drag("right", "25", 10);
try t.press("left", "25", 10);
try t.release("left", "25", 10);
try t.release("right", "25", 10);
try t.stable(700, 8000);
try t.snap("cancellook");
// the same look released clean opens g.txt
try t.press("right", "21", 10);
try t.drag("right", "25", 10);
try t.release("right", "25", 10);
try t.wait(10000, "line 2");
try t.stable(700, 10000);
try t.snap("lookafter");
// a fresh left click dismisses the chord's leftover selection instead of
// dragging the anchored span to the click: copy `line` on g.txt line 1
// (styled snap shows the selection), then click the next row (it's gone)
try t.press("left", "8", 24);
try t.drag("left", "11", 24);
try t.press("middle", "11", 24);
try t.release("middle", "11", 24);
try t.press("right", "11", 24);
try t.release("right", "11", 24);
try t.release("left", "11", 24);
try t.stable(400, 5000);
try t.style("chordsel");
try t.press("left", "8", 25);
try t.release("left", "8", 25);
try t.stable(400, 5000);
try t.style("clickdismiss");
// g.txt opened under the lower shell's text and left it three rows: close it,
// and the shell grows back into its rows, for what follows to run in
try t.press("middle", "59", 23);
try t.release("middle", "59", 23);
try t.stable(700, 15000);
// tty paste chord: over a mouse-listening app B1 is the app's, so the
// chord's B1 holds Shift (B3 is pardes's either way); the app gets a click
// where the text goes (SGR, body-relative) then the register between
// bracketed-paste markers — cat -v prints the received bytes visibly
try t.press("left", "35", 23);
try t.release("left", "35", 23);
try t.stable(400, 5000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("stty -icanon -echo; printf '\\x1b[?2004h\\x1b[?1000h\\x1b[?1006h'; cat -v");
try t.key("enter");
try t.stable(700, 8000);
try t.press("shift-left", "40", 25);
try t.press("right", "40", 25);
try t.release("right", "40", 25);
try t.release("shift-left", "40", 25);
try t.stable(700, 8000);
try t.snap("ttyprobe");
// a plain prompt (mouse modes off) gets no click bytes — just the paste;
// readline's own 2004 strips the markers and inserts the register text
try t.key("c-c");
try t.stable(600, 8000);
try t.send("stty sane; printf '\\x1b[?1000l\\x1b[?1006l'");
try t.key("enter");
try t.stable(600, 8000);
try t.press("left", "40", 25);
try t.press("right", "40", 25);
try t.release("right", "40", 25);
try t.release("left", "40", 25);
try t.stable(700, 8000);
try t.snap("ttyprompt");
try t.done();
}
// 2-1 chord borrows the argument selection from ANOTHER pane: pane A (left)
// holds the selection, pane B (right) middle-drags the command with no
// selection of its own — the chord's left tap finds A's kept left selection,
// and later A's explicit v selection, and rides it as the argument.
fn selarg(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "selarg");
defer t.deinit();
try t.file("s.txt", "x");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "s.txt");
try t.stable(700, 20000);
// pane A (left, active at boot): print the two argument words
try t.key("c-b");
try t.stable(600, 8000);
try t.send("clear; printf 'ZZARG ZZVEE\\n'");
try t.key("enter");
try t.wait(8000, "ZZVEE");
try t.stable(700, 15000);
try t.key("c-b");
try t.stable(600, 8000);
// pane B (top right): create the arg-printing script and show its path
try t.press("left", "60", 7);
try t.release("left", "60", 7);
try t.stable(400, 5000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("printf '#!/bin/sh\\necho CHORDARG:\"$1\"\\n' > c.sh; chmod +x c.sh; clear; printf './c.sh\\n'");
try t.key("enter");
try t.wait(10000, "./c.sh");
try t.stable(700, 15000);
try t.key("c-b");
try t.stable(600, 8000);
// keep a left selection over ZZARG in pane A (this also focuses A)
try t.press("left", "3", 5);
try t.drag("left", "7", 5);
try t.release("left", "7", 5);
try t.stable(400, 5000);
try t.snap("kept");
// chord in pane B: middle on ./c.sh + left tap (B has NO selection: the
// argument comes from pane A's kept left selection) + middle release runs
try t.press("middle", "55", 5);
try t.press("left", "55", 5);
try t.release("middle", "55", 5);
try t.release("left", "55", 5);
try t.wait(10000, "CHORDARG:ZZARG");
try t.stable(700, 10000);
try t.snap("crosspane");
// now an explicit modal selection: plain-click ZZVEE in A (drops A's kept
// left selection), select it with v e, chord in B again
try t.press("left", "9", 5);
try t.release("left", "9", 5);
try t.stable(400, 5000);
try t.send("ve");
try t.stable(400, 5000);
try t.press("middle", "55", 5);
try t.press("left", "55", 5);
try t.release("middle", "55", 5);
try t.release("left", "55", 5);
try t.wait(10000, "CHORDARG:ZZVEE");
try t.stable(700, 10000);
try t.snap("vselarg");
try t.done();
}
// SPC f f: a query pane under the pane (Query.zig), line 1 `Find `, typed
// into. The files below the pane's directory are listed once, on the disk
// engine's worker (rg --files when it is on PATH, else the sorted walk: both
// pass over .git), and each key scores them fuzzily (pick's scorer), the best
// first, the matched letters tinted. The current one is shown in the
// +Preview under the query pane, born with it so nothing moves later;
// Ctrl-n / Ctrl-p step it, never the pointer. Enter makes the preview the
// file's pane where it stands. Esc while typing closes the query pane and
// gives its rows back. A query that matches nothing is a count of 0, not an
// exit. B2 on `Find` with a selection asks with that word, the keyboard
// staying in the text.
fn find(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "find");
defer t.deinit();
try t.dir("sub");
try t.dir("sub/nest");
try t.dir(".git");
try t.file("here.txt", "Find zqm");
try t.file("zqmark-alpha.txt", "alpha body");
try t.file("sub/ZQMARK-beta.txt", "beta body");
try t.file("sub/nest/zqmark-gamma.txt", "gamma body");
try t.file("other.txt", "nothing to match here");
try t.file(".git/zqmark-hidden.txt", "hidden body");
try t.start(41, 120, &.{"here.txt"});
try t.wait(8000, "here.txt");
try t.stable(700, 20000);
// SPC f is a group (Find, New, Save, Recent, Grep): the indicator waits
try t.key("space");
try t.key("f");
try t.stable(400, 5000);
try t.snap("group");
// the second f opens the query pane: every file listed, line 1 `Find `
try t.key("f");
try t.wait(10000, "zqmark-alpha.txt");
try t.stable(700, 15000);
try t.snap("armed");
try t.send("zqm");
try t.stable(700, 15000);
try t.snap("typing");
// the next one current, its text in the preview
try t.key("c-n");
try t.wait(10000, "beta body");
try t.stable(700, 15000);
try t.snap("next");
// Enter: the preview is that file's pane now, where it stood
try t.key("enter");
try t.stable(700, 15000);
try t.snap("promoted");
// a second Find from here.txt reuses its query pane; nothing found is 0
try t.press("left", "8", 4);
try t.release("left", "8", 4);
try t.stable(400, 5000);
try t.key("space");
try t.key("f");
try t.key("f");
try t.send("zzqq");
try t.stable(700, 15000);
try t.snap("nomatch");
// Esc: the kept rows of the last query are back
try t.key("esc");
try t.settle(100);
try t.stable(700, 15000);
try t.snap("cancel");
// B2 on Find with `zqm` selected in here.txt: the query pane under it, the
// keyboard still in here.txt
try t.press("left", "13", 4);
try t.drag("left", "15", 4);
try t.release("left", "15", 4);
try t.stable(400, 5000);
try t.press("middle", "@Find", 1);
try t.release("middle", "@Find", 1);
try t.wait(10000, "Find zqm");
try t.stable(700, 15000);
try t.snap("topbar");
try t.done();
}
// `/` in a file: its query pane under it (Query.zig), line 1 `/` and the
// pattern, typed into; nothing on the notice band. Each key searches the
// file again (a regex, any case unless it has a capital): every match is
// tinted and ticked on the scroll rail, the first at or after the cursor
// selected and in view, and the rows under line 1 are the lines holding a
// match, a line number in the gutter. Ctrl-n steps while typing; Enter puts
// the keyboard on the match, the pattern in `/`, and keeps the rows as text;
// n / N then step the matches in the file, round the end without a word. A
// later `/` reuses the pane; Esc while typing brings the kept rows back. A
// pattern that matches nothing is a count of 0, not an exit.
fn fsearch(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "fsearch");
defer t.deinit();
try t.file("g.txt", "l1\nMARK a\nl3\nl4\nl5\nMARK b\nl7\nl8\nl9\nMARK c\nl11\nl12");
// Builtins announce themselves by default, and an announcement is a band at
// the top of the body -- which moves every row this script clicks. What the
// verbs do is what is under test, not the announcement.
try t.config("Verbose off");
try t.start(31, 180, &.{ "-n", "3" });
try t.wait(8000, "g.txt");
try t.stable(700, 20000);
// open g.txt: type the name in the shell, look it (as in look-file.snap)
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("g.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "6", 9);
try t.release("right", "6", 9);
try t.wait(10000, "MARK a");
try t.stable(700, 15000);
try t.snap("opened");
try t.key("/");
try t.stable(400, 5000);
try t.snap("slash");
try t.send("MARK");
try t.stable(400, 5000);
try t.snap("typing");
try t.style("typing");
try t.key("c-n");
try t.stable(400, 5000);
try t.snap("ctrln");
try t.key("enter");
try t.stable(700, 10000);
try t.snap("landed");
try t.send("n");
try t.stable(400, 5000);
try t.snap("n");
try t.send("N");
try t.stable(400, 5000);
try t.snap("N");
try t.key("/");
try t.send("zz");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("cancel");
try t.key("/");
try t.send("zzqq");
try t.stable(700, 10000);
try t.snap("nomatch");
try t.done();
}
// The Grep builtin (topbar word, `SPC f g`): the query pane under the pane
// that asked, line 1 `Grep ` and the text, the lines of the files below its
// directory holding it (literally, any case unless it has a capital), on the
// disk engine's worker once the typing pauses: rg --json when it is on PATH,
// else the sorted walk. The rows sit under their file's name, a line number
// in the gutter. A hit in a file an open pane shows is shown there; one in a
// file nothing shows, in the +Preview under the query pane, which Enter makes
// the file's pane. A query that matches nothing is a count of 0, and Esc
// while typing brings the kept rows back.
fn grep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "grep");
defer t.deinit();
try t.dir("sub");
try t.file("a.txt", "hello TARGET one\nnothing here\nlast TARGET line");
try t.file("sub/b.txt", "deep\nTARGET inside sub");
try t.file("noise.txt", "nothing to see");
try t.config("Verbose off");
try t.start(31, 180, &.{ "-n", "3" });
try t.wait(8000, "a.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("a.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "6", 9);
try t.release("right", "6", 9);
try t.wait(10000, "hello TARGET");
try t.stable(700, 15000);
try t.snap("opened");
// middle-click Grep on the topbar: the query pane under a.txt, typed into
try t.press("middle", "@Grep", 1);
try t.release("middle", "@Grep", 1);
try t.stable(400, 5000);
try t.send("TARGET");
// three lines (the pane is short: its count says how many)
try t.wait(10000, "+Search 1/3");
try t.stable(700, 15000);
try t.snap("typing");
// a.txt's hits are shown in a.txt; sub/b.txt's in the preview
try t.key("c-n");
try t.stable(700, 15000);
try t.snap("second");
try t.key("c-n");
try t.wait(10000, "deep");
try t.stable(700, 15000);
try t.snap("preview");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("opened-hit");
try t.key("space");
try t.key("f");
try t.key("g");
try t.stable(400, 5000);
try t.send("zzqq");
try t.stable(700, 10000);
try t.snap("nomatch");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("esc");
try t.done();
}
// ONE PRESS, ONE ROW. A query pane's rows are one a line with a hit, the
// hit's line under a gutter number, and Ctrl-n / Ctrl-p (typing on line 1)
// step them a row at a time, round the end: row 2 below matched on a line
// that mentions `sub/b.txt`, and the step does not stop on that word, as the
// old word-grained walk did; the fourth press wraps back to row 1.
//
// A path with a BLANK in it is one name: `two words.txt` is found whole by
// Find and Enter opens exactly it.
fn stepgrain(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "stepgrain");
defer t.deinit();
try t.dir("sub");
try t.file("a.txt", "hello ZQMARK one\nsee also sub/b.txt for ZQMARK two");
try t.file("sub/b.txt", "ZQMARK inside sub");
try t.run("touch 'two words.txt'");
try t.start(31, 150, &.{"a.txt"});
try t.wait(8000, "hello ZQMARK");
try t.stable(700, 20000);
// Grep from the leader: three hits, under their files, the empty file
// contributing none. Row 2 is the one whose TEXT holds a path.
try t.key("space");
try t.key("f");
try t.key("g");
try t.stable(400, 5000);
try t.send("ZQMARK");
try t.wait(10000, "ZQMARK inside sub");
try t.stable(700, 15000);
try t.snap("results");
try t.key("c-n");
try t.stable(400, 5000);
try t.snap("step-row2");
try t.style("step-row2");
try t.key("c-n");
try t.stable(400, 5000);
try t.snap("step-row3");
try t.key("c-n");
try t.stable(400, 5000);
try t.snap("step-wrap");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
// Find `words`: the name with a blank in it, whole
try t.key("space");
try t.key("f");
try t.key("f");
try t.send("words");
try t.wait(10000, "two words.txt");
try t.stable(700, 15000);
try t.snap("blank-in-path");
try t.style("blank-in-path");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("blank-opened");
try t.done();
}
// a look on path:NN opens the file with the target line CENTERED in the body
// (scroll = line - body/2): fresh open at a deep line, then dedup re-looks at
// the same path re-center the existing pane, and a look near line 1 clamps
// the scroll at 0 (no negative scroll)
fn look_center(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "look-center");
defer t.deinit();
try t.lines("big.txt", 200, "");
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "big.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("big.txt:100 big.txt:150 big.txt:2");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "7", 9);
try t.release("right", "7", 9);
try t.stable(700, 15000);
try t.snap("center-open");
// The narrow-window split keeps the source shell above the new file. Use the
// unchanged right-hand shell for the remaining references, so they stay visible.
try t.press("left", "80", 9);
try t.release("left", "80", 9);
try t.key("i");
try t.send("big.txt:150 big.txt:2");
try t.key("esc");
try t.stable(400, 5000);
try t.press("right", "82", 9);
try t.release("right", "82", 9);
try t.stable(700, 15000);
try t.snap("center-dedup");
try t.press("right", "94", 9);
try t.release("right", "94", 9);
try t.stable(700, 15000);
try t.snap("center-clamp");
try t.done();
}
// right-click look on a typed path:NN opens a file pane scrolled to the line;
// Enter chord on the same path focuses the existing pane (dedup)
fn look_file(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "look-file");
defer t.deinit();
try t.lines("big.txt", 60, "");
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "big.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("big.txt:40");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "7", 9);
try t.release("right", "7", 9);
try t.stable(700, 15000);
try t.snap("file-open");
try t.style("file-open");
try t.done();
}
// single narrow column (-n 1): the first document splits below its source
// shell, like Term. A new column would require at least 200 cells of width.
fn look_file_1col(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "look-file-1col");
defer t.deinit();
try t.lines("big.txt", 60, "");
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "big.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("big.txt:40");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "7", 9);
try t.release("right", "7", 9);
try t.stable(700, 15000);
try t.snap("file-open-1col");
try t.done();
}
// a look matches an already-LOADED pane before touching the filesystem: open
// big.txt:40 from a look, rm the file on disk, then look big.txt:10 — the
// loaded pane focuses and recenters even though realpath now fails. (This
// fs-last ordering is what lets the fs-less web build focus dump panes.)
fn lookloaded(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lookloaded");
defer t.deinit();
try t.lines("big.txt", 60, "");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "big.txt");
try t.stable(700, 20000);
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("big.txt:40 big.txt:10");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "7", 9);
try t.release("right", "7", 9);
try t.stable(700, 15000);
try t.snap("file-open");
// Use the unrelated right-hand shell to remove the file: the source shell now
// stays above its file and is only a few rows tall.
try t.press("left", "70", 12);
try t.release("left", "70", 12);
try t.stable(400, 5000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("rm big.txt; echo GO''NE");
try t.key("enter");
try t.wait(8000, "GONE");
try t.stable(700, 15000);
try t.key("c-b");
try t.stable(600, 8000);
try t.snap("removed");
// look big.txt:10: nothing on disk, but the pane is loaded — it focuses and
// recenters on line 10 (before this change: realpath fails, look no-ops)
// Put a fresh reference in the right-hand shell, then look it. This ensures the
// gesture hits the missing path rather than empty space after source resizing.
try t.press("left", "55", 9);
try t.release("left", "55", 9);
try t.key("i");
try t.send("big.txt:10");
try t.key("esc");
try t.stable(400, 5000);
try t.press("right", "57", 9);
try t.release("right", "57", 9);
try t.stable(700, 15000);
try t.snap("look-noFS");
try t.done();
}
// a look resolves against EVERY open pane's directory, in access order: the
// pane the click came from first, then the rest most-recently-focused first,
// and only a word NO directory holds falls through to a search. Two dirs
// (alpha, beta) hold same-named files and the shell's own cwd holds none of
// them, so every look below would have been a search before. alpha's pane
// is its directory window (a look at a directory opens a pane listing it),
// whose directory is alpha.
fn lookpanes(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lookpanes");
defer t.deinit();
try t.dir("alpha");
try t.dir("beta");
try t.file("zzboot.txt", "x");
try t.file("alpha/amark.txt", "a");
try t.file("alpha/zqonly.txt", "ONLY-IN-ALPHA");
try t.file("alpha/pick.txt", "PICK-FROM-ALPHA");
try t.file("alpha/twin.txt", "TWIN-FROM-ALPHA");
try t.file("alpha/both.txt", "BOTH-FROM-ALPHA");
try t.file("beta/pick.txt", "PICK-FROM-BETA");
try t.file("beta/twin.txt", "TWIN-FROM-BETA");
try t.file("beta/both.txt", "BOTH-FROM-BETA");
// the file argument opens a pane whose directory is beta's, and nothing else —
// so the workdir shell every look below falls through is opened with Alt-n
// (`New`/`Newcol` open an empty +New scratch now, and one inheriting beta's
// directory at that) and Alt-c puts it in a column of its own on the right;
// its first line is a word to look FROM that pane
try t.file("beta/bmark.txt", "both.txt\nb-marker");
// Builtins announce themselves by default, and an announcement is a band at
// the top of the body -- which moves every row this script clicks. What the
// verbs do is what is under test, not the announcement.
try t.config("Verbose off");
try t.start(51, 130, &.{"beta/bmark.txt"});
try t.wait(8000, "b-marker");
try t.stable(700, 20000);
try t.key("a-n");
try t.key("a-c");
try t.wait(8000, "zzboot.txt");
try t.stable(700, 20000);
try t.key("space w h");
try t.stable(400, 5000);
// an ordinary dir look on the shell's own ls output: alpha's directory pane,
// split below it, which takes the keyboard
try t.press("right", "@alpha", 6);
try t.release("right", "@alpha", 6);
try t.wait(10000, "amark.txt");
try t.stable(700, 20000);
// type the words to look into what is left of the workdir shell (past its own
// ls output, on the same row: its last row is the resize handle)
try t.press("left", "95", 5);
try t.release("left", "95", 5);
try t.stable(400, 5000);
try t.key("i");
try t.send("zqonly.txt pick.txt twin.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("shells");
// make the beta pane the most recently focused, so the walk has to pass it
try t.press("left", "10", 5);
try t.release("left", "10", 5);
try t.stable(700, 10000);
// zqonly.txt is only under alpha: the clicked shell's cwd fails, beta fails,
// alpha's directory pane answers. Before, this word became a search.
try t.press("right", "@zqonly.txt", 5);
try t.release("right", "@zqonly.txt", 5);
try t.wait(10000, "ONLY-IN-ALPHA");
try t.stable(700, 20000);
try t.snap("other-dir");
// both.txt is in BOTH dirs and alpha is now the most recent (its file pane
// just opened), but the CLICK still wins: looked inside the beta pane it
// opens beta's copy
try t.press("right", "10", 5);
try t.release("right", "10", 5);
try t.wait(10000, "BOTH-FROM-BETA");
try t.stable(700, 20000);
try t.snap("clicked-wins");
// from a pane whose own dir holds neither copy the access order decides:
// focus alpha's directory pane (a click on its first row), look pick.txt (in
// both dirs) from the workdir shell -> alpha's
try t.press("left", "@amark.txt", 9);
try t.release("left", "@amark.txt", 9);
try t.stable(700, 10000);
try t.press("right", "@pick.txt", 5);
try t.release("right", "@pick.txt", 5);
try t.wait(10000, "PICK-FROM-ALPHA");
try t.stable(700, 20000);
try t.snap("mru-alpha");
// focus the beta pane instead and the same look flips: twin.txt is in both
// dirs, beta is most recent, beta's copy opens
try t.press("left", "10", 5);
try t.release("left", "10", 5);
try t.stable(700, 10000);
try t.press("right", "@twin.txt", 5);
try t.release("right", "@twin.txt", 5);
try t.wait(10000, "TWIN-FROM-BETA");
try t.stable(700, 20000);
try t.snap("mru-beta");
try t.style("mru-beta");
try t.done();
}
// RANGED LOOK PATHS. `path:LINE:COL` says where to PARK; a range says what to
// SELECT, and it belongs to the PATH (config.range_sep) rather than to the
// search that is merely the first thing writing one. So this script right-
// clicks the three spellings as ordinary words sitting in a file:
// r.txt:3-5 whole lines 3 through 5
// r.txt:7:4-9 line 7, columns 4 through 9
// r.txt:3:2-5:3 line 3 column 2 through line 5 column 3
// ...and only then presses `/`, whose result rows are exactly this syntax —
// which is how n/N select a hit and Enter lands on it with the matched text
// selected.
//
// `snapstyle` is the assertion that matters: the grid TEXT after a ranged look
// is the same text a plain `:LINE:COL` look leaves, so the selection only shows
// in the styles.
fn lookrange(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lookrange");
defer t.deinit();
try t.file("r.txt", "aaaa\nbbbb\ncccc dccc\ndddd\neeee\nffff\ngg NEEDLE gg\nhhhh NEEDLE\niiii");
try t.file("look.txt", "r.txt:3-5\nr.txt:7:4-9\nr.txt:3:2-5:3\nr.txt:8:6-99:9");
// Builtins announce themselves by default, and an announcement is a band at
// the top of the body -- which moves every row this script clicks. What the
// verbs do is what is under test, not the announcement.
try t.config("Verbose off");
try t.start(31, 150, &.{"look.txt"});
try t.wait(8000, "r.txt:3-5");
try t.stable(700, 20000);
try t.snap("opened");
// --- form 1: whole lines. r.txt opens BELOW look.txt (an ordinary look) with
// lines 3, 4 and 5 selected whole, terminators included — helix's own `x`.
try t.press("right", "10", 4);
try t.release("right", "10", 4);
try t.wait(10000, "cccc dccc");
try t.stable(700, 15000);
try t.snap("wholelines");
try t.style("wholelines");
// --- form 2: one line, a column span. r.txt is open now, so this re-uses that
// pane (focusPaneByPath) — the same route a `/` result row takes.
try t.press("right", "12", 5);
try t.release("right", "12", 5);
try t.stable(700, 15000);
try t.snap("onelinespan");
try t.style("onelinespan");
// --- form 3: the general one, across both lines and columns
try t.press("right", "12", 6);
try t.release("right", "12", 6);
try t.stable(700, 15000);
try t.snap("fullspan");
try t.style("fullspan");
// --- a STALE range: line 99 of a nine-line file, which is what a result row
// looks like once the file has changed underneath it. It must CLAMP — no crash,
// no garbage highlight — landing on the last cell that really exists.
try t.press("right", "12", 7);
try t.release("right", "12", 7);
try t.stable(700, 15000);
try t.snap("stale");
try t.style("stale");
// --- and `/`: its query pane under r.txt, line 1 the pattern, the lines
// holding it as rows (a line number in the gutter, the match tinted); Enter
// puts the keyboard on the match after the cursor, the word itself selected.
try t.key("/");
try t.send("NEEDLE");
try t.wait(10000, "gg NEEDLE gg");
try t.stable(700, 15000);
try t.key("enter");
try t.stable(700, 15000);
try t.snap("hit1");
try t.style("hit1");
// n: the next match in the text, selected
try t.send("n");
try t.stable(700, 15000);
try t.snap("hit2");
try t.style("hit2");
// N walks back onto the first, still selected
try t.send("N");
try t.stable(700, 15000);
try t.snap("back");
try t.style("back");
try t.done();
}
// RULE: there is ONE focus history and it is a stack of LOCATIONS — a pane and
// a spot in it. Ctrl-o walks it back, Ctrl-i walks it forward again, `SPC j j`
// (Last) hops to the newest OTHER pane, and `SPC j l` (Jumplist) writes the
// same stack out as an output buffer whose rows are ordinary look targets, so
// n/N step them. What gets ONTO the stack is decided in one place (trackJump):
// focus ended the update in a different pane, or more than a bodyful of rows
// away in the same one — which is why `100G` below leaves a location behind
// and the j/k that follow it do not.
//
// Focus and position both show in the golden's `cursor=` header: that is the
// ACTIVE pane's cursor, so each snap is named by where it should land.
fn jumps(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "jumps");
defer t.deinit();
try t.lines("big.txt", 200, "");
try t.start(31, 150, &.{"big.txt"});
try t.wait(8000, "big.txt");
try t.stable(700, 20000);
// a FILE boots alone now, so this is one column holding big.txt, focused, and
// the stack is one entry deep
try t.snap("start");
// two focus moves. The shell has to be opened before it can be walked to
// (`New`/`Newcol` open an empty +New scratch now, so the shell is asked for by
// name): Alt-n opens it AND focuses it, Alt-c moves it into a column of its
// own on the right — so opening it IS the first of the two moves, and the
// stack below is the same one a shell at boot left. Walking straight back to
// the file does NOT leave `file -> shell -> file` behind: a hop to the entry
// under the top one is the same two places again, so trackJump swaps them
// rather than appending, and the stack is `shell -> file` with the file on top
// (see trackJump).
try t.key("a-n");
try t.key("a-c");
try t.stable(700, 15000);
try t.snap("to-shell");
try t.key("space w h enter");
try t.stable(400, 5000);
try t.snap("to-file");
// a FAR motion inside one pane: 100G is a jump, so the line we left is
// remembered and Ctrl-o can come back to it
try t.send("100");
try t.key("G");
try t.stable(400, 5000);
try t.snap("goto-100");
// Ctrl-o: back to line 1 of the same pane — a stack of panes could not do this
try t.key("c-o");
try t.stable(400, 5000);
try t.snap("back-in-file");
// ...and back again into the shell
try t.key("c-o");
try t.stable(400, 5000);
try t.snap("back-to-shell");
// Ctrl-i forward, twice: back to line 1 of the file, then line 100 again. Sent as the
// kitty-protocol CSI u (`CSI 105;5u`) because on the wire Ctrl-i IS Tab —
// see config.jump_keys.
try t.send("\x1b[105;5u");
try t.stable(400, 5000);
try t.snap("forward-file");
try t.send("\x1b[105;5u");
try t.stable(400, 5000);
try t.snap("forward-100");
// SPC j j — the newest OTHER pane, and pressing it again comes straight back
try t.key("space j j");
try t.stable(400, 5000);
try t.snap("last");
try t.key("space j j");
try t.stable(400, 5000);
try t.snap("last-back");
// SPC j l — the stack as text: `location text` rows, the file naming itself
// and the shell spelled @pN because it has no path
try t.key("space j l");
try t.stable(700, 15000);
try t.snap("jumplist");
// n/N select the next/prev row and Enter looks it, exactly as they do a
// +Search: the stepped span is selected in the buffer (snapstyle) and the Enter
// after it moves the pane the row names. Row 1 is the shell (no path, so
// `@pN`), row 2 the file at line 1, row 4 the file at line 100 — so the body
// visibly rides the list.
//
// ONE PRESS PER ROW, and this buffer is where that rule earns itself: an `@pN`
// row's trailing text is the pane's DIRECTORY, which is a look-able word of its
// own, so rows 1 and 3 used to hold TWO stops each and reaching the next row
// took two steps. A results buffer is a LIST — its rows are locations, and the
// text after one says what is THERE rather than naming another place to go — so
// the walk takes the location at the head of a row and moves on to the next row
// (output_pane.Grain.line). Free text still steps every word.
//
// An `@pN` row moves focus like any other, which it did not use to: the STEP
// only selects now, and the look Enter runs goes to the pane by the same route
// a path takes.
try t.key("space j n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step1-shell");
try t.style("step1-shell");
// on to row 2 — one press, the directory on row 1 is no longer a stop of its own
try t.key("space j n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step2-file");
// row 3 is the shell again, then row 4
try t.key("space j n");
try t.stable(400, 5000);
try t.key("space j n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step4-line100");
// N is the exact inverse: one press back onto row 3's location, and Enter
// follows it to the shell
try t.key("space j p");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step-back");
// and an ordinary LOOK on a row goes there too — the leading word IS a
// location, so the right-click look resolves it like any other path. Row 4
// again, this time by clicking it: the list shows every row, and its row 4 is
// screen row 21.
try t.press("right", "16", 21);
try t.release("right", "16", 21);
try t.stable(700, 15000);
try t.snap("look-row");
try t.done();
}
// `@`...`` — a word that names a COMMAND instead of a file to open. The
// delimiters are config.cmd_open/cmd_close and nothing else in the editor knows
// how one is spelled.
//
// A backtick is not a file char, so the ordinary word expansion would stop dead
// inside one and hand a look the fragment `echo`. config.wordBounds takes the
// whole run instead, which is what makes a single CLICK the way you invoke one
// (acme does the same for its own `<`/`|`/`>` command words).
//
// EXECUTE runs it, as a command pane, and leaves you where you were; LOOK runs
// it and lands you in the pane that answered — looking at a thing means being
// shown it, and a directory's look is a pane listing it, as acme's directory
// window is.
//
// And Look and Exec are ORDINARY BUILTINS now, so their names are executable
// words like Save or Grep: `Look p.txt` run off the page is the same look a
// right click on `p.txt` is. Which is also what makes `@`Look .`` nest — Exec
// unwraps it and the contents go straight back through the one dispatcher.
fn cmdword(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "cmdword");
defer t.deinit();
try t.file("cmds.txt", "@`echo ZZ''E` @`echo ZZ''L` Look p.txt @`Look .`");
try t.file("p.txt", "just text");
try t.file("zzmark.txt", "x");
// Builtins announce themselves by default, and an announcement is a band at
// the top of the body -- which would move every row this script clicks. The
// verbs are what is under test here, not the announcement.
try t.config("Verbose off");
try t.start(31, 120, &.{"cmds.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "cmds.txt");
try t.stable(700, 20000);
try t.snap("opened");
// a single middle CLICK inside the run (col 11 is inside `echo`) expands to the
// whole `@`echo ZZ''E`` and runs it as a command pane; focus stays on the file
try t.press("middle", "11", 4);
try t.release("middle", "11", 4);
try t.wait(10000, "ZZE");
try t.stable(700, 15000);
try t.snap("atexec");
// LOOK on the second one (col 24, inside its `echo`) runs it too, in the same
// command pane now its first is done, below it, AND focuses it — that is the
// whole difference between the two verbs
try t.press("right", "24", 4);
try t.release("right", "24", 4);
try t.wait(10000, "ZZL");
try t.stable(700, 15000);
try t.snap("atlook");
// `Look p.txt` middle-dragged: the builtin by NAME, with an argument
try t.press("middle", "36", 4);
try t.drag("middle", "45", 4);
try t.release("middle", "45", 4);
try t.wait(10000, "just text");
try t.stable(700, 15000);
try t.snap("lookword");
// nesting: `@`Look .`` — Exec unwraps it, `Look .` is parsed as the ordinary
// Look builtin with an argument, and Look opens the directory: a pane named
// for it with a trailing /, listing it (zzmark.txt is only ever in that
// listing: no pane here shows it otherwise), which takes the keyboard
try t.press("middle", "49", 4);
try t.release("middle", "49", 4);
try t.wait(10000, "zzmark.txt");
try t.stable(700, 15000);
try t.snap("nested");
// the same syntax typed into a TAG — the other place the expansion has to know
// about backticks. The look above left the directory pane focused, so `:`
// opens ITS tag; `A` appends at the end of it, Esc and `h` put the
// normal-mode cursor on the last character typed, and the execute key runs
// the word under it exactly as the body's does.
try t.key(":");
try t.key("A");
try t.key("space");
try t.send("Exec");
try t.key("esc");
try t.settle(100);
try t.key("h");
try t.key("tab");
try t.stable(700, 8000);
// ...except that word is `Exec` ITSELF, with nothing to execute. This is the
// case that must not hang a re-entrant dispatcher: it runs out of argument
// immediately and does nothing at all. Executing gave the keyboard back to the
// body, and `:` finds the tag's cursor where it was left.
try t.snap("execword");
// a command word run from that tag runs as a command pane in the directory
// the pane lists, as a word run from any text pane's tag does
try t.key(":");
try t.key("A");
try t.key("space");
try t.send("@`echo ZZ''T`");
try t.key("esc");
try t.settle(100);
try t.key("h");
try t.key("tab");
try t.wait(10000, "ZZT");
try t.stable(700, 15000);
try t.snap("tagcmd");
try t.done();
}
// Language intelligence end to end: the helix keymap, the async round trip and
// the two dispositions of an answer.
//
// The backend behind the seam here is zls, run as a child process by the
// protocol client (it must be on PATH): `gd` is a request on a worker thread
// whose result comes back as an ordinary event, the same shape a pty read
// already had. Nothing in this script knows that: it presses keys and reads
// the grid, which is the point of the seam.
//
// a.zig is deliberately self-contained — a definition, a call site, and not one
// symbol from std — so these goldens do not encode this machine's stdlib
// version or its install path.
fn lsp(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsp");
defer t.deinit();
try t.file("a.zig", "const std = @import(\"std\");\n\nfn helper(x: u32) u32 {\n return x + 1;\n}\n\npub fn main() void {\n _ = helper(41);\n}\n");
try t.start(41, 120, &.{"a.zig"});
try t.wait(8000, "helper");
try t.stable(700, 20000);
try t.snap("opened");
// park the cursor inside the CALL `helper(41)` (file line 8, grid row 9)
try t.press("left", "18", 11);
try t.release("left", "18", 11);
try t.stable(400, 5000);
try t.snap("cursor");
// gd on a call: exactly one location comes back, so it JUMPS rather than
// opening a picker — and lands SELECTING the definition's name token on line 3,
// because ZLS answers with a range and a ranged row is one a look selects.
// The jumplist is pinned first, so ctrl-o comes back.
try t.key("g");
try t.key("d");
try t.stable(700, 15000);
try t.snap("definition");
// SPC l k is hover (K is keep_selections in helix and stays that way). The answer
// is prose, not locations, so it opens +Hover and does NOT arm the n/N stepper.
try t.key("space");
try t.key("l");
try t.key("k");
try t.stable(700, 15000);
try t.snap("hover");
// SPC l s lists the file's own symbols. Several rows, so it opens a +Search
// buffer — which IS the picker: n selects a row and Enter looks it, exactly as
// the Find and `/` results already do, with no picker code of its own.
try t.key("space");
try t.key("l");
try t.key("s");
try t.stable(700, 15000);
try t.snap("symbols");
try t.key("space j n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step");
// gd on something with no declaration behind it (a keyword) answers nothing,
// and nothing is a legal answer: no buffer opens, no error is rendered.
try t.press("left", "8", 6);
try t.release("left", "8", 6);
try t.key("g");
try t.key("d");
try t.stable(700, 10000);
try t.snap("nothing");
try t.done();
}
// The protocol client end to end, against the deterministic mock server the
// harness pins via PARDES_LSP_RS (test/lspmock.zig). What this exercises is
// everything BETWEEN the keymap and the analyser: spawn, handshake, the reader
// thread, $/progress narration onto the transient message row, and the
// location shapes coming back as +Search rows.
// gd on a cross-file Location -> a look: lib.rs opens with `add` selected,
// and the message row still carries the server's settled state
// ("lsp lspmock: ready") because nothing has cleared it yet.
// gr -> the text's query pane, line 1 `Refs`, rows under their files,
// the next occurrence current, the keyboard on it in normal mode
// (a list answered, not a query typed); n/N step the places.
fn lsp_client(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsp-client");
defer t.deinit();
try t.file("main.rs", "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n");
try t.file("lib.rs", "// mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n");
try t.start(25, 100, &.{"main.rs"});
try t.wait(8000, "add(1, 2)");
try t.stable(700, 20000);
// cursor into the first `add` call, then helix's goto-definition
try t.press("left", "13", 6);
try t.release("left", "13", 6);
try t.key("g");
try t.key("d");
try t.wait(10000, "pub fn add");
try t.stable(700, 15000);
try t.snap("gd-jumped");
// references from the definition the look landed on (cursor sits on `add`)
try t.key("g");
try t.key("r");
try t.wait(10000, "add(3, 4)");
try t.stable(700, 15000);
try t.snap("gr-list");
// the list opens in normal mode, the caret on the current row: n steps to
// the next hit, Enter lands there; N in the text goes back to the one
// before, round the places in main.rs
try t.key("n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("gr-opened");
try t.send("N");
try t.stable(700, 15000);
try t.snap("gr-back");
try t.done();
}
// The protocol client's MUTATING answers, through the @put record path: a
// server TextEdit response becomes one atomic buffer edit with one undo step.
// = applies the mock's formatting edit (a header line) and narrates
// "formatted 1 range(s)" on the message row
// SPC l r renames both `add` calls via the server's WorkspaceEdit
// u reverses each as a single transaction
fn lsp_client_edit(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsp-client-edit");
defer t.deinit();
try t.file("main.rs", "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n");
try t.file("lib.rs", "// mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n");
try t.start(25, 100, &.{"main.rs"});
try t.wait(8000, "add(1, 2)");
try t.stable(700, 20000);
try t.key("=");
try t.wait(10000, "formatted by mock");
try t.stable(700, 15000);
try t.snap("formatted");
try t.key("u");
try t.wait(8000, "mod lib;");
try t.stable(700, 15000);
try t.snap("unformatted");
// rename through the leader prompt: both call sites change in one step
try t.press("left", "13", 6);
try t.release("left", "13", 6);
try t.key("space");
try t.key("l");
try t.key("r");
try t.stable(400, 5000);
try t.send("sum");
try t.key("enter");
try t.wait(10000, "sum(3, 4)");
try t.stable(700, 15000);
try t.snap("renamed");
try t.key("u");
try t.wait(8000, "add(3, 4)");
try t.stable(700, 15000);
try t.snap("unrenamed");
try t.done();
}
// Tab after a dot in insert mode: "what could go here".
//
// Each wait for zls's answer allows a minute: it returns as soon as the answer
// is drawn (2 s alone), and a zls slowed by a loaded machine (the parallel
// snap run) took over 15 s, which failed the old wait. The answer is a
// `+Search` buffer of zls's candidates, one row each at the cursor (a
// completion item names no declaration) — nothing is inserted and nothing pops
// up.
//
// a.zig is std-free for the reason lsp.snap's is: these goldens must not encode
// this machine's stdlib version or its install path. Its enum members are
// nonsense words, and the dot is TYPED into an empty switch body, so a row
// naming line 2 or 3 can only have come from a member's declaration — the line
// the cursor is on is line 8 and holds nothing but the dot.
//
// Typing it is the point rather than pointing at one already there: the moment
// the dot lands the file STOPS PARSING (`switch (s) { . }` loses the whole
// switch to the parser's error recovery), and that is the normal input to a
// completion, not a corner case.
//
// The helix corpora cannot reach any of this — hxOpenFileContent names its pane
// `/hxcase.txt`, so lsp.speaks is false for all 1042 cases — which makes this
// script the only end-to-end coverage the feature has.
fn lspcomplete(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lspcomplete");
defer t.deinit();
try t.file("a.zig", "const Shade = enum {\n verdigris,\n cinnabar,\n};\n\nfn pick(s: Shade) u8 {\n return switch (s) {\n \n };\n}\n\n// note. see below\n");
try t.file("notes.txt", "abc.def ghi\n");
try t.start(41, 120, &.{"a.zig"});
try t.wait(8000, "verdigris");
try t.stable(700, 20000);
try t.snap("opened");
// Tab with no dot before it is still Tab: line 10 is the closing `}`, and this
// is the plain insert_tab path putting spaces in front of it.
try t.press("left", "8", 13);
try t.release("left", "8", 13);
try t.key("i");
try t.key("tab");
try t.stable(400, 5000);
try t.snap("indent");
try t.key("esc");
try t.settle(100);
// A dot the backend cannot answer must STILL indent. Line 12 is a comment, so
// the position context is `.comment` and no candidate can exist — and because
// Tab had already diverted to the backend, the indent has to happen
// retroactively when the empty answer arrives (lspResponse), on the condition
// that the cursor has not moved meanwhile. Four spaces go in after `// note.`
// and the keystroke is not eaten, which is the whole contract.
try t.press("left", "16", 15);
try t.release("left", "16", 15);
try t.stable(400, 5000);
try t.key("i");
try t.key("tab");
try t.stable(700, 15000);
try t.snap("commentindent");
try t.key("esc");
try t.settle(100);
// Line 8 (grid row 9, 1-based click row 10) is the switch's empty body. End
// puts the cursor past its indent, and then the dot is typed.
try t.press("left", "8", 11);
try t.release("left", "8", 11);
try t.stable(400, 5000);
try t.key("i");
try t.key("end");
try t.send(".");
try t.stable(400, 5000);
try t.snap("athedot");
try t.key("tab");
// The rows that prove it: `verdigris` and `cinnabar` can only have come from
// resolving the switch's condition to `Shade` and asking what it declares.
// Line 8 still reads `.` and nothing else — a completion INSERTS NOTHING.
try t.wait(60000, "+Search");
try t.stable(700, 30000);
try t.snap("completion");
// Two more Tabs. Every one of them answers, and every answer REFILLS the one
// `+Search` rather than opening its twin. The SECOND press is already the whole
// assertion: without the refill it leaves a second byte-identical `+Search` and
// this golden diverges. What TWENTY do is only worse in degree — fifteen
// stacked panes, the file crushed to one visible line, and from the sixteenth
// on freeSlot returns null and the keystroke is eaten for the rest of the
// session — and that story is told here rather than replayed in three seconds of
// every suite run. One file pane, one results pane, same as after the first.
try t.key("tab");
try t.settle(150);
try t.key("tab");
try t.settle(150);
try t.key("tab");
try t.stable(700, 30000);
try t.snap("refill");
// The pane is still in insert mode, which is right — the query answered beside
// the cursor and typing goes on — so walking the answer means leaving it first,
// the same as for any other results buffer.
try t.key("esc");
try t.settle(100);
// Several rows, so the buffer IS the picker and n walks it; completion does not
// jump the way a goto with one row does. The first step selects row 1, and the
// Enter after it looks that row and lands SELECTING `verdigris` on line 2 of
// a.zig.
try t.key("space j n");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("step");
// A pane the backend does not speak: same keystrokes, same dot before the
// cursor, and Tab must still indent — synchronously this time, since the core
// never asks. The gate is lsp.speaks, which the core consults and the backend
// owns.
try t.start(41, 120, &.{"notes.txt"});
try t.wait(8000, "abc.def");
try t.stable(700, 20000);
try t.press("left", "12", 4);
try t.release("left", "12", 4);
try t.key("i");
try t.key("tab");
try t.stable(400, 5000);
try t.snap("txtindent");
// ---- the two genuinely INCOMPLETE states ----
//
// Everything above types its dot into syntax that is otherwise finished, which
// is the easy half and is why a repair chosen by parse-error count looked like
// it worked. Mid-typing, the line is short of its terminator too.
//
// `const z: Shade = .` is ONE parse error with or without a placeholder
// identifier spliced in, so the repair has to be chosen by whether it makes the
// dot reachable in the tree, never by counting errors.
try t.file("c.zig", "const Shade = enum {\n verdigris,\n cinnabar,\n};\n\npub fn nosemi() void {\n const z: Shade = \n}\n");
try t.start(19, 100, &.{"c.zig"});
try t.wait(8000, "nosemi");
try t.stable(700, 20000);
try t.press("left", "8", 10);
try t.release("left", "8", 10);
try t.stable(400, 5000);
try t.key("i");
try t.key("end");
try t.send(".");
try t.stable(400, 5000);
try t.key("tab");
try t.wait(60000, "+Search");
try t.stable(700, 30000);
try t.snap("nosemi");
// ...and a construct still hanging OPEN. The switch has no closing brace at
// all — the one `}` in the file closes it and leaves the function unclosed —
// which makes Zig's recovery throw the whole declaration away. No placeholder
// sitting at the dot can survive that, so the repair has to close the construct
// as well, on the same line (a spelling containing a newline would move every
// line number the rows are built from).
try t.file("d.zig", "const Shade = enum {\n verdigris,\n cinnabar,\n};\n\npub fn nobrace(s: Shade) void {\n switch (s) {\n \n}\n");
try t.start(19, 100, &.{"d.zig"});
try t.wait(8000, "nobrace");
try t.stable(700, 20000);
try t.press("left", "8", 11);
try t.release("left", "8", 11);
try t.stable(400, 5000);
try t.key("i");
try t.key("end");
try t.send(".");
try t.stable(400, 5000);
try t.key("tab");
try t.wait(60000, "+Search");
try t.stable(700, 30000);
try t.snap("nobrace");
try t.done();
}
// The guard that makes "an empty answer indents" safe to have at all.
//
// lspcomplete.snap pins the indent itself: Tab after a dot the backend cannot
// answer diverts, the answer comes back empty, and four spaces go in LATE so
// the keystroke is not eaten. That late write is the dangerous half — it lands
// a few hundred milliseconds after the key, by which time the hands have moved
// on — so lspResponse only performs it if nothing has: same pane, still insert,
// one cursor, cursor still on the cell the Tab was pressed at. Nothing covered
// the condition, only its happy side.
//
// Same file and same click as lspcomplete's `commentindent` arm — line 12 is a
// comment, so no candidate can exist and the answer is certainly empty — but
// here an `x` is typed straight after the Tab, in the same write, long before a
// ZLS analysis can finish. The buffer below is the assertion: `// note.x`, with
// neither `// note. x` (the indent landing under the typing) nor
// `// note.x ` (the indent landing on top of it).
fn lspcompletemoved(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lspcompletemoved");
defer t.deinit();
try t.file("a.zig", "const Shade = enum {\n verdigris,\n cinnabar,\n};\n\nfn pick(s: Shade) u8 {\n return switch (s) {\n \n };\n}\n\n// note. see below\n");
try t.start(21, 120, &.{"a.zig"});
try t.wait(8000, "verdigris");
try t.stable(700, 20000);
try t.press("left", "16", 15);
try t.release("left", "16", 15);
try t.stable(400, 5000);
try t.key("i");
try t.key("tab");
try t.send("x");
try t.stable(700, 20000);
try t.snap("typedthrough");
try t.key("esc");
try t.settle(100);
try t.key("space f s");
try t.stable(700, 15000);
try t.snapFile("buffer", "/tmp/pardes-snap/lspcompletemoved/cwd/a.zig");
try t.done();
}
fn lspdebug(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lspdebug");
defer t.deinit();
try t.file("z.zig", "const std = @import(\"std\");\n\nfn helper() u32 {\n return 3;\n}\n\npub fn main() void {\n const v = helper();\n _ = v;\n}\n");
// Builtins announce themselves by default, and an announcement is a band at
// the top of the body -- which moves every row this script clicks. What the
// verbs do is what is under test, not the announcement.
try t.config("Verbose off");
try t.start(45, 120, &.{"z.zig"});
try t.wait(8000, "fn helper");
try t.stable(700, 20000);
try t.snap("opened");
// Ctrl-click jumps to the definition; plain click only moves the cursor.
try t.press("ctrl-left", "22", 11);
try t.release("ctrl-left", "22", 11);
try t.stable(700, 15000);
try t.snap("ctrlclick");
try t.press("left", "22", 11);
try t.release("left", "22", 11);
try t.stable(700, 15000);
try t.snap("plainclick");
try t.send("3gg1g|");
try t.stable(400, 10000);
try t.key("space l w");
try t.wait(10000, "lsp explain — the definition query");
try t.wait(10000, "row(s)");
try t.key("space w j enter");
try t.key("space d");
try t.stable(700, 15000);
try t.snap("why-closed");
// Check the report's answers, not installed compiler paths or dependency counts.
try t.key("space l i");
try t.wait(10000, "language servers:");
try t.wait(10000, "zls");
try t.key("space w j enter");
try t.key("/");
try t.send("client queries");
try t.key("enter");
try t.wait(10000, "client queries");
try t.wait(10000, "definition");
// Enter left the keyboard in the report, on the match; its query pane is
// attached to it, so one Del closes both, their rows back to the source
try t.key("space d");
try t.stable(700, 15000);
try t.snap("report-closed");
try t.done();
}
// What a language row SPELLS its path as, and that both spellings still LOOK.
//
// A row spells its path the shortest way a Look from the query pane resolves
// (Query.lookPath): relative to the pane's directory, `../` included, when that
// is shorter than the absolute path, else absolute — a `gr` list was otherwise
// the same forty-character prefix repeated down the pane with the part you came
// to read pushed off the right edge.
//
// A row in the SAME directory shortens to a bare basename; the two that a
// careless shortening can get wrong are here, one app each, as `gr` rows
// (the file headers of the asking text's query pane, line 1 `Refs`):
//
// PARENT the enum is one level UP from the asking file, so the row
// climbs: `../shade.zig`, shorter than `/tmp/.../cwd/shade.zig`,
// and a Look from the pane still lands on it.
// SUBDIRECTORY the enum is one level DOWN, so the strip leaves a path with a
// separator still in it — `inner/tint.zig`, not `tint.zig`. A
// strip that took the basename instead would produce a row that
// resolves to nothing.
//
// `n` and the Enter after it are the assertion in both, not the row text: the
// step selects row 1, the look opens the right file with the member SELECTED
// on its own line, and focus follows what opened — so the snap header's cursor
// is that pane's, and the style capture is where the selection itself shows.
fn lsprelpath(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsprelpath");
defer t.deinit();
try t.dir("sub");
try t.dir("sub/inner");
try t.file("shade.zig", "pub const Shade = enum {\n verdigris,\n cinnabar,\n};\n");
try t.file("sub/inner/tint.zig", "pub const Tint = enum {\n ochre,\n indigo,\n};\n");
try t.file("sub/parent.zig", "const shade = @import(\"../shade.zig\");\n\npub fn pick(s: shade.Shade) u8 {\n return switch (s) {\n \n };\n}\n");
try t.file("sub/subdir.zig", "const tint = @import(\"inner/tint.zig\");\n\npub fn hue(t: tint.Tint) u8 {\n return switch (t) {\n \n };\n}\n");
// ---- PARENT: outside the asking file's tree, so the row climbs ----
try t.start(35, 100, &.{"sub/parent.zig"});
try t.wait(8000, "fn pick");
try t.stable(700, 20000);
try t.press("left", "31", 6);
try t.release("left", "31", 6);
try t.stable(400, 5000);
try t.key("g");
try t.key("r");
// the query pane under parent.zig, line 1 `Refs`, the rows under each file:
// shade.zig's spelled from above, `../shade.zig`
try t.wait(15000, "../shade.zig:1");
try t.stable(700, 15000);
try t.snap("absrow");
// the current row is parent.zig's own; the one before it is shade.zig's,
// shown in the +Preview (N, the list in normal mode), which Enter makes
// shade.zig's pane
try t.key("N");
try t.wait(10000, "verdigris");
try t.stable(700, 15000);
try t.key("enter");
try t.stable(700, 15000);
try t.snap("abslook");
try t.style("abslook");
try t.start(35, 100, &.{"sub/subdir.zig"});
try t.wait(8000, "fn hue");
try t.stable(700, 20000);
try t.press("left", "29", 6);
try t.release("left", "29", 6);
try t.stable(400, 5000);
try t.key("g");
try t.key("r");
try t.wait(15000, "inner/tint.zig");
try t.stable(700, 15000);
try t.snap("subrow");
try t.key("N");
try t.wait(10000, "ochre");
try t.stable(700, 15000);
try t.key("enter");
try t.stable(700, 15000);
try t.snap("sublook");
try t.style("sublook");
try t.press("right", "12", 13);
try t.release("right", "12", 13);
try t.stable(700, 15000);
try t.snap("clicked");
try t.done();
}
// Rename end to end: the leader prompt, async ZLS resolution, atomic file edit,
// shadow filtering, and one-step undo/redo. The source has a same-spelled local
// which must not be changed when the top-level helper is renamed.
fn lsp_rename(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsp-rename");
defer t.deinit();
try t.file("rename.zig", "const std = @import(\"std\");\n\nfn helper(x: u32) u32 {\n return x + 1;\n}\n\npub fn main() void {\n _ = helper(41);\n}\n\nfn shadowed() void {\n const helper: u32 = 7;\n _ = helper;\n}\n");
try t.start(25, 110, &.{"rename.zig"});
try t.wait(8000, "helper(41)");
try t.stable(700, 20000);
// Put the cursor inside the top-level call, then use the helix rename binding.
try t.press("left", "18", 11);
try t.release("left", "18", 11);
try t.key("space");
try t.key("l");
try t.key("r");
try t.stable(400, 5000);
try t.send("renamed_helper");
try t.key("enter");
try t.wait(10000, "renamed_helper(41)");
try t.stable(700, 15000);
try t.snap("renamed");
// Both resolved top-level occurrences changed; the shadowed local stayed helper.
// The whole asynchronous rename is one history transaction.
try t.key("u");
try t.stable(400, 5000);
try t.snap("undone");
try t.key("U");
try t.stable(400, 5000);
try t.snap("redone");
try t.done();
}
// A Rename reaches the other files open in the editor. A server renames in
// the documents it has seen (zls's store), so before a query whose answer can
// reach other files the client tells it of every open file of its language.
// Here main.rs is opened by a look, asking the server nothing, and the rename
// is asked from lib.rs: the mock answers in each document it was told of, so
// the preview lists main.rs's two calls and lib.rs's definition.
fn lsp_rename_files(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "lsp-rename-files");
defer t.deinit();
try t.file("lib.rs", "// main.rs\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n");
try t.file("main.rs", "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n");
try t.start(25, 100, &.{"lib.rs"});
try t.wait(8000, "pub fn add");
try t.stable(700, 20000);
try t.press("right", "@main.rs", 4);
try t.release("right", "@main.rs", 4);
try t.wait(8000, "let x = add");
try t.stable(700, 15000);
try t.snap("opened");
// into lib.rs's `add`, and rename it from there
try t.press("left", "@add", 5);
try t.release("left", "@add", 5);
try t.stable(400, 5000);
try t.key("space");
try t.key("l");
try t.key("r");
try t.stable(400, 5000);
try t.send("sum");
try t.key("enter");
try t.wait(10000, "sum");
try t.stable(700, 15000);
try t.snap("previewed");
try t.done();
}
// Static call hierarchy in a dedicated pane; sites and declarations are Look
// targets, the source's colours on them.
fn callstack(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "callstack");
defer t.deinit();
try t.file("main.rs", "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n");
try t.file("lib.rs", "// mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n");
try t.start(40, 110, &.{"main.rs"});
try t.wait(8000, "add(1, 2)");
try t.stable(700, 20000);
try t.press("left", "13", 6);
try t.release("left", "13", 6);
try t.key("g c");
try t.wait(10000, "Callstack");
try t.wait(10000, "recursion");
try t.stable(700, 15000);
try t.snap("hierarchy");
try t.style("hierarchy");
// LookNext selects the caller signature; Enter opens it in the source pane.
try t.key("space j n");
try t.key("enter");
try t.wait(10000, "fn main");
try t.stable(700, 15000);
try t.snap("caller");
try t.done();
}
// A diff pane, for reviewing a change: each hunk's code coloured as Zig (a
// multi-line string over three lines, `defer` inside it no keyword), added and
// removed rows tinted to the pane's edge with their prefix in the tint's hue,
// headers muted. Then a right click on an added line's `+` opens the new file
// at that line: the path is the repository's (a `.git` above the diff), b/
// dropped.
fn diffview(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "diffview");
defer t.deinit();
try t.dir(".git");
try t.dir("src");
try t.file("src/shape.zig", "const std = @import(\"std\");\n\npub const Shape = union(enum) {\n circle: f32,\n square: f32,\n triangle: struct { base: f32, height: f32 },\n\n const note =\n \\\\areas, defer\n \\\\summed\n ;\n};\n");
try t.file("change.diff", "diff --git a/src/shape.zig b/src/shape.zig\nindex 1111111..2222222 100644\n--- a/src/shape.zig\n+++ b/src/shape.zig\n@@ -1,10 +1,12 @@\n const std = @import(\"std\");\n \n pub const Shape = union(enum) {\n circle: f32,\n- square: u8 = 7,\n+ square: f32,\n+ triangle: struct { base: f32, height: f32 },\n \n const note =\n- \\\\areas\n+ \\\\areas, defer\n+ \\\\summed\n ;\n };\n");
try t.start(31, 100, &.{"change.diff"});
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.snap("diff-pane");
try t.style("diff-colours");
try t.press("right", "8", 15);
try t.release("right", "8", 15);
try t.stable(700, 15000);
try t.snap("look-added-line");
// The same diff printed by a command (`git diff`, here `cat`) into a command
// pane: its output is told for a diff and coloured the same, over the colours
// the program printed, and a right click on a `+` there opens the file too.
try t.file("cmds.txt", "cat change.diff\n");
try t.start(31, 100, &.{"cmds.txt"});
try t.wait(8000, "cmds.txt");
try t.stable(700, 20000);
try t.press("middle", "7", 4);
try t.drag("middle", "22", 4);
try t.release("middle", "22", 4);
try t.wait(10000, "exit 0");
try t.stable(700, 15000);
try t.snap("command-pane");
try t.style("command-colours");
try t.press("right", "3", 21);
try t.release("right", "3", 21);
try t.stable(700, 15000);
try t.snap("command-look");
try t.done();
}
// a look at a directory opens a pane named for it with a trailing /, its
// entries in columns as acme's directory window lays them out: down each
// column first, a directory's marked /, dotfiles shown. A look at an entry
// opens it from that directory. No shell anywhere: nothing here races a prompt.
fn dirpane(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "dirpane");
defer t.deinit();
try t.dir("sub");
try t.dir("sub/deeper");
try t.file("sub/inner.txt", "inner-marker");
try t.file("sub/.hidden", "x");
try t.file("sub/alpha.txt", "x");
try t.file("sub/beta-gamma.txt", "x");
try t.file("sub/zeta", "x");
try t.file("top.txt", "sub");
try t.config("Verbose off");
try t.start(24, 80, &.{"top.txt"});
try t.wait(8000, "top.txt");
try t.stable(700, 20000);
try t.press("right", "@sub", 4);
try t.release("right", "@sub", 4);
try t.wait(8000, "inner.txt");
try t.stable(700, 20000);
try t.snap("dir-open");
// an entry, by its name alone: sub's inner.txt
try t.press("right", "@inner.txt", 7);
try t.release("right", "@inner.txt", 7);
try t.wait(8000, "inner-marker");
try t.stable(700, 20000);
try t.snap("entry-open");
try t.done();
}
// scrolloff: keyboard motion keeps 3 context rows above/below the cursor,
// clamped at file boundaries (cursor may reach the top/bottom body row there)
fn scrolloff(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "scrolloff");
defer t.deinit();
try t.lines("g.txt", 40, "");
try t.start(16, 210, &.{ "-n", "1" });
try t.wait(8000, "g.txt");
try t.stable(700, 20000);
// right-click the g.txt name in the greeting ls -> file pane under the shell's
// text, 9 body rows
try t.press("right", "4", 5);
try t.release("right", "4", 5);
try t.wait(10000, "line 3");
try t.stable(700, 15000);
try t.press("left", "10", 9);
try t.release("left", "10", 9);
try t.stable(400, 5000);
// (b) gg: cursor CAN sit on the top body row, no forced scroll
try t.key("g g");
try t.stable(400, 5000);
try t.snap("top");
// (a) five j's reach the bottom margin (visual row 5 of 9) without scrolling...
try t.key("j j j j j");
try t.stable(400, 5000);
try t.snap("edge");
// ...the sixth j scrolls: view slides one line, cursor holds the margin
try t.key("j");
try t.stable(400, 5000);
try t.snap("scrolled1");
try t.key("j j j j");
try t.stable(400, 5000);
try t.snap("jdown");
// (d) ge (goto last line; bare G is a helix no-op): bottom clamp, view stops
// at EOF-at-bottom, cursor on the bottom row
try t.key("g e");
try t.stable(400, 5000);
try t.snap("end");
// (c) k-walk up: cursor climbs to the top margin, then the view scrolls
try t.key("k k k k k k k k");
try t.stable(400, 5000);
try t.snap("kup");
// (b) again from deep in the file: gg puts the cursor back on the top row
try t.key("g g");
try t.stable(400, 5000);
try t.snap("top2");
try t.done();
}
// Soft line breaks: ON by default, off with the Wrap builtin (`SPC t w`). A
// file line too long for the pane renders across several body rows instead of
// running off the right edge.
//
// Three rules pinned here. The break is at the PANE'S OWN content width and
// nothing else — there is no upper bound, a wide window breaks wide. A
// continuation row carries a BLANK gutter (the number belongs to the LINE, and
// a number repeated down a wrapped line would read as several lines) and the
// row it broke out of ends in `↩`, in the one column the wrap keeps free for
// it — a break is otherwise invisible, and an absent line number is a poor
// thing to read a document by. And the mouse follows the render: a click on a
// continuation row lands on the character under the pointer, which only works
// if the click resolves through the same row->line map the body was drawn from.
//
// The line is 20 decades, each headed by its own column marker: `0` at column
// 0, `4` at 40, `A` at 100. So the first character of a continuation row NAMES
// the column it broke at, and the width rule is readable straight off the grid.
fn wrap(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "wrap");
defer t.deinit();
try t.file("long.txt", "0---------1---------2---------3---------4---------5---------6---------7---------8---------9---------A---------B---------C---------D---------E---------F---------G---------H---------I---------J---------\nsecond line\nthird line\n");
// 48 columns: the 2-column chrome gutter, the 5-column line-number gutter and
// the 1 column the `↩` sits in leave 40 for content.
try t.start(15, 48, &.{"long.txt"});
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
// the default: five rows for line 1 (200 bytes / 40), the four continuations
// gutterless and starting at `4` `8` `C` `G` — the columns 40, 80, 120, 160 —
// and each of the first four rows ending in the break marker
try t.snap("on-narrow");
// a click on the SECOND row of line 1, on the `5` marker at column 50. The
// cursor must come back to the cell that was clicked (grid 17,3): the click
// resolved to line 1 column 50, and the render put line 1 column 50 back where
// the finger was. Off by one row and it would land in line 2.
try t.press("left", "18", 5);
try t.release("left", "18", 5);
try t.stable(400, 5000);
try t.snap("clicked");
// motions stay LOGICAL: one `j` from line 1 leaves the whole wrapped line
// behind and lands on line 2, four screen rows down at once.
try t.key("j");
try t.stable(400, 5000);
try t.snap("logical-j");
// ...while `gj`/`gk` are the VISUAL pair. `gg` puts the cursor back at line 1
// column 0 with no goal column left over, `3l` moves three in, and from there
// each `gj` steps ONE screen row: still line 1, the column kept INSIDE the row,
// so the cursor stays in grid column 10 while the row walks 2 -> 3 -> 4. `gk`
// steps back onto the row it came from. This is the only motion that reads the
// wrap map's own arithmetic, so it is the one that can silently become `j`.
try t.key("g g");
try t.stable(400, 5000);
try t.key("3 l");
try t.stable(400, 5000);
try t.key("g j");
try t.stable(400, 5000);
try t.snap("visual-gj");
try t.key("g j");
try t.stable(400, 5000);
try t.snap("visual-gj-again");
try t.key("g k");
try t.stable(400, 5000);
try t.snap("visual-gk");
// a count is counted in ROWS too, and two of them are still inside line 1
try t.key("2 g j");
try t.stable(400, 5000);
try t.snap("visual-count-gj");
// SPC t w turns it off: line 1 back on ONE row, clipped at the right edge with
// no marker, lines 2 and 3 under it — the render this pane had before soft
// breaks existed, because the map the readers consult goes back to empty and
// every one of them falls back to the row arithmetic it used before any of it
try t.key("space t w");
try t.stable(400, 5000);
try t.snap("off");
// ...and on again is on
try t.key("space t w");
try t.stable(400, 5000);
try t.snap("on-again");
// 128 columns: 120 for content, and the break is at the `C` — column 120, the
// window's own width. The old 100-column cap would have broken at the `A`.
try t.start(15, 128, &.{"long.txt"});
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.snap("on-wide");
try t.done();
}
// horizontal scroll, file panes only (terminals wrap at pty width): the
// horizontal wheel shifts the content window (gutter stays put, no scrollbar),
// and keyboard movement keeps the scrolloff margin sideways — $ on a long
// line pulls the view right, 0 snaps it back. Overscroll right is allowed;
// a cursor move reels it in.
fn hscroll(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "hscroll");
defer t.deinit();
try t.file("wide.txt", "short1 END_A_MARKER_WAY_OUT_RIGHT_padpadpadpadpadpadpadpadpadpadpadpadpadpad_TAIL");
try t.start(31, 90, &.{ "-n", "3" });
try t.wait(8000, "wide.txt");
try t.stable(700, 20000);
// soft wrap is ON by default and a wrapped body has nothing to scroll sideways
// — hscroll is what you get when you turn it OFF, so this whole script runs
// with it off. SPC t w is global, so it is spent once, before the file exists.
try t.key("space t w");
try t.stable(400, 5000);
// open wide.txt: click a body spot, type the name, look it
try t.press("left", "5", 9);
try t.release("left", "5", 9);
try t.stable(400, 5000);
try t.key("i");
try t.send("wide.txt");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("right", "7", 9);
try t.release("right", "7", 9);
try t.stable(700, 15000);
try t.snap("opened");
// wheel right over the file pane: content shifts, line numbers stay
try t.send("\x1b[<66;10;8M");
try t.send("\x1b[<66;10;8M");
try t.stable(400, 5000);
try t.snap("wheeled");
// wheel back left past the start clamps at column 0
try t.send("\x1b[<67;10;8M");
try t.send("\x1b[<67;10;8M");
try t.send("\x1b[<67;10;8M");
try t.stable(400, 5000);
try t.snap("clamped");
// gl walks the cursor to the line end: the view follows with the margin
try t.key("g g");
try t.stable(400, 5000);
try t.key("g l");
try t.stable(400, 5000);
try t.snap("dollar");
// 0 back to column zero: the view snaps home
try t.key("0");
try t.stable(400, 5000);
try t.snap("zero");
try t.done();
}
// Follow (SPC c f) twice on a 300-line file: three pages in three columns,
// each going on the line after the one before ends; Unfollow on the two
// followers' tags only. Then j past the first page's last row takes the
// keyboard to the second page without scrolling, and a wheel notch in the
// last page moves all three.
fn follow(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "follow");
defer t.deinit();
try t.lines("big.txt", 300, "");
try t.start(30, 150, &.{"big.txt"});
try t.wait(8000, "big.txt");
try t.stable(500, 15000);
try t.key("space c f");
try t.stable(500, 8000);
try t.key("space c f");
try t.stable(500, 8000);
try t.snap("three-pages");
try t.send("27j");
try t.stable(500, 8000);
try t.snap("hop");
try t.wheel("down", "120", 12);
try t.stable(500, 8000);
try t.snap("wheel");
try t.done();
}
// `:` — vim's command line with acme's vocabulary. It focuses the pane's OWN
// tag in NORMAL mode (block cursor; the layout box shows the pane's BODY mode,
// which for this file pane is normal either way). The tag remembers where its
// cursor was; the first time there is nothing to remember and it starts on
// Save. The tag's normal mode is the body's: w selects the "Save" span exactly
// as a body word motion does, and the execute key runs the word under the
// cursor and hands the body back — same keys as the body, so Tab by default
// (see config.look_key/exec_key). `:` again backs out instead, leaving the tag
// as it was.
fn tagcmd(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "tagcmd");
defer t.deinit();
try t.lines("c.txt", 6, "");
try t.start(31, 100, &.{"c.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "c.txt");
try t.stable(700, 20000);
// edit line 1 so Save has something to write
try t.key("i");
try t.send("ZZEDIT");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("edited");
// `:` -> the tag, in normal mode, cursor on Save
try t.key(":");
try t.stable(400, 5000);
try t.snap("colon");
// w -> the "Save" span (selected, like the body's word motion)
try t.key("w");
try t.stable(400, 5000);
try t.snap("word");
// Tab executes it: c.txt is written and focus is back in the body
try t.key("tab");
try t.stable(600, 8000);
try t.stable(400, 5000);
try t.snap("saved");
try t.snapFile("written", "/tmp/pardes-snap/tagcmd/cwd/c.txt");
// `:` then `:`: back to the body with the tag untouched, nothing run
try t.key(":");
try t.stable(400, 5000);
try t.key(":");
try t.stable(400, 5000);
try t.snap("escaped");
try t.done();
}
// A tag's normal mode is the body's: h/l/w move in the tag's own text, and
// moving between panes is the window keys' job from a tag as from a body --
// there are no tag-only hops. `:` is the one key a tag and a body do not
// share: from the body it focuses the pane's own tag, from the tag it hands the
// keyboard back to the body. Each tag remembers its cursor; the first time
// there is nothing to remember and it starts on Save.
//
// Evidence is the `cursor=` header (the ACTIVE pane's cursor, which while a tag
// is focused sits on THAT pane's tag row) plus each pane's layout box, which
// carries its BODY mode as one character: ` ` normal, `^` insert, `$` tty. The
// tag has a mode of its own, so the box never changes while a tag is used.
fn tagnav(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "tagnav");
defer t.deinit();
try t.file("w.txt", "alpha\nbeta\ngamma");
try t.start(31, 100, &.{"w.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "w.txt");
try t.stable(700, 20000);
// A FILE boots alone, so the launch shell is opened here: Alt-n opens it and
// focuses it, Alt-c puts it in a column of its own on the right, SPC w h Enter
// comes back to the file.
try t.key("a-n");
try t.key("a-c");
try t.stable(700, 15000);
try t.key("space w h enter");
try t.stable(400, 5000);
// Alt-n: a shell below the file, so the left column has two rows and every
// direction has somewhere to go
try t.key("a-n");
try t.stable(700, 15000);
try t.key("space w k enter");
try t.stable(400, 5000);
try t.snap("start");
// `:` -> the file's OWN tagline, normal mode, on Save
try t.key(":");
try t.stable(400, 5000);
try t.snap("colon");
// w selects in the tag the way it selects in a body
try t.key("w");
try t.stable(400, 5000);
try t.snap("word");
// l is a motion in the tag, not a hop to the next pane
try t.key("l l");
try t.stable(400, 5000);
try t.snap("in-tag");
// the window keys move between panes from a tag as from a body: the tag lets
// go and the neighbour's BODY takes the keyboard
try t.key("c-w l enter");
try t.stable(400, 5000);
try t.snap("right");
// `:` there -> that pane's own tag, on its Save the first time
try t.key(":");
try t.stable(400, 5000);
try t.snap("right-tag");
// back left, and `:` finds the file's tag cursor where l left it
try t.key("c-w h enter");
try t.stable(400, 5000);
try t.key(":");
try t.stable(400, 5000);
try t.snap("left-tag");
// `:` in the tag's normal mode: back to the body
try t.key(":");
try t.stable(400, 5000);
try t.snap("back-to-body");
// A TERMINAL KEEPS ITS TTY MODE. Put the launch shell in raw tty mode (Ctrl-b),
// click its tagline and come back: its box reads `$` throughout, because the
// tag's mode is the tag's own.
try t.key("c-w l enter");
try t.stable(400, 5000);
try t.key("c-b");
try t.stable(700, 15000);
try t.snap("tty-on");
try t.press("left", "@Mode", 3);
try t.release("left", "@Mode", 3);
try t.stable(400, 5000);
try t.snap("tty-tag");
try t.key(":");
try t.stable(400, 5000);
try t.snap("tty-restored");
// The column and workspace tags are Texts in the same layout, with the same
// keys: Up from a pane with nothing above it reaches its column's tag, in
// normal mode, then the workspace's; Down comes back the same way.
try t.key("c-b");
try t.stable(700, 15000);
try t.key("c-w h enter");
try t.stable(400, 5000);
try t.key("c-w k");
try t.stable(400, 5000);
try t.snap("column-tag");
try t.key("w");
try t.stable(400, 5000);
try t.snap("column-word");
try t.key("c-w k");
try t.stable(400, 5000);
try t.snap("workspace-tag");
// `$` is the last cell; five long-word steps back land on `Dump`, and the
// execute key runs it and gives the keyboard back to the body FIRST -- `Exit`
// lives up here too, so a builtin that frees the session must never return
// into a focused header. Dump grows a `Restore <path>` word, which is also the
// case where the line gets longer than the column you were parked on.
try t.key("g l");
try t.stable(400, 5000);
try t.snap("topbar-dollar");
try t.key("B B B B B");
try t.stable(400, 5000);
try t.snap("topbar-dump-word");
try t.key("tab");
try t.stable(700, 15000);
try t.snap("topbar-exec");
// THE DELETION HAZARD, from the bar itself: `Restore` frees every pane and
// swaps the core out from under the caller. Walk back up onto the word the
// Dump just grew -- B twice off the tail, because the LONG word motions are the
// ones that step over a path in one go -- and run it.
try t.key("c-w k");
try t.key("c-w k");
try t.stable(400, 5000);
try t.key("g l B B");
try t.stable(400, 5000);
try t.snap("topbar-restore-word");
try t.key("tab");
try t.stable(900, 15000);
try t.snap("topbar-restored");
try t.done();
}
// The path is part of the tag's text for the keyboard as for the mouse: `0`
// goes to its start, `E` selects it and `y` yanks it. It is read-only, but
// typing into it drafts a new name there, as a click on it does. Escape
// cancels; Enter changes buffer identity, never renames a disk file.
fn tagpath(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "tagpath");
defer t.deinit();
try t.lines("c.txt", 4, "");
try t.start(31, 100, &.{"c.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "c.txt");
try t.stable(700, 20000);
try t.snap("start");
try t.key(":");
try t.stable(400, 5000);
try t.snap("colon");
try t.key("0");
try t.stable(400, 5000);
try t.snap("col0");
try t.key("E");
try t.stable(400, 5000);
try t.snap("sel-path");
try t.style("sel-path");
try t.key("y");
// `:` gives the keyboard back to the body, and `p` puts the path there
try t.key(":");
try t.key("p");
try t.stable(400, 5000);
try t.snap("yanked-path");
// Sweep across the path / command boundary without injected padding.
try t.press("left", "12", 3);
try t.drag("left", "30", 3);
try t.drag("left", "42", 3);
try t.release("left", "42", 3);
try t.stable(400, 5000);
try t.snap("drag-cross");
try t.style("drag-cross");
// Esc is the tag's normal mode; typed at the path's start, `/renamed` drafts
// a name
try t.key("esc");
try t.settle(100);
try t.key("0");
try t.key("i");
try t.send("/renamed");
try t.stable(400, 5000);
try t.snap("name-draft");
// Esc keeps the draft pending; a second drops it
try t.key("esc");
try t.settle(100);
try t.key("esc");
try t.stable(400, 5000);
try t.snap("name-cancelled");
try t.key(":");
try t.key("0");
try t.key("i");
try t.send("/renamed");
try t.key("enter");
try t.stable(400, 5000);
try t.snap("name-committed");
try t.done();
}
// a CLICKED tag is in normal mode, its cursor where it was clicked: `i` types
// there (`:` is the door back to the body, see tagcmd); backspace edits; Esc drops to the tag's normal mode, which is
// the body's normal mode, and `:` there hands the keyboard back to the body;
// Enter looks the word at the cursor (Tab executes it). Multi-word execution
// from the tag stays the mouse's job (middle-drag), like anywhere else.
fn tag(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "tag");
defer t.deinit();
try t.file("t.txt", "ZZLOOKED");
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "t.txt");
try t.stable(700, 20000);
// Click the one editable separator before Save, directly after the cwd.
// The former generated alignment gap no longer exists.
// The layout box shows
// the pane's BODY mode, not the tag's; `i` then types into the tag where it
// was clicked.
try t.press("left", "@Save-1", 3);
try t.release("left", "@Save-1", 3);
try t.stable(400, 5000);
try t.snap("tag-focus");
try t.key("i");
try t.send(" t.txt");
try t.stable(600, 8000);
try t.stable(400, 5000);
try t.snap("tag-typed");
try t.key("bs");
try t.key("bs");
try t.key("bs");
try t.key("bs");
try t.stable(400, 5000);
try t.snap("tag-del");
try t.send(".txt");
try t.stable(600, 8000);
try t.stable(400, 5000);
// Esc: the tag's normal mode; `:` then gives the keyboard back to the body,
// which is in normal mode, and the typed text stays
try t.key("esc");
try t.settle(100);
try t.key(":");
try t.stable(400, 5000);
try t.snap("tag-exit");
// re-enter the tag and look the typed word: Enter in normal mode opens t.txt
// as a file pane. Click the inserted word itself; filename, separator and
// commands are compact.
try t.press("left", "@t.txt", 3);
try t.release("left", "@t.txt", 3);
try t.stable(400, 5000);
try t.key("enter");
try t.wait(10000, "ZZLOOKED");
try t.stable(700, 15000);
try t.snap("tag-look");
try t.done();
}
|