summaryrefslogtreecommitdiff
path: root/test/process/tty_layout.zig
blob: 08a024886503615cfebd9367b5a96a11232aeb29 (plain) (blame)
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
//! The tty frontend's own cases (test/tty.zig), columns, panes and tags: placement, grips, drags, collapse, the window ops.
const std = @import("std");
const Tty = @import("../tty.zig").Tty;

pub const cases = .{
    .{ "tty layout: colgrip", colgrip },
    .{ "tty layout: collapse", collapse },
    .{ "tty layout: delask", delask },
    .{ "tty layout: emptycol", emptycol },
    .{ "tty layout: layout-close", layout_close },
    .{ "tty layout: layout-open", layout_open },
    .{ "tty layout: shrinktag", shrinktag },
    .{ "tty layout: tagalign", tagalign },
    .{ "tty layout: tagalign2col", tagalign2col },
    .{ "tty layout: windownav", windownav },
    .{ "tty layout: windowops", windowops },
    .{ "tty layout: wheeldrift", wheeldrift },
};

// Column grips: the two cells left of a column tag carry the column. A grabbed
// grip lights.
// The right column is at x 50; its grip is cells 51-52 (1-based) on row 2.
fn colgrip(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "colgrip");
    defer t.deinit();
    try t.file("w.txt", "x");
    try t.start(24, 100, &.{"w.txt"});
    try t.wait(8000, "Newcol Joincol");
    try t.wait(8000, "w.txt");
    try t.stable(700, 20000);
    try t.key("a-n");
    try t.key("a-c");
    try t.stable(700, 15000);
    try t.style("rest");
    // held on its own grip: lit
    try t.press("left", "51", 2);
    try t.stable(400, 5000);
    try t.style("held");
    // dropped short of the left column's middle, the left edge moves
    try t.drag("left", "41", 2);
    try t.stable(400, 5000);
    try t.snap("resize-drag");
    try t.style("resize-drag");
    try t.release("left", "41", 2);
    try t.stable(700, 15000);
    try t.snap("resize-done");
    // carried over the left column's left half it goes first
    try t.press("left", "41", 2);
    try t.drag("left", "10", 2);
    try t.stable(400, 5000);
    try t.snap("reorder-drag");
    try t.style("reorder-drag");
    try t.release("left", "10", 2);
    try t.stable(700, 15000);
    try t.snap("reorder-done");
    try t.done();
}

// A default pane-tag command collapses to one row and restores the body.
// Exercise real middle clicks twice, then the tag's own execute key twice: a
// click types into the tag, Esc is its normal mode, and Tab executes there.
fn collapse(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "collapse");
    defer t.deinit();
    try t.file("kept.txt", "KEEP-FIRST\nKEEP-SECOND\nKEEP-THIRD");
    try t.start(25, 160, &.{"kept.txt"});
    try t.wait(8000, "KEEP-THIRD");
    try t.stable(500, 15000);
    try t.snap("before");
    try t.press("middle", "@Collapse", 3);
    try t.release("middle", "@Collapse", 3);
    try t.stable(500, 8000);
    try t.snap("middle-collapsed");
    // The terminal remembers its last cursor position even when hidden. The core
    // screen explicitly reports null, guarding against a leaked body caret.
    try t.snap9p("middle-collapsed-cursor");
    try t.press("middle", "@Collapse", 3);
    try t.release("middle", "@Collapse", 3);
    try t.wait(8000, "KEEP-THIRD");
    try t.stable(500, 8000);
    try t.snap("middle-restored");
    try t.press("left", "@Collapse", 3);
    try t.release("left", "@Collapse", 3);
    try t.key("esc");
    try t.settle(100);
    try t.key("tab");
    try t.stable(500, 8000);
    try t.snap("tab-collapsed");
    try t.snap9p("tab-collapsed-cursor");
    try t.press("left", "@Collapse", 3);
    try t.release("left", "@Collapse", 3);
    try t.key("esc");
    try t.settle(100);
    try t.key("tab");
    try t.wait(8000, "KEEP-THIRD");
    try t.stable(500, 8000);
    try t.snap("tab-restored");
    // Save via the visible tag; the original bytes must survive all four toggles.
    try t.press("middle", "@Save", 3);
    try t.release("middle", "@Save", 3);
    try t.stable(500, 8000);
    try t.snapFile("unchanged", "kept.txt");
    try t.done();
}

// Del from the keyboard on a pane with open panes above AND below asks, on the
// pane's notice band, which one takes its rows: k above, j below, anything else
// keeps the pane. A click, and DelAbove/DelBelow (Del k / Del j), never ask.
fn delask(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "delask");
    defer t.deinit();
    try t.file("top.txt", "top-marker");
    try t.start(36, 100, &.{"top.txt"});
    try t.wait(8000, "top-marker");
    try t.stable(700, 20000);
    // two scratch panes below the file, each saying which it is, then focus the
    // middle one
    try t.key("space f n");
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("middle-pane");
    try t.key("esc");
    try t.settle(100);
    try t.key("space f n");
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("bottom-pane");
    try t.key("esc");
    try t.settle(100);
    try t.key("c-w k enter");
    try t.stable(400, 5000);
    try t.snap("three");
    // asked, and nothing closes yet; the question goes up on the band only after
    // config.del_question_delay_ns (400 ms) with no answer, a hint
    try t.key("space d");
    try t.settle(700);
    try t.stable(400, 5000);
    try t.snap("asked");
    // Esc takes the question back: the pane stays
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("kept");
    // j: the pane below grows over the middle one's rows, the file keeps its own
    try t.key("space d");
    try t.stable(400, 5000);
    try t.key("j");
    try t.stable(700, 10000);
    try t.snap("below-took");
    // a pane under it, and DelBelow (Del j) appended to the middle one's text and
    // executed with a click: no question, the pane below takes the rows
    try t.key("space f n");
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("third-pane");
    try t.key("esc");
    try t.settle(100);
    try t.key("c-w k enter");
    try t.stable(400, 5000);
    try t.key("A");
    try t.send(" DelBelow");
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("typed");
    try t.press("middle", "@DelBelow", 21);
    try t.release("middle", "@DelBelow", 21);
    try t.stable(700, 10000);
    try t.snap("below-took-click");
    // a fresh pane at the foot of the column (acme's New takes the bottom half of
    // the last pane), and the third one, now between the file and it, closed by a
    // middle click on its tag's Del: no question, and the rows go up as they
    // always have
    try t.press("left", "10", 5);
    try t.release("left", "10", 5);
    try t.stable(400, 5000);
    try t.key("space f n");
    try t.stable(400, 5000);
    try t.snap("four");
    try t.press("middle", "@Del", 20);
    try t.release("middle", "@Del", 20);
    try t.stable(700, 10000);
    try t.snap("mouse-del");
    try t.done();
}

// A column can hold no pane, as acme's can (cols.c:186). Newcol makes one
// empty, its tag over blank space and holding the keyboard; the next pane
// made while it is the active column fills it whole (makenewwindow,
// util.c:468-469); and a shell that exits there leaves it empty again, the
// keyboard back on its tag.
fn emptycol(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "emptycol");
    defer t.deinit();
    try t.file("notes.txt", "one\ntwo");
    try t.config("Verbose off");
    try t.start(24, 100, &.{"notes.txt"});
    try t.wait(8000, "notes.txt");
    try t.stable(700, 20000);
    try t.key("space c n");
    try t.stable(400, 5000);
    try t.snap("newcol");
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("filled");
    try t.key("c-b");
    try t.stable(400, 5000);
    try t.send("exit");
    try t.key("enter");
    try t.stable(700, 10000);
    try t.snap("emptied");
    try t.done();
}

// every pane close hands its space to ONE sibling, the rest of the column
// keeps its sizes: Alt-c move-out, tag Del, and shell exit (pty EOF); an
// emptied column stays, as acme's does, its tag over blank space
fn layout_close(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "layout-close");
    defer t.deinit();
    try t.file("marker.txt", "x");
    try t.start(41, 140, &.{ "-n", "3" });
    try t.wait(8000, "marker.txt");
    try t.stable(700, 20000);
    // build a left column of five: Alt-n three times from pane 0 (active follows
    // the new pane, each split takes from the freshly split pane only)
    try t.press("left", "5", 9);
    try t.release("left", "5", 9);
    try t.stable(400, 5000);
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("built");
    // Alt-c: the active (4th) pane moves to a fresh column; the pane above it
    // absorbs its rows, the other three keep theirs (columns reflow horizontally)
    try t.key("a-c");
    try t.stable(700, 15000);
    try t.snap("altc");
    // Del the 2nd pane: source-local column insertion makes this column too narrow
    // to expose its tag words, so focus its body and invoke the same pane-scoped
    // builtin by chord. With panes above and below, the chord asks which one
    // takes the rows: k, the pane above, which also takes the focus. The other
    // panes keep their rows.
    try t.press("left", "5", 9);
    try t.release("left", "5", 9);
    try t.stable(400, 5000);
    try t.key("space d");
    try t.key("k");
    try t.stable(700, 10000);
    try t.snap("del");
    // exit the (now) 2nd shell through its real tty: pty EOF, again only the pane
    // above absorbs — and takes the focus too, not the pane that had it before
    // this one (the moved-out column)
    try t.press("left", "40", 9);
    try t.release("left", "40", 9);
    try t.stable(400, 5000);
    try t.press("left", "5", 24);
    try t.release("left", "5", 24);
    try t.stable(400, 5000);
    try t.key("c-b");
    try t.stable(400, 5000);
    try t.send("exit");
    try t.key("enter");
    try t.stable(700, 10000);
    try t.snap("exit");
    // exit the moved-out pane's shell: its column stays where it was, empty, the
    // keyboard on its tag; the other columns keep their widths
    try t.press("left", "40", 9);
    try t.release("left", "40", 9);
    try t.stable(400, 5000);
    try t.key("c-b");
    try t.stable(400, 5000);
    try t.send("exit");
    try t.key("enter");
    try t.stable(700, 10000);
    try t.snap("colclose");
    try t.done();
}

// every pane open splits ONE existing pane, the rest of the column keeps its
// sizes: Alt-n splits the active pane, an execute-spawned command pane for a file's
// dir splits only the bottom pane of the rightmost column. At this narrow
// width the first looked-up file also splits below its source, leaving every
// unrelated pane (including the ones above the source) at its exact rectangle.
fn layout_open(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "layout-open");
    defer t.deinit();
    try t.dir("sub");
    try t.file("sub/f.txt", "echo 'TTY'OK");
    try t.start(31, 100, &.{ "-n", "3" });
    try t.wait(8000, "sub");
    try t.stable(700, 20000);
    // give pane 0 (top-left) some content so its content-height split is visible
    try t.press("left", "5", 9);
    try t.release("left", "5", 9);
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("echo one; echo two");
    try t.key("enter");
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("before");
    // Alt-n: new shell below pane 0 — the bottom pane's boundary must not move
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("altn-left");
    // make the right column two panes (Alt-n in a fresh column, trivial split)
    try t.press("left", "70", 9);
    try t.release("left", "70", 9);
    try t.stable(400, 5000);
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("altn-right");
    // look sub/f.txt from the bottom-left shell: the first doc splits this shell,
    // not the top-left pane. Both panes above it and the entire right column stay put.
    try t.press("left", "5", 28);
    try t.release("left", "5", 28);
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("sub/f.txt");
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.press("right", "7", 28);
    try t.release("right", "7", 28);
    try t.stable(700, 15000);
    try t.snap("file-open");
    // execute the file's command (middle drag over line 1): it runs as a command
    // pane for sub/, forked at the bottom of the rightmost column, splitting only
    // the pane above it
    try t.press("middle", "8", 25);
    try t.drag("middle", "19", 25);
    try t.release("middle", "19", 25);
    try t.wait(10000, "TTYOK");
    try t.motion("40", 27);
    try t.stable(700, 10000);
    try t.snap("ttydir");
    try t.done();
}

// a terminal shrinks only to its tag and 2 body rows (a text pane would go
// to its tag alone): the pane below dragged by its grip up to the tag row
// stops there -- a terminal has no rule between panes, so the grip is the
// handle, as acme's button is -- the gutter box still grabs a move, and
// dragging back down restores the body intact
fn shrinktag(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "shrinktag");
    defer t.deinit();
    try t.file("w.txt", "x");
    try t.start(31, 100, &.{ "-n", "3" });
    try t.wait(8000, "w.txt");
    try t.stable(700, 20000);
    // content in pane 0 so the restored body is provably intact
    try t.press("left", "5", 9);
    try t.release("left", "5", 9);
    try t.stable(400, 5000);
    try t.key("i");
    try t.send("echo one; echo two");
    try t.key("enter");
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("before");
    // drag the lower pane's grip up under pane 0's tag row: it keeps 2 body rows
    try t.press("left", "1", 18);
    try t.drag("left", "1", 3);
    try t.release("left", "1", 3);
    try t.motion("40", 25);
    try t.stable(500, 8000);
    try t.snap("shrunk");
    // the shrunk pane's gutter box grabs a move: carried into the right column
    // nothing shows until the release, aborted by releasing over the pane itself
    try t.press("left", "1", 3);
    try t.drag("left", "70", 9);
    try t.stable(400, 5000);
    try t.snap("move-preview");
    try t.drag("left", "20", 3);
    try t.release("left", "20", 3);
    try t.stable(400, 5000);
    // re-enlarge: the lower pane's grip, now under pane 0's 2 body rows, pulled
    // back down
    try t.press("left", "1", 7);
    try t.drag("left", "1", 18);
    try t.release("left", "1", 18);
    try t.motion("40", 25);
    try t.stable(500, 8000);
    try t.snap("restored");
    // the bottom pane stops at ITS tag and 2 rows too: its grip dragged past the
    // bottom
    try t.press("left", "1", 18);
    try t.drag("left", "1", 31);
    try t.release("left", "1", 31);
    try t.motion("40", 25);
    try t.stable(500, 8000);
    try t.snap("bottom-shrunk");
    try t.done();
}

// Compact commands stay beside their own prefix regardless of sibling length.
fn tagalign(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "tagalign");
    defer t.deinit();
    try t.dir("deep");
    try t.dir("deep/nested-project-directory");
    try t.file("deep/nested-project-directory/document.txt", "alpha\nbeta\ngamma");
    try t.start(31, 100, &.{"deep/nested-project-directory/document.txt"});
    try t.wait(8000, "Newcol Joincol");
    try t.wait(8000, "document.txt");
    try t.stable(700, 20000);
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("aligned");
    // Clipping never changes underlying tag text or shorter siblings' positions.
    try t.resize(31, 87);
    try t.stable(400, 5000);
    try t.snap("fits");
    try t.resize(31, 86);
    try t.stable(400, 5000);
    try t.snap("overby1");
    try t.resize(31, 100);
    try t.stable(700, 15000);
    try t.press("left", "12", 3);
    try t.release("left", "12", 3);
    try t.stable(400, 5000);
    try t.snap("clicked");
    // The click was on the path, so it drafted a name; Esc keeps it pending and
    // a second Esc drops the draft. `:`
    // then `A` puts the caret after the tag's end, which reveals the complete
    // command suffix; a scrolled Del still executes.
    try t.resize(31, 70);
    try t.key("esc");
    try t.settle(100);
    try t.key("esc");
    try t.settle(100);
    try t.key(":");
    try t.key("A");
    try t.stable(400, 5000);
    try t.snap("revealed");
    try t.press("middle", "@Del", 4);
    try t.release("middle", "@Del", 4);
    try t.stable(700, 15000);
    try t.snap("alone");
    try t.done();
}

// Each compact command run follows its own prefix, never a neighboring path.
fn tagalign2col(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "tagalign2col");
    defer t.deinit();
    try t.dir("deep");
    try t.dir("deep/proj");
    try t.file("deep/proj/document.txt", "alpha\nbeta\ngamma");
    try t.start(31, 160, &.{"deep/proj/document.txt"});
    try t.wait(8000, "Newcol Joincol");
    try t.wait(8000, "document.txt");
    try t.stable(700, 20000);
    // A shell in a separate right-hand column.
    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);
    try t.snap("onecol");
    // A left sibling does not move either existing tag's command text.
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("aligned");
    // Resizing by the right column's grip moves it as a whole and clips
    // without hidden spaces.
    try t.press("left", "81", 2);
    try t.drag("left", "101", 2);
    try t.release("left", "101", 2);
    try t.stable(700, 15000);
    try t.snap("widened");
    try t.done();
}

// RULE: moving focus is a BUILTIN like any other, so there is ONE
// implementation and every route reaches it. SPC w (as Ctrl-w) is window mode:
// h/j/k/l move an outline by the same geometric nearest pane Left/Down/Up/Right
// use and Enter focuses it — and SPC j j
// plus body-normal Esc run Last, the hop to the pane you were in BEFORE this
// one, whichever kind it was. It reads the focus history the core already keeps
// to hand focus back when a pane closes, and going somewhere is itself recorded,
// which is what makes the hop back the same key. Focus shows up in the golden's
// `cursor=` header: that is the
// ACTIVE pane's cursor, so each snap is named by the pane it should land in.
fn windownav(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "windownav");
    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 now, so the terminal every hop below needs 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 straight back — which also puts the shell on the stack,
    // and Last only ever names a pane that is on it. (`New`/`Newcol` open an empty
    // +New scratch now, not a shell.)
    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);
    // left column = the file, right column = that shell; the file has focus
    try t.snap("start");
    // SPC j j: the pane before this one, which is the shell just opened
    try t.key("space j j");
    try t.stable(400, 5000);
    try t.snap("to-term");
    // ...and back, because going there made the file the pane before THAT
    try t.key("space j j");
    try t.stable(400, 5000);
    try t.snap("back-to-file");
    // A bare Esc from a body in normal mode dispatches that SAME builtin: file to
    // terminal, then the same key on the normal-mode terminal returns to the file.
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("esc-to-term");
    try t.key("esc");
    try t.settle(100);
    try t.stable(400, 5000);
    try t.snap("esc-back-to-file");
    // Alt-n: a second shell, below the file — the left column now has two rows
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("altn");
    // SPC w k Enter: up out of that new shell into the file above it
    try t.key("space w k enter");
    try t.stable(400, 5000);
    try t.snap("up");
    // SPC w l Enter: right, into the launch shell
    try t.key("space w l enter");
    try t.stable(400, 5000);
    try t.snap("right");
    // SPC w h Enter: left, back into the file column
    try t.key("space w h enter");
    try t.stable(400, 5000);
    try t.snap("left");
    // SPC w j Enter: down, into the shell under the file
    try t.key("space w j enter");
    try t.stable(400, 5000);
    try t.snap("down");
    // SPC j j from a terminal: the file, which is where SPC w h Enter left off
    try t.key("space j j");
    try t.stable(400, 5000);
    try t.snap("toggle-doc");
    // ...and back to the shell just left, not the launch shell in the right column,
    // which was focused earlier
    try t.key("space j j");
    try t.stable(400, 5000);
    try t.snap("toggle-back");
    try t.done();
}

// hover (no hints), grip resize, move drag, Alt-n, Ctrl-w focus (window mode), Debug box
fn windowops(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "windowops");
    defer t.deinit();
    try t.file("w.txt", "x");
    try t.start(31, 100, &.{ "-n", "3" });
    try t.wait(8000, "w.txt");
    try t.stable(700, 20000);
    // hover over the left column's last col: no hint, columns resize by their grips
    try t.motion("50", 10);
    try t.stable(400, 5000);
    try t.snap("hover-v");
    // hover over the top-left pane's last row: no hint, a row of text is no handle
    try t.motion("20", 16);
    try t.stable(400, 5000);
    try t.snap("hover-h");
    // resize the left pair by the lower pane's grip, 4 rows up (a terminal has no
    // rule between panes; pane 0's last row is now 13)
    try t.press("left", "1", 18);
    try t.drag("left", "1", 14);
    try t.release("left", "1", 14);
    try t.stable(500, 8000);
    try t.snap("hborder-done");
    // move pane 1 (its gutter box) into the right column: nothing shows until
    // the release
    try t.press("left", "1", 18);
    try t.drag("left", "70", 9);
    try t.stable(400, 5000);
    try t.snap("move-preview");
    try t.release("left", "70", 9);
    try t.stable(500, 8000);
    try t.snap("moved");
    // Alt-n: a new shell below the active pane
    try t.key("a-n");
    try t.stable(700, 15000);
    try t.snap("altn");
    // Ctrl-w l Enter: window mode, the outline right, into the pane just moved to
    // the right column, and Enter focuses it (windownav covers the leader side,
    // SPC w); `h` from here would have nothing to its left to prove.
    try t.key("c-w l enter");
    try t.stable(400, 5000);
    try t.snap("focus-right");
    // Debug overlay on (topbar middle-click on Debug), then off
    try t.press("middle", "@Debug", 1);
    try t.release("middle", "@Debug", 1);
    try t.stable(400, 8000);
    try t.snap("debug-on");
    try t.style("debug-on");
    try t.press("middle", "@Debug", 1);
    try t.release("middle", "@Debug", 1);
    try t.stable(400, 8000);
    try t.snap("debug-off");
    try t.done();
}

// the touchpad drift guard (config.wheel_guard_ticks). A two-finger swipe that
// is MEANT to be vertical carries a little sideways drift and the pad turns it
// into wheel_left/wheel_right, so the view used to slide sideways under a plain
// scroll. Every vertical tick re-arms the guard; a horizontal tick spends one
// instead of scrolling. SGR codes are vaxis's: 64/65 = wheel up/down (the
// `wheel` command), 66/67 = wheel RIGHT/left, sent raw as hscroll.snap does.
// The drift ticks here are all rightward on purpose: leftward drift at column 0
// is clamped away and would prove nothing.
fn wheeldrift(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
    var t = try Tty.init(gpa, exe, "wheeldrift");
    defer t.deinit();
    try t.lines("drift.txt", 20, "_0123456789_abcdefghij_ZEND");
    try t.start(17, 70, &.{"drift.txt"});
    try t.wait(8000, "drift.txt");
    try t.stable(700, 20000);
    // the guard protects HSCROLL, and hscroll only exists with soft wrap off (a
    // wrapped body has nothing off to the right to drift towards), so turn it off
    // first — otherwise every sideways tick is a no-op and the test proves nothing
    try t.key("space t w");
    try t.stable(400, 5000);
    try t.snap("home");
    // a drifting swipe: five ticks down with three sideways ones mixed in. The
    // view scrolls DOWN five lines and does not move one column sideways.
    try t.wheel("down", "10", 5);
    try t.wheel("down", "10", 5);
    try t.send("\x1b[<66;10;6M");
    try t.wheel("down", "10", 5);
    try t.send("\x1b[<66;10;6M");
    try t.send("\x1b[<66;10;6M");
    try t.wheel("down", "10", 5);
    try t.wheel("down", "10", 5);
    try t.stable(400, 5000);
    try t.snap("drifted");
    // the guard is armed at 3 now, so a DELIBERATE horizontal swipe pays it off
    // first: these three ticks still move nothing (without the guard they would
    // have shifted the text 12 columns)
    try t.send("\x1b[<66;10;6M");
    try t.send("\x1b[<66;10;6M");
    try t.send("\x1b[<66;10;6M");
    try t.stable(400, 5000);
    try t.snap("paying");
    // ...and from the fourth tick on it scrolls freely: two ticks, 8 columns
    try t.send("\x1b[<66;10;6M");
    try t.send("\x1b[<66;10;6M");
    try t.stable(400, 5000);
    try t.snap("moved");
    // vertical again re-arms the guard, so drift is swallowed once more even
    // though horizontal was just running
    try t.wheel("up", "10", 5);
    try t.send("\x1b[<66;10;6M");
    try t.send("\x1b[<66;10;6M");
    try t.stable(400, 5000);
    try t.snap("rearmed");
    try t.done();
}