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
|
//! The tty frontend's own cases (test/tty.zig), starting: argv, the flags, the topbar's builtins, dumps and loads.
const std = @import("std");
const Tty = @import("../tty.zig").Tty;
pub const cases = .{
.{ "tty boot: argv", argv },
.{ "tty boot: badutf", badutf },
.{ "tty boot: boot", boot },
.{ "tty boot: builtins", builtins },
.{ "tty boot: dump", dump },
.{ "tty boot: load", load },
.{ "tty boot: restore", restore },
.{ "tty boot: headersweep", headersweep },
.{ "tty boot: headersweep-restored", headersweep_restored },
.{ "tty boot: logquiet", logquiet },
.{ "tty boot: tutor", tutor },
.{ "tty boot: topbarexec", topbarexec },
.{ "tty boot: leader", leader },
.{ "tty boot: mini", mini },
.{ "tty boot: ninep", ninep },
.{ "tty boot: nested", nested },
.{ "tty boot: nested-optout", nested_optout },
.{ "tty boot: shellset", shellset },
.{ "tty boot: msg", msg },
.{ "tty boot: winch", winch },
.{ "tty boot: savepane", savepane },
.{ "tty boot: filewatch", filewatch },
};
// argv: bare `pardes` boots one shell already in tty mode; a FILE argument
// opens it ALONE, filling the window (file:LINE scrolls there) — naming a file
// is asking to read it, not to be handed a shell beside it; a DIRECTORY
// argument becomes the cwd the shell spawns in
fn argv(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "argv");
defer t.deinit();
try t.lines("notes.txt", 8, "");
try t.file("zmarker.txt", "x");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("echo ARGV''TTY");
try t.key("enter");
try t.wait(8000, "ARGVTTY");
try t.stable(700, 10000);
try t.snap("noargs");
try t.start(31, 100, &.{"notes.txt:3"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "line 3");
try t.stable(700, 20000);
try t.snap("filearg");
// -n and a FILE are not a combination: the file names the whole boot layout, so
// `-n 3` boots the very same single pane (it always did — the file arm never
// looked at the count; before this it merely also stapled a shell to the right)
try t.start(31, 100, &.{ "-n", "3", "notes.txt" });
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "line 1");
try t.stable(700, 20000);
try t.snap("filearg-n3");
try t.dir("sub");
try t.file("sub/inside.txt", "marker");
try t.start(31, 100, &.{"sub"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "inside.txt");
try t.stable(700, 20000);
try t.snap("dirarg");
try t.done();
}
// Invalid UTF-8 must RENDER, never panic. Two sources, both ordinary use:
// a file pane holds whatever bytes are on disk (latin-1, a truncated sequence,
// an ELF opened by mistake). Undecodable bytes come out as U+FFFD, while
// horizontal scrolling must start at a complete grapheme boundary.
fn badutf(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "badutf");
defer t.deinit();
try t.file("bad.txt", "hello \xff\xfe world\nlatin-1 caf\xe9 tail\ntruncated \xe6\x97 here\nend\n");
try t.file("wide.txt", "日本語 日本語 日本語 日本語 日本語 日本語 日本語 tail\nsecond line\n");
try t.start(31, 100, &.{"bad.txt"});
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.snap("badbytes");
// 50 columns, not 100: a FILE boots alone and fills the window, and at 100 the
// whole line fits, so `$` scrolls nowhere. This is
// the width the left column used to be, i.e. the pane this case was written for
try t.start(31, 50, &.{"wide.txt"});
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
// SPC t w turns soft wrap OFF: hscroll is the other half of this case and a
// wrapped body has nothing to scroll sideways. The unwrapped view must keep the
// first visible CJK glyph intact instead of starting inside its UTF-8 bytes.
try t.key("space t w");
try t.stable(400, 5000);
try t.key("g l");
try t.stable(700, 10000);
try t.snap("hscroll-midglyph");
try t.done();
}
// -n 1: one shell pane in normal mode, greets with ls; prompts hidden
fn boot(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "boot");
defer t.deinit();
try t.file("hello.txt", "marker-content");
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "hello.txt");
try t.stable(700, 20000);
try t.snap("boot");
try t.style("boot");
try t.done();
}
fn builtins(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "builtins");
defer t.deinit();
try t.lines("notes.txt", 6, "");
try t.start(67, 120, &.{"notes.txt"});
try t.wait(8000, "notes.txt");
try t.stable(700, 20000);
try t.snap("boot");
// The full index includes commands without leader paths.
try t.key("space ?");
try t.wait(10000, "pardes builtins, and how to run each:");
try t.wait(10000, "ClipPasteBefore");
try t.key("g e");
// Every builtin added since adds an index line, and one wheel tick is one row
// (config.wheel_rows): scroll far enough to expose Look and Exec above the
// bottom viewport while keeping the same pane geometry for the later clicks.
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wheel("up", "110", 50);
try t.wait(10000, "Look enter, right-click");
try t.wait(10000, "Exec tab, middle-click");
try t.wait(10000, "Filter");
try t.wait(10000, "Theme");
try t.stable(700, 15000);
// n moves through look-able text; it must not execute command names.
try t.key("space j n space j n space j n");
try t.wait(10000, "Look enter, right-click");
try t.wait(10000, "Exec tab, middle-click");
try t.key("space c ?");
try t.wait(10000, "under SPC c");
try t.wait(10000, "Joincol");
try t.stable(700, 15000);
try t.snap("column-group");
try t.key("space h ?");
try t.wait(10000, "Tutor");
try t.stable(700, 15000);
try t.snap("docs-group");
try t.press("middle", "@Tutor", 16);
try t.release("middle", "@Tutor", 16);
try t.wait(10000, "PARDES TUTOR");
try t.stable(700, 15000);
try t.snap("tutor-from-index");
try t.done();
}
// Dump writes the whole session to this fixture's $DUMP path, a dump of the
// walk (src/walk.zig), and `-l` of it is that session again: the text typed
// into a terminal over its history comes back where it was.
fn dump(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "dump");
defer t.deinit();
try t.file("d.txt", "x");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "d.txt");
try t.stable(700, 20000);
try t.press("left", "5", 10);
try t.release("left", "5", 10);
try t.stable(400, 5000);
try t.key("i");
try t.send("typed-marker");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.press("middle", "@Dump", 1);
try t.release("middle", "@Dump", 1);
try t.stable(600, 8000);
try t.start(31, 100, &.{ "-l", t.dump });
try t.wait(8000, "typed-marker");
try t.stable(700, 20000);
try t.snap("loaded");
try t.done();
}
// pardes -l loads another instance's dump: the session as it was dumped, each
// terminal's view where it was (scrolled back into the seq output), its
// history above a "restored history" banner and a new shell below it.
fn load(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "load");
defer t.deinit();
try t.file("d.txt", "x");
try t.start(31, 100, &.{ "-n", "3" });
try t.wait(8000, "d.txt");
try t.stable(700, 20000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("echo LOAD''MARK; seq 1 40; echo E''ND");
try t.key("enter");
try t.wait(8000, "END");
try t.stable(700, 10000);
try t.key("c-b");
try t.stable(600, 8000);
try t.wheel("up", "10", 8);
try t.wheel("up", "10", 8);
try t.stable(500, 8000);
try t.press("middle", "@Dump", 1);
try t.release("middle", "@Dump", 1);
try t.stable(600, 8000);
try t.start(31, 100, &.{ "-l", t.dump });
try t.wait(8000, "restored");
try t.stable(700, 20000);
try t.snap("loaded");
try t.style("loaded");
try t.done();
}
// Dump writes to the resolved dump path ($PARDES_DUMP here; a timestamped file
// under ~/.local/share/pardes in live runs) and the topbar grows Restore <path>;
// middle-click Restore loads that dump back into the live session: output on
// screen at Dump time survives (pty history), later output does not
fn restore(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "restore");
defer t.deinit();
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("echo KEEP''ME");
try t.key("enter");
try t.wait(8000, "KEEPME");
try t.stable(700, 10000);
try t.press("middle", "@Dump", 1);
try t.release("middle", "@Dump", 1);
try t.stable(700, 10000);
try t.snap("dumped");
try t.send("echo GONE''SOON");
try t.key("enter");
try t.wait(8000, "GONESOON");
try t.stable(700, 10000);
try t.press("middle", "@Restore", 1);
try t.release("middle", "@Restore", 1);
try t.stable(900, 15000);
try t.snap("restored");
try t.done();
}
// A middle sweep over a column's tag or the workspace's runs what it swept,
// as it does over a pane's tag: highlighted while the button is held, run
// when it comes up. Both headers used to run the word under the PRESS, on
// the press, so a sweep of `echo SWEPT-COL` ran a bare `echo`. A right sweep
// looks for what it swept the same way, and the other button cancels.
fn headersweep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "headersweep");
defer t.deinit();
try t.file("hay.txt", "ZQNEEDLE");
try t.start(21, 120, &.{ "-n", "3" });
try t.wait(8000, "Newcol");
try t.stable(700, 20000);
// the column tag: type a command onto it, then sweep the whole command
try t.press("left", "50", 2);
try t.release("left", "50", 2);
try t.key("i");
try t.key("space");
try t.send("echo SW''EPT-COL");
try t.key("esc");
try t.settle(100);
try t.press("middle", "@echo", 2);
try t.drag("middle", "@echo+8", 2);
try t.stable(300, 5000);
try t.style("col-sweeping");
try t.drag("middle", "@echo+16", 2);
try t.release("middle", "@echo+16", 2);
try t.wait(8000, "SWEPT-COL");
try t.stable(700, 15000);
try t.snap("col-swept");
// the workspace tag, the same
try t.press("left", "110", 1);
try t.release("left", "110", 1);
try t.key("i");
try t.key("space");
try t.send("echo SW''EPT-WS");
try t.key("esc");
try t.settle(100);
try t.press("middle", "@echo", 1);
try t.drag("middle", "@echo+15", 1);
try t.release("middle", "@echo+15", 1);
try t.wait(8000, "SWEPT-WS");
try t.stable(700, 15000);
try t.snap("ws-swept");
// a right sweep over part of a word looks for the part: `hay.txt` opens,
// where a click would look for all of `xxhay.txtxx`
try t.press("left", "118", 1);
try t.release("left", "118", 1);
try t.key("i");
try t.key("space");
try t.send("xxhay.txtxx");
try t.key("esc");
try t.settle(100);
try t.press("right", "@xxhay.txtxx+2", 1);
try t.drag("right", "@xxhay.txtxx+9", 1);
try t.release("right", "@xxhay.txtxx+9", 1);
try t.wait(8000, "ZQNEEDLE");
try t.stable(700, 15000);
try t.snap("ws-looked");
// the look button tapped during a middle sweep cancels it: nothing runs
try t.press("middle", "@echo", 2);
try t.drag("middle", "@echo+16", 2);
try t.press("right", "@echo+16", 2);
try t.release("right", "@echo+16", 2);
try t.release("middle", "@echo+16", 2);
try t.stable(700, 15000);
try t.snap("cancelled");
// for comparison, a select sweep over the second column's tag selects, in
// the tag's selection colours, and runs nothing
try t.press("left", "@Find#2", 2);
try t.drag("left", "@Grep#2+4", 2);
try t.release("left", "@Grep#2+4", 2);
try t.stable(700, 15000);
try t.style("selected");
try t.done();
}
// headersweep.snap in a session restored from a dump: its column and
// workspace tags are rebuilt, and a middle sweep over each runs what it
// swept, as it does in a fresh session.
fn headersweep_restored(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "headersweep-restored");
defer t.deinit();
try t.start(21, 120, &.{ "-n", "3" });
try t.wait(8000, "Newcol");
try t.stable(700, 20000);
try t.press("middle", "@Dump", 1);
try t.release("middle", "@Dump", 1);
try t.stable(700, 10000);
try t.press("middle", "@Restore", 1);
try t.release("middle", "@Restore", 1);
try t.stable(900, 15000);
try t.press("left", "50", 2);
try t.release("left", "50", 2);
try t.key("i");
try t.key("space");
try t.send("echo RE''STORED-COL");
try t.key("esc");
try t.settle(100);
try t.press("middle", "@echo", 2);
try t.drag("middle", "@echo+8", 2);
try t.stable(300, 5000);
try t.style("col-sweeping");
try t.drag("middle", "@echo+19", 2);
try t.release("middle", "@echo+19", 2);
try t.wait(8000, "RESTORED-COL");
try t.stable(700, 15000);
try t.snap("col-swept");
try t.press("left", "118", 1);
try t.release("left", "118", 1);
try t.key("i");
try t.key("space");
try t.send("echo RE''STORED-WS");
try t.key("esc");
try t.settle(100);
try t.press("middle", "@echo", 1);
try t.drag("middle", "@echo+8", 1);
try t.stable(300, 5000);
try t.style("ws-sweeping");
try t.drag("middle", "@echo+18", 1);
try t.release("middle", "@echo+18", 1);
try t.wait(8000, "RESTORED-WS");
try t.stable(700, 15000);
try t.snap("ws-swept");
try t.done();
}
// ghostty-vt narrates every sequence it does not implement through std.log,
// and a pardes child's stderr is this pty — so a library log line lands on the
// rendered grid, exactly where it does on a real user's terminal. The two
// sequences below are the cheapest ones that trip it: a kitty graphics query
// (`debug(kitty_gfx): executing kitty graphics command`) and a private CSI p
// (`warning(stream): ignoring unimplemented CSI p with intermediates: >`).
// The golden is the assertion that neither reaches the screen.
fn logquiet(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "logquiet");
defer t.deinit();
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("printf '\\033_Ga=q,i=1,s=1,v=1,f=24,t=d;AAAA\\033\\\\\\033[>0p'");
try t.key("enter");
try t.stable(700, 20000);
try t.snap("quiet");
try t.done();
}
// topbar middle-click Tutor opens the embedded tutor below its source shell
fn tutor(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "tutor");
defer t.deinit();
try t.start(31, 150, &.{ "-n", "3" });
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
try t.press("middle", "@Tutor", 1);
try t.release("middle", "@Tutor", 1);
try t.stable(700, 15000);
try t.snap("tutor");
try t.done();
}
// A topbar word runs on a middle click, and it runs WITH whatever is selected:
// sweep a word, click Grep, it greps that word. That is acme's 2-1 chord with
// no drag to chord into, and it is the whole reason the topbar reads the
// selection at all.
//
// But a selection is only an argument to a builtin that has somewhere to put
// one. `Exit`, `Debug`, `NextColor` and the rest match their name WHOLE — that
// is what makes `Exit foo` a shell command and not Exit — so splicing a sweep
// onto them produced a name matching no builtin, which fell out of the builtin
// parser and into a SHELL, as a command nobody typed (`bash: Debug: command
// not found`). It only ever bit you with a terminal open, because that is
// where the stray text went.
//
// So both halves are pinned here, against the same live selection: the no-arg
// builtin runs, and the arg-taking one still gets the word.
fn topbarexec(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "topbarexec");
defer t.deinit();
try t.file("zmarkfile.txt", "hay ZQNEEDLE stack");
try t.start(21, 90, &.{ "-n", "3" });
try t.wait(8000, "zmarkfile.txt");
try t.stable(700, 20000);
// sweep `zmarkfile.txt` out of the shell's own greeting: an ordinary left drag,
// and the kind of stale highlight that is simply lying around in real use
try t.press("left", "3", 6);
try t.drag("left", "15", 6);
try t.release("left", "15", 6);
try t.stable(700, 15000);
try t.snap("selected");
// Debug takes NO argument. Middle-clicked with that sweep live it must open the
// overlay — not send `Debug zmarkfile.txt` to bash. The box IS the assertion.
try t.press("middle", "@Debug", 1);
try t.release("middle", "@Debug", 1);
try t.stable(700, 15000);
try t.snap("noarg-runs");
// ...and off again, so the overlay does not cover what comes next
try t.press("middle", "@Debug", 1);
try t.release("middle", "@Debug", 1);
try t.stable(700, 15000);
// Find DOES take one, and still gets it: the sweep is the pattern, so the
// results buffer names the file it matched. An empty buffer would mean Find
// ran with no argument (which arms the prompt instead), so the ROW is the
// assertion — the splice is what put it there.
try t.press("middle", "@Find", 1);
try t.release("middle", "@Find", 1);
try t.wait(10000, "+Search");
try t.stable(700, 15000);
try t.snap("arg-still-spliced");
try t.done();
}
fn leader(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "leader");
defer t.deinit();
try t.file("cmds.txt", "Help");
try t.start(41, 100, &.{"cmds.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "cmds.txt");
try t.stable(700, 20000);
try t.key("space");
try t.stable(400, 5000);
try t.snap("spc");
try t.key("h");
try t.stable(400, 5000);
try t.snap("spc-h");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("abandoned");
try t.key("space x");
try t.stable(400, 5000);
try t.snap("unmapped");
// Executing Help as text opens the full index, not a filtered group.
try t.press("middle", "@Help", 4);
try t.release("middle", "@Help", 4);
try t.wait(10000, "pardes builtins, and how to run each:");
try t.wait(10000, "ClipPasteBefore");
try t.key("space h ?");
try t.wait(10000, "under SPC h");
try t.stable(700, 15000);
try t.snap("help-group");
try t.key("space h t");
try t.wait(10000, "PARDES TUTOR");
try t.stable(700, 15000);
try t.snap("tutor");
// the tutor is at the foot of its column (acme's placement put it under the
// +Help's text), so SPC d has nothing to ask and closes it at once
try t.key("space d");
try t.stable(700, 15000);
try t.snap("deleted");
// ...and the +Help it squeezed goes too, so the full index below opens with
// room to show it
try t.key("c-w j enter");
try t.key("space d");
try t.stable(700, 15000);
try t.key("space ?");
try t.wait(10000, "pardes builtins, and how to run each:");
try t.wait(10000, "ClipPasteBefore");
// PDF commands depend on the build; these toggles do not.
try t.key("space t ?");
try t.wait(10000, "under SPC t");
try t.wait(10000, "Ascii");
try t.wait(10000, "Palette");
try t.wait(10000, "Petscii");
try t.wait(10000, "Wrap");
// SPC w is Window itself now, not a group; the column group stands in
try t.key("space c ?");
try t.wait(10000, "under SPC c");
try t.wait(10000, "Joincol");
try t.stable(700, 15000);
try t.snap("help-column");
try t.key("space l ?");
try t.wait(10000, "WsDiagnostics");
try t.stable(700, 15000);
try t.snap("help-language");
try t.key("space d");
try t.settle(100);
try t.stable(700, 15000);
try t.snap("del-output");
try t.done();
}
fn mini(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "mini");
defer t.deinit();
try t.file("commands.txt", "@`Mini demo.zig`");
try t.file("demo.zig", "const greeting = \"café λ 界 é\";\n\npub fn choose(ok: bool) u32 {\n if (ok) return 42;\n return 7;\n}\n\n// space and color survive compression\nconst answer = choose(true);\n");
try t.start(23, 90, &.{"commands.txt"});
try t.wait(8000, "Mini demo.zig");
try t.stable(400, 10000);
try t.press("middle", "@Mini", 4);
try t.release("middle", "@Mini", 4);
try t.wait(8000, "/Mini demo.zig");
try t.stable(500, 10000);
try t.snap("opened");
try t.style("opened");
try t.snap9p("opened");
try t.resize(27, 105);
try t.stable(400, 10000);
try t.snap("resized");
try t.snap9p("resized");
try t.done();
}
fn ninep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "ninep");
defer t.deinit();
try t.file("demo.zig", "const greeting = \"café λ 界 é\";\n\npub fn choose(ok: bool) u32 {\n if (ok) return 42;\n return 7;\n}\n");
try t.start(15, 90, &.{"demo.zig"});
try t.wait(8000, "choose");
try t.stable(400, 10000);
try t.snap("opened");
try t.style("opened");
try t.snap9p("opened");
try t.key("g g i");
try t.send("// café λ 界\n");
try t.key("esc");
try t.settle(100);
try t.stable(300, 8000);
try t.snap("edited");
try t.snap9p("edited");
try t.style("edited");
try t.resize(20, 105);
try t.stable(400, 10000);
try t.style("resized");
try t.snap9p("resized");
try t.snap("resized");
try t.snap9p("unchanged");
try t.done();
}
fn nested(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "nested");
defer t.deinit();
try t.dir("nestdir");
try t.file("nestdir/inside-nested.txt", "marker");
try t.file("nested.txt", "hello-from-nested\nsecond-nested-line\n");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("$(readlink /proc/$PPID/exe) nested.txt");
try t.key("enter");
try t.wait(15000, "hello-from-nested");
try t.stable(700, 20000);
try t.snap("file-arg");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("$(readlink /proc/$PPID/exe)");
try t.key("enter");
try t.wait(15000, "already inside pardes");
try t.stable(700, 20000);
try t.snap("no-arg");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("$(readlink /proc/$PPID/exe) nestdir");
try t.key("enter");
try t.wait(15000, "inside-nested.txt");
try t.stable(700, 20000);
try t.snap("dir-arg");
try t.done();
}
fn nested_optout(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "nested-optout");
defer t.deinit();
try t.file("nested.txt", "optout-marker\nsecond-optout-line\n");
try t.dir("innerdir");
try t.file("innerdir/deeper.txt", "deepest-marker\n");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("$(readlink /proc/$PPID/exe) --nested nested.txt");
try t.key("enter");
try t.wait(20000, "optout-marker");
try t.stable(700, 20000);
try t.snap("optout-file");
try t.start(31, 100, &.{});
try t.wait(8000, "$");
try t.stable(700, 20000);
try t.send("(cd innerdir && $(readlink /proc/$PPID/exe) --nested)");
try t.key("enter");
try t.wait(20000, "cwd/innerdir");
try t.stable(700, 20000);
try t.snap("inner-shell");
try t.send("$(readlink /proc/$PPID/exe) deeper.txt");
try t.key("enter");
try t.wait(20000, "deepest-marker");
try t.stable(700, 20000);
try t.snap("inner-launch");
try t.done();
}
// The Shell builtin names the binary the NEXT terminal execs. What is pinned
// here is the case that has to hold on a machine you did not set up: the name
// resolves to nothing, so Shell refuses it and says why on the message row,
// and the next pane opens anyway with the shell that was set before.
//
// A default $SHELL that names nothing executable falls back to /bin/sh
// (config.defaultShell), and the host's lookup still falls back at spawn for
// a shell that went away after it was set: a pane never gets a child that
// dies at exec and shows one EOF.
//
// The rest of the feature is unit-tested rather than pinned here, on purpose.
// Which family a binary belongs to, what argv each one gets and where the
// lookup searches are in host_io.Shell's own tests; the fish end of it cannot
// be a golden at all, because fish's prompt carries a hostname and its greeting
// a version number. (Every script in this suite runs bash, pinned through an
// ordinary config file the harness writes — see snapshot.zig.)
fn shellset(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "shellset");
defer t.deinit();
try t.file("cmd.txt", "Shell zznosuchshell");
try t.file("zmarkfile.txt", "x");
try t.start(21, 90, &.{"cmd.txt"});
try t.wait(8000, "Shell zznosuchshell");
try t.stable(700, 20000);
try t.snap("boot");
// execute the line the way you would run any command: select it, Tab. Nothing
// on any machine is installed under that name, so the resolver runs out of
// directories. (A file pane, so the line executed is the line you can see —
// typing into a terminal's overlay would leave `gg`/`x` selecting its output.)
try t.key("g g");
try t.key("x");
try t.stable(400, 5000);
try t.key("tab");
try t.stable(700, 15000);
// NOTHING happened on screen, and that is the assertion: a name the builtin
// parser does not know is a command line, so it would have forked a terminal
// for this directory and printed `Shell: command not found` into it. One
// pane, no error — `Shell` was consumed as a builtin and its argument went
// with it.
try t.snap("builtin-ran");
// a new terminal, which asks for a shell that is not there. It gets the
// fallback: the pane greets, `ls` runs, and its output is on screen. Alt-n and
// Alt-c, because `New`/`Newcol` open an empty +New scratch rather than a shell.
try t.key("a-n");
try t.key("a-c");
try t.wait(15000, "zmarkfile.txt");
try t.stable(700, 20000);
try t.snap("fallback-shell");
try t.done();
}
// The transient message row: the LAST row of a pane, left-aligned at the text
// area's origin, saying what just happened to that pane and when. An OVERLAY,
// not geometry — nothing shrinks to make room, so a pane with nothing to say is
// not touched at all, which is why the other 71 goldens only moved where a
// prompt or a message actually appears.
//
// The clock reads `--:--:--` here and only here: $PARDES_NOTIME (set by
// snapshot.zig, the same flag that hides the language backend's durations)
// blanks the DIGITS rather than the row, because a message that disappeared
// under the harness could not be pinned at all.
//
// The row has exactly two possible occupants and they are not the same kind of
// thing. A MESSAGE is a report of something that already happened, and the next
// key or mouse event wipes it. An armed PROMPT is what that keystroke is being
// typed INTO, it lives until Enter or Esc, and it WINS.
fn msg(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "msg");
defer t.deinit();
try t.lines("a.txt", 6, "");
try t.start(15, 70, &.{"a.txt"});
try t.wait(8000, "Newcol Joincol");
try t.wait(8000, "a.txt");
try t.stable(700, 20000);
try t.snap("opened");
// Save (SPC f s) writes the file; the SHELL is where the write and the clock
// both are, so the shell is what posts the message once the bytes are down.
try t.key("space f s");
try t.stable(700, 15000);
try t.snap("saved");
// A REPAINT is not input. A resize redraws every cell in the window from
// scratch and the message is still there on the other side of it — the row is
// state, not one frame's flash. (Different rows, or the kernel sends no
// SIGWINCH and nothing repaints.)
try t.resize(17, 70);
try t.stable(700, 15000);
try t.snap("repainted");
// ...but the next KEY takes it away. `j` is a plain cursor motion and changes
// nothing else on screen, so the vanishing message is the whole diff.
try t.key("j");
try t.stable(700, 15000);
try t.snap("keycleared");
// Again, and this time a bare mouse MOTION — no button, nothing clicked —
// clears it: any mouse event counts, the rule is "you are back", not "you did
// something".
try t.key("space f s");
try t.stable(700, 15000);
try t.snap("saved-again");
try t.motion("20", 6);
try t.stable(700, 15000);
try t.snap("mousecleared");
// The other message: an external write lands in the pane (filewatch.snap owns
// that contract) and the row says which of the two things happened. `run` is a
// child of the RUNNER, so the app receives no keystroke here and nothing but
// the watch could have posted this.
try t.run("printf 'EXTERNAL\\n' > a.txt");
try t.wait(10000, "EXTERNAL");
try t.stable(700, 15000);
try t.snap("reloaded");
// `/` still types into the tag tail — same buffer, same offsets, same one-line
// editor, same Enter and Esc — but it is DRAWN here now, so the tagline keeps
// its builtins instead of losing them to a long pattern. Note the tag row above
// ends at `Del`: the marker and the pattern are no longer on it at all. (The
// `/` keystroke also cleared the reload message, which is the rule above.)
try t.key("s");
try t.send("EXT");
try t.stable(700, 15000);
try t.snap("prompt");
// ...and a message arriving UNDER an armed prompt does not disturb it: a second
// external write reloads the pane and posts one, the row stays the prompt's.
try t.run("printf 'AGAIN\\n' > a.txt");
try t.wait(10000, "AGAIN");
try t.stable(700, 15000);
try t.snap("prompt-wins");
// Esc abandons the input, and the very key that abandoned it is also the key
// that clears the message queued underneath — so the row goes empty rather than
// handing back a report from before you started typing.
try t.key("esc");
try t.settle(100);
try t.stable(700, 15000);
try t.snap("esc");
// Every other writer of this row is something going WRONG, which is a poor way
// to look at a row: `Msg <text>` is the word that writes it on purpose. An
// ordinary builtin, so it runs the ordinary way — write it in the buffer,
// select the line, execute it — and what lands is the text, verbatim, with the
// same stamped-looking left edge as the reports above. (The clock belongs to
// the SHELL, which is why this one has none: the core has no clock.)
try t.key("o");
try t.send("Msg hand-written report");
try t.key("esc");
try t.settle(100);
try t.key("x");
try t.key("tab");
try t.stable(700, 15000);
try t.snap("msgbuiltin");
// A message wider than the pane keeps its TAIL, not its head: the end of a
// message is the part that says something -- a path's file name, an error's
// reason -- so the head is what a narrow pane goes without.
try t.key("j");
try t.key("o");
try t.send("Msg 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 THE-END");
try t.key("esc");
try t.settle(100);
try t.key("x");
try t.key("tab");
try t.stable(700, 15000);
try t.snap("msgtail");
try t.done();
}
// SIGWINCH crash (reported as "crash on font-size change"): resizing the outer
// terminal delivers SIGWINCH, and vaxis's default handler locks std.Io mutexes
// from signal context — landing on a thread inside an Io.Threaded syscall
// region (pty readers in read(2), main parked in queue.pop) panicked the Io
// machinery and killed pardes. Now every thread blocks SIGWINCH and a sigwait
// watcher consumes it. The in-pane kill storm below crashed pardes before the
// fix; the resize after proves the watcher still reflows the grid.
fn winch(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "winch");
defer t.deinit();
try t.start(31, 100, &.{ "-n", "3" });
try t.stable(700, 20000);
try t.key("c-b");
try t.stable(600, 8000);
try t.send("for i in $(seq 600); do kill -WINCH $PPID; done; echo SUR''VIVED");
try t.key("enter");
try t.wait(15000, "SURVIVED");
try t.stable(700, 15000);
try t.snap("storm");
try t.resize(35, 106);
try t.stable(700, 15000);
try t.snap("resized");
try t.done();
}
// `Save` with NO argument on a +New scratch: the prompt is drawn in the tag,
// prefilled with the pane's own directory, and submitting it turns the scratch
// into an ordinary file pane whose bytes are on disk.
//
// config.zig's save_marker is rendered in no other golden in the suite. Ten
// unit tests assert the STRING startSavePrompt builds (pardes.zig's "Save on a
// scratch asks for a path in its inherited dir and makes it a file"); none of
// them can see it drawn, land on the tag rather than the message row, or show
// what the pane becomes afterwards. That is what this script is for.
fn savepane(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "savepane");
defer t.deinit();
try t.start(31, 100, &.{ "-n", "1" });
try t.wait(8000, "Newcol Joincol");
try t.stable(700, 20000);
// a scratch of our own, with something in it to save
try t.key("space f n");
try t.stable(400, 5000);
try t.key("i");
try t.send("scratch bytes");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("scratch");
// Save, no argument: the tag gains the armed ` Save <dir>/` prompt, and the
// pane is still the scratch — nothing is written until the path is submitted
try t.key("space f s");
try t.stable(400, 5000);
try t.snap("prompt");
// name it: the prompt submits, the pane becomes that file (its tag is the path,
// and the `*` is gone because what is on screen is what is on disk)
try t.send("saved.txt");
try t.key("enter");
try t.stable(700, 15000);
try t.snap("saved");
try t.snapFile("bytes", "saved.txt");
try t.done();
}
// external file updates: a write from outside pardes lands in an open pane
// that has no unsaved edits, committed like any other edit; a pane WITH
// unsaved edits keeps them and says the file changed on disk (File.changed).
//
// The writer must be a STRANGER to the editor. This script used to have a
// pardes PANE run the write, which proved much less than it looked: that
// shell's own pty output wakes the loop and paints a frame, so the reload
// could be riding on the keystroke's frame instead of on the watch. `run` is a
// child of the RUNNER — nothing it does reaches an app pty — and every
// assertion below it is a `wait`, which only READS the pty. So between the
// write and the reload the app receives no keystroke, no resize, no mouse: if
// the watch does not wake the loop by itself, these waits time out.
//
// Two files in two directories, written the two ways files actually change:
// w.txt in place (CLOSE_WRITE) and sub/s.txt by rename-over, which is what
// `zig fmt`, `git checkout` and every editor's atomic save do (MOVED_TO, and
// a new inode — the reason the mark is on the directory).
fn filewatch(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
var t = try Tty.init(gpa, exe, "filewatch");
defer t.deinit();
try t.dir("sub");
try t.file("w.txt", "line 1\nline 2\n/tmp/pardes-snap/filewatch/cwd/sub/s.txt\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\nline 10\nline 11\nline 12\n");
try t.lines("sub/s.txt", 8, "");
// 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, 210, &.{ "-n", "1" });
try t.wait(8000, "w.txt");
try t.stable(700, 20000);
// open w.txt as a file pane: type the name into the shell, right-click 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("w.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 4");
try t.stable(700, 15000);
// ...and open sub/s.txt from the path sitting on line 3 of that pane, so the
// second watched pane is in a DIFFERENT directory from the first
try t.press("right", "20", 10);
try t.release("right", "20", 10);
try t.wait(10000, "line 8");
try t.stable(700, 15000);
// an UNSAVED edit on line 1 of w.txt
try t.press("left", "10", 8);
try t.release("left", "10", 8);
try t.stable(400, 5000);
try t.key("i");
try t.send("MYEDIT");
try t.key("esc");
try t.settle(100);
try t.stable(400, 5000);
try t.snap("edited");
// ---- from here to `snap reloaded_sub`, pardes is sent NOTHING ----
// w.txt has the unsaved edit: it is kept, and the change is said
try t.run("printf 'EXTERNAL\\n' > w.txt");
try t.wait(10000, "changed on disk");
try t.stable(700, 10000);
try t.snap("kept");
// sub/s.txt has none: it takes the new text
try t.run("printf 'RENAMED\\n' > sub/t && mv sub/t sub/s.txt");
try t.wait(10000, "RENAMED");
try t.stable(700, 10000);
try t.snap("reloaded_sub");
try t.done();
}
|