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
|
//! The builtins: one struct each, and nothing hand-maintained about them.
//!
//! Executing a builtin's NAME (middle-click / Tab) runs it through the one
//! dispatcher (Pardes.runBuiltin), no matter where the name appears. The
//! struct's DECL NAME is the user-visible word — the one in the topbar, the
//! one sitting in a tag, the one Help prints, the one you execute — so
//! `std.meta.stringToEnum` is the lookup and there is no name table to sync.
//!
//! A zig file IS a struct, so THIS FILE'S declarations are the list: `all`
//! walks them at comptime and `Builtin` folds an enum out of that, in source
//! order. Adding a builtin is writing one struct here — there is no list to
//! append to and no switch prong to add, so there is nothing to forget. The
//! hand-written enum and the four-hundred-line-away switch this replaces were
//! two lists that had to agree; now the code IS the data.
//!
//! What makes a declaration a builtin is its SHAPE: a struct declaring
//! `pub fn run(Ctx) void`. That is strict enough that Ctx and the two folds
//! below fall out by construction rather than by a blocklist — a helper can
//! never accidentally become a builtin, and a builtin whose run has the wrong
//! signature silently vanishes instead of half-working, which the leader
//! table catches immediately (see leader_path: a missing key path is a
//! compile error).
//!
//! What is NOT here: the key bindings. `leader_path` is ONE table in
//! config.zig next to `topbar_str` and every other syntactic choice — the
//! whole remapping surface belongs in one file a user can read top to bottom,
//! not scattered a line at a time across thirty-three structs.
const std = @import("std");
const pardes = @import("pardes.zig");
const Pardes = pardes.Pardes;
const Pane = pardes.Pane;
const output_pane = @import("output_pane.zig");
const config = @import("config.zig");
/// The installed fonts, for the two builtins at the bottom of this file. A
/// GUI-only file behind a comptime branch, the way look.zig imports the web's
/// source archive: the tty and web builds evaluate the other arm and compile
/// none of it.
const fonts = if (pardes.font_picker) @import("fonts.zig") else struct {};
/// What a builtin gets to act on. One bundle rather than five parameters
/// because most builtins want two of them and zig rejects the unused rest.
/// `txt` is the executed text (Restore reads its path back out of it) and
/// `arg` the execute's ARGUMENT — text typed after the name, or the selection
/// a mouse chord kept, which is why Grep and Find run straight away when there
/// is one instead of asking. The leader passes "" and null: a key path names a
/// builtin, never an argument.
pub const Ctx = struct {
p: *Pardes,
/// pane `id`, already resolved — the dispatcher's null check is the one
/// guard every builtin used to share.
pane: *Pane,
id: usize,
txt: []const u8,
arg: ?[]const u8,
};
/// Every enabled builtin, in source order. Feature gates are explicit data;
/// a declaration that claims to be enabled but has the wrong run signature is
/// a compile error instead of silently disappearing from the command enum.
fn isEnabled(comptime T: type) bool {
return !@hasDecl(T, "enabled") or T.enabled;
}
fn builtinCount() comptime_int {
comptime {
var count = 0;
for (@typeInfo(@This()).@"struct".decls) |d| {
if (@TypeOf(@field(@This(), d.name)) != type) continue;
const T = @field(@This(), d.name);
if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue;
if (@TypeOf(T.run) != fn (Ctx) void)
@compileError(d.name ++ ".run must have signature fn (Ctx) void");
count += 1;
}
return count;
}
}
fn builtinList() [builtinCount()]type {
comptime {
@setEvalBranchQuota(4000);
var list: [builtinCount()]type = undefined;
var count = 0;
for (@typeInfo(@This()).@"struct".decls) |d| {
if (@TypeOf(@field(@This(), d.name)) != type) continue;
const T = @field(@This(), d.name);
if (@typeInfo(T) != .@"struct" or !@hasDecl(T, "run") or !isEnabled(T)) continue;
list[count] = T;
count += 1;
}
return list;
}
}
/// A builtin's user-visible word: the LAST dotted segment of `@typeName`,
/// because @typeName spells a file-scope struct fully qualified
/// ("builtins.Kill"). Deriving it beats a `pub const name` field per struct,
/// which would be the same word written twice with nothing keeping the two
/// honest. A name that is not a legal identifier would be spelled `@"..."`.
pub fn word(comptime T: type) []const u8 {
const n = @typeName(T);
const dot = std.mem.lastIndexOfScalar(u8, n, '.') orelse return n;
return n[dot + 1 ..];
}
pub const OutputTraits = struct {
name: []const u8,
steps: bool = false,
jumps: bool = false,
commands: bool = false,
};
/// The enum: field name = struct name, value = index into `all()`. Everything
/// downstream (leader_path's EnumArray, leader_rows, the topbar's comptime
/// check, stringToEnum) speaks it exactly as it did when it was hand-written.
///
/// Registry-dependent APIs live in one namespace so the outer declaration
/// walk only sees this namespace's type, not functions whose signatures depend
/// on the builtin enum being constructed.
pub const registry = struct {
pub fn all() [builtinCount()]type {
return builtinList();
}
pub fn Builtin() type {
const cmds = builtinList();
const Tag = std.math.IntFittingRange(0, cmds.len - 1);
var names: [cmds.len][]const u8 = undefined;
for (cmds, 0..) |T, i| names[i] = word(T);
return @Enum(Tag, .exhaustive, &names, &std.simd.iota(Tag, cmds.len));
}
pub fn takesArg(b: Builtin()) bool {
inline for (builtinList(), 0..) |T, i|
if (@intFromEnum(b) == i) return @hasDecl(T, "takes_arg") and T.takes_arg;
unreachable;
}
pub fn outputTraits(b: Builtin()) ?OutputTraits {
inline for (builtinList(), 0..) |T, i|
if (@intFromEnum(b) == i) return if (@hasDecl(T, "output")) T.output else null;
unreachable;
}
};
// ---- the two acme verbs ----
// Look and Execute are the verbs the whole environment is built on, and they
// are BUILTINS: `Look main.zig` typed in a tag and executed is the same look a
// right click on `main.zig` is, `Exec ls` the same as a middle click on `ls`.
// The mouse buttons and Enter/Tab are not a second path into them any more —
// they are two bindings pointing here (config.look_cmd / exec_cmd), the status
// `SPC f s` has relative to Save. That is the whole feature: what used to be a
// `button` parameter threaded through every keyboard call site, with the
// builtin dispatch nested INSIDE it, is now one word each.
//
// The operand is `arg` in both — a name's tail (`Look main.zig`), else the
// selection a chord kept, else the word the gesture pointed at, which the
// gesture resolves and passes. Nothing to act on means nothing happens, the
// way `Save` on a terminal is inert.
pub const Look = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
c.p.lookAt(c.id, c.arg orelse return);
}
};
pub const Exec = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
// the destination pane is Look's business (it focuses what answered);
// an execute deliberately leaves you where you were
_ = c.p.execute(c.id, c.arg orelse return);
}
};
// ---- session ----
pub const Kill = struct {
pub fn run(c: Ctx) void {
c.p.quit = true;
c.p.emit(.quit);
}
};
pub const Dump = struct {
pub fn run(c: Ctx) void {
c.p.dumpState() catch {};
}
};
pub const Restore = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
var it = std.mem.tokenizeAny(u8, c.txt, " \t");
_ = it.next(); // the word "Restore"
const path = it.next() orelse (c.p.last_dump orelse return);
if (path.len > c.p.restore_buf.len) return;
@memcpy(c.p.restore_buf[0..path.len], path);
c.p.restore_req = c.p.restore_buf[0..path.len];
}
};
// ---- the message row ----
/// TEXT onto this pane's transient message row — the row a failed save, a
/// refused Look and a language server that would not start all report through
/// (Pardes.setMessage, and Pardes.reportError one line above it). Every writer
/// of that row is something going wrong, so until this word there was no way
/// to look at it without breaking something on purpose: no wording could be
/// checked against a narrow pane, and no test could pin the row without
/// arranging a real failure first.
///
/// Bare, it reports ITSELF through the error path, because that is the other
/// half of the same machinery — `reportError` is `setMessage` plus an
/// `<operation>: <Error>` — and because a word that needs no argument to
/// demonstrate one is a word you can also just click.
///
/// Whether the row is FREE is not asked here and is not this word's business:
/// an armed prompt outranks a message at render time, so posting under one is
/// stored and invisible, exactly as a save finishing under one is. Nor does
/// anything here decide when it goes away — your next key or click does, on
/// every pane at once, because a message is exactly as old as your last input.
pub const Msg = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
if (c.arg) |text|
c.p.setMessage(c.id, text)
else
c.p.reportError(c.id, comptime word(@This()), error.NoMessage);
}
};
// ---- display toggles ----
pub const Debug = struct {
pub fn run(c: Ctx) void {
c.p.show_debug = !c.p.show_debug;
}
};
pub const Colors = struct {
pub fn run(c: Ctx) void {
c.p.colors_on = !c.p.colors_on;
}
};
/// Soft wrap: a file line too long for the pane renders across several body
/// rows instead of running off the right edge. Global, the way Colors is —
/// it changes what every file pane looks like, so it is a switch you flip
/// once rather than something a pane carries. ON by default (Pardes.wrap_on),
/// so this is the word that turns wrapping OFF and gives hscroll back.
pub const Wrap = struct {
pub fn run(c: Ctx) void {
c.p.wrap_on = !c.p.wrap_on;
}
};
/// Taglines at the BOTTOM of every pane instead of the top. Global like Wrap
/// and for the same reason — a layout where some panes label themselves above
/// and others below is unreadable, so it is one switch for the whole screen.
/// The transient message row gives that row up and takes the one above it (see
/// render), so it is the pane's last BODY row either way and a prompt stays
/// beside the tag it is typed into.
pub const Tagbottom = struct {
pub fn run(c: Ctx) void {
c.p.tag_bottom = !c.p.tag_bottom;
}
};
/// One step along the ring. With 228 themes in it this is no longer a way to
/// REACH a theme — ThemeSel is — but it is still the way to browse one, and the
/// browse got better rather than worse: the generated half is sorted by name, so
/// the neighbours of wherever you are are that theme's own variants (light,
/// hard, soft, the whole gruvbox family in a row). Kept as the topbar word and
/// SPC t n it has always been; a ring you can walk off the end of in three
/// clicks was never what made it useful.
pub const NextColor = struct {
pub fn run(c: Ctx) void {
c.p.setThemeIndex((c.p.theme_idx + 1) % pardes.themes.len);
}
};
/// The theme BY NAME — `Theme acme`. The ring grew past the point where
/// cycling to the one you want is reasonable, so this is the way to ask for
/// one, and NextColor stays as the way to browse. Inert without an argument
/// (there is no theme called nothing), which is also why it has no leader path:
/// a key path names a builtin and can never carry the name of a theme.
///
/// A LINEAR SCAN over 228 names, on a keystroke: the alternative is a comptime
/// name->index map, which is a second copy of the ring to build for a lookup
/// nobody will ever measure. 228 short string compares is microseconds, and it
/// happens once per theme change, not once per frame.
pub const Theme = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
const want = std.mem.trim(u8, c.arg orelse return, " \t\r\n");
for (pardes.themes, 0..) |t, i| {
if (std.mem.eql(u8, t.name, want)) {
c.p.setThemeIndex(i);
return;
}
}
}
};
/// The binary a NEW terminal execs: `Shell fish`, `Shell zsh`,
/// `Shell /opt/homebrew/bin/bash`. A bare name is looked up on the shells'
/// side against the handful of directories a shell actually lives in — not
/// $PATH, because the lookup has to finish BEFORE the fork (a PATH search
/// allocates, and nothing between fork and exec may).
///
/// Takes a NAME, so it has no leader path and none in the topbar, for the same
/// reason Theme has neither. Panes already open keep the shell they are
/// running; this is what the next one starts.
pub const Shell = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
const want = std.mem.trim(u8, c.arg orelse return, " \t\r\n");
// A name too long for the buffer is not silently truncated into a
// DIFFERENT binary — `/very/long/path/to/fish` clipped is a path that
// either does not exist or, worse, does.
if (want.len == 0 or want.len > c.p.shell_buf.len) return;
@memcpy(c.p.shell_buf[0..want.len], want);
c.p.shell_len = @intCast(want.len);
}
};
/// ...and the list of what Theme takes, as a buffer you walk. Its rows are
/// `Theme <name>` COMMANDS rather than locations, which is one flag on the
/// buffer (output_pane.Traits.commands) and changes what a step SELECTS: the
/// whole line, since there is no path inside it to pick out. Tab on what n
/// selected wears that theme — the same middle click on the row is — so
/// walking the list with n/Tab is trying them on, and stopping is choosing.
pub const ThemeSel = struct {
pub const output: OutputTraits = .{ .name = config.themes_buffer, .steps = true, .commands = true };
pub fn run(c: Ctx) void {
output_pane.openThemes(c.p, c.id) catch |err| c.p.reportError(c.id, "themes", err);
}
};
pub const Crt = struct {
pub fn run(c: Ctx) void {
c.p.crt_on = !c.p.crt_on;
}
};
// ---- the GUI's font, and NOTHING on any other platform ----
//
// Theme and ThemeSel again, one layer down: a word that takes a name, and the
// list of what it takes. What is different is that these two only EXIST in a
// gui build, and the mechanism is the one this file's header describes rather
// than a new one — `all()` folds the enum out of the SHAPE of each decl, so a
// struct whose `run` is not `fn (Ctx) void` is not a builtin. Here `run` is a
// void const on tty and web: the enum has no field, `SPC ?` has no row, the
// dispatcher has no prong, and nothing in a tty binary ever opens a font
// directory. The body sits inside the struct as an ordinary private decl,
// which the walk never sees (it only reads pub, file-scope declarations) and
// which nothing on those platforms ever analyses.
//
// A `pub const Font = if (gui) struct {...} else struct {}` would read better
// and is WRONG: zig names a struct born inside an if-expression
// "builtins.Font__struct_32751", and that name is the user-visible word.
/// The GUI font BY NAME — `Font DejaVuSansMono-Regular`, the way `Theme <name>`
/// takes a theme, and inert without an argument for the same reason (there is
/// no font called nothing). The name is a font FILE's stem, which is what the
/// picker lists; resolving it is a walk of the font directories that stops at
/// the first match, so nothing is cached and an install five seconds ago is
/// findable.
///
/// The core cannot load a font — it has no rasterizer, no atlas and no window
/// — so this asks: the resolved PATH goes in fonts.want, the shell takes it on
/// its next pass and re-rasters. Exactly the shape Restore already has.
pub const Font = struct {
pub const takes_arg = true;
pub const enabled = pardes.font_picker;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
fn apply(c: Ctx) void {
const want = std.mem.trim(u8, c.arg orelse return, " \t\r\n");
const hit = fonts.list(c.p.scratch.allocator(), want);
if (hit.len == 0) return;
const path = hit[0].path;
if (path.len > fonts.want_buf.len) return;
@memcpy(fonts.want_buf[0..path.len], path);
fonts.want = fonts.want_buf[0..path.len];
fonts.chosen = std.fs.path.stem(fonts.want.?);
}
};
/// ...and the list of what Font takes: every MONOSPACE font on the machine,
/// one `Font <name>` row each, in the picker ThemeSel already is (rows that
/// are commands, so n/N select each one WHOLE and Tab runs it — walking with
/// n and pressing Tab wears each font in turn, and picking one is stopping
/// there).
///
/// Monospace only, which is the one judgement in the feature: the grid is a
/// fixed cell, so a proportional face is not a worse-looking option but an
/// unreadable one — and this picker EXECUTES what it steps onto, so listing
/// them would mean the list wearing one on the way past. See fonts.monospaced.
pub const FontSel = struct {
pub const output: OutputTraits = .{ .name = config.fonts_buffer, .steps = true, .commands = true };
pub const enabled = pardes.font_picker;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
fn apply(c: Ctx) void {
output_pane.openFonts(c.p, c.id) catch |err| c.p.reportError(c.id, "fonts", err);
}
};
/// Toggle a native PDF between the reading-oriented fit-width view and the
/// whole-page-height view. Like Font on non-GUI builds, this declaration's
/// `run` deliberately has the wrong shape when MuPDF is disabled: `all()` then
/// omits it entirely, so the enum, Help and runtime binary contain no
/// PdfFit.
pub const PdfFit = struct {
pub const enabled = pardes.pdf_enabled;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
fn apply(c: Ctx) void {
c.p.togglePdfFit(c.pane);
}
};
/// Cycle a native PDF through original pixels, a chroma-preserving themed
/// filter, and a full theme duotone. It has the same compile-time and
/// pane-local shape as PdfFit: absent without MuPDF and inert off a PDF pane.
pub const PdfTint = struct {
pub const enabled = pardes.pdf_enabled;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
fn apply(c: Ctx) void {
c.p.togglePdfTint(c.pane);
}
};
/// Show this PDF's document outline as a live, steppable output pane. The
/// command is absent from non-MuPDF builds and deliberately inert on every
/// other pane kind, like the two PDF display toggles above.
pub const PdfSections = struct {
pub const output: OutputTraits = .{ .name = config.pdf_sections_buffer, .steps = true };
pub const enabled = pardes.pdf_enabled;
pub fn run(c: Ctx) void {
if (comptime enabled) apply(c) else unreachable;
}
fn apply(c: Ctx) void {
c.p.openPdfSections(c.id);
}
};
// The image pane's three renderer toggles. They used to be words the image tag
// printed and the execute dispatcher matched by hand; as builtins they are
// executable anywhere, pressable under SPC and listed by `SPC ?`, the whole
// reason the tag no longer carries them. Each acts on the pane it runs in and
// is inert anywhere else, the way Save is on a terminal — flipping the field is
// the whole toggle: drawImage re-matches the glyph grid when it sees
// grid_mode/grid_ascii disagree with the live ones.
/// glyph art over the host's pixels
pub const Petscii = struct {
pub fn run(c: Ctx) void {
if (c.pane.image) |*iv| {
iv.petscii = !iv.petscii;
}
}
};
/// the C64 palette or the terminal's own 16
pub const Palette = struct {
pub fn run(c: Ctx) void {
if (c.pane.image) |*iv| {
iv.pmode = if (iv.pmode == .commodore) .terminal else .commodore;
}
}
};
/// add the printable ASCII bitmaps to the matcher's glyph set
pub const Ascii = struct {
pub fn run(c: Ctx) void {
if (c.pane.image) |*iv| {
iv.ascii = !iv.ascii;
}
}
};
// ---- the system clipboard ----
// helix's `<space>` clipboard menu, and the ONLY five words in pardes that
// touch the desktop's clipboard. Everything else — `y`, `d`, `c`, `p`, `P`,
// `R`, the acme cut/paste chords — lives entirely in the internal register,
// which is helix's arrangement and, less abstractly, the reason deleting a
// character no longer throws away whatever you had copied from a browser.
//
// They are builtins rather than bare chords because the leader table is the
// remapping surface and a leader path names a builtin: spelling them here
// puts them in Help's index, makes them executable words like every other
// verb, and costs no second mechanism. Their paths ARE helix's letters, on
// the same leader helix uses — see config.leader_path.
//
// The two directions are not symmetric, and cannot be. Writing is a fire-off:
// the core owns the bytes and the shell copies them out. READING has to leave
// the core and come back — SDL and NSPasteboard answer inside the same drain,
// a browser answers a promise later, and a terminal answers over OSC 52 or,
// far more often, refuses outright. So a paste is a REQUEST (the
// read_clipboard effect) that may simply never be answered, and a `SPC p`
// that does nothing in a locked-down terminal is the honest outcome rather
// than a bug to paper over with the internal register.
pub const ClipYank = struct {
pub fn run(c: Ctx) void {
c.p.clipYank(c.pane, false);
}
};
/// helix `<space>Y`: the PRIMARY selection alone, where `SPC y` joins every
/// cursor's. One cursor makes them the same word.
pub const ClipYankMain = struct {
pub fn run(c: Ctx) void {
c.p.clipYank(c.pane, true);
}
};
pub const ClipPaste = struct {
pub fn run(c: Ctx) void {
c.p.clipRequest(c.id, .after);
}
};
pub const ClipPasteBefore = struct {
pub fn run(c: Ctx) void {
c.p.clipRequest(c.id, .before);
}
};
pub const ClipReplace = struct {
pub fn run(c: Ctx) void {
c.p.clipRequest(c.id, .replace);
}
};
// ---- panes and columns ----
pub const Save = struct {
pub fn run(c: Ctx) void {
// an output buffer has no file behind it — nothing to write
if (c.pane.file) |*f| {
if (!output_pane.fileTraits(f.output).saves) return;
c.p.emit(.{ .save_file = .{ .pane = @intCast(c.id) } });
// ...and this edit is now the one on disk. See File.saved_revision
// for why the mark goes here rather than after the write.
f.saved_revision = f.revision;
}
}
};
/// Ask the native shell for an atomically-created empty temporary file. The
/// pane and its lifetime serial are the placement token: by the time IO
/// finishes another column may be active, or this slot may even have been
/// reused, and neither is permission to put the document somewhere else.
pub const New = struct {
pub fn run(c: Ctx) void {
if (c.p.freeSlot() == null) return;
c.p.emit(.{ .new_file = .{ .pane = @intCast(c.id), .serial = c.pane.serial } });
}
};
pub const Newcol = struct {
pub fn run(c: Ctx) void {
const free = c.p.freeSlot() orelse return;
if (c.p.ncol >= pardes.MAX_COLS) return;
const nt = c.p.newShell(free, "") catch return;
nt.greet = true;
c.p.layoutAppendColumn(free);
c.p.active = free;
}
};
pub const Del = struct {
pub fn run(c: Ctx) void {
c.p.absorbVWeight(c.id);
c.p.layoutRemove(c.id);
c.p.deinitPane(c.pane);
c.p.panes[c.id] = null;
if (c.p.active == c.id) c.p.active = c.p.prevFocus(c.id) orelse {
c.p.quit = true;
c.p.emit(.quit);
return;
};
}
};
pub const Delcol = struct {
pub fn run(c: Ctx) void {
const f = c.p.layoutFindTerm(c.id) orelse return;
var ids: [pardes.MAX_PANES]usize = undefined;
const nids = c.p.col_n[f.col];
for (0..nids) |k| ids[k] = c.p.col_terms[f.col][k];
for (ids[0..nids]) |tid| {
if (c.p.panes[tid]) |tt| {
c.p.layoutRemove(tid);
c.p.deinitPane(tt);
c.p.panes[tid] = null;
}
}
if (c.p.panes[c.p.active] == null) c.p.active = c.p.prevFocus(c.p.active) orelse {
c.p.quit = true;
c.p.emit(.quit);
return;
};
}
};
pub const Tutor = struct {
pub fn run(c: Ctx) void {
const free = c.p.freeSlot() orelse return;
const nt = c.p.openTutorView(free) catch return;
c.p.placeDoc(c.id, free, nt); // a doc like any other
}
};
pub const Help = struct {
pub const output: OutputTraits = .{ .name = config.help_buffer };
pub fn run(c: Ctx) void {
output_pane.openHelp(c.p, c.id, "") catch |err| c.p.reportError(c.id, "help", err);
}
};
/// Where pardes read its startup commands from — the path, printed into an
/// output buffer, `SPC f c` or the word executed anywhere.
///
/// The one question docs/config.md cannot answer, because the answer depends
/// on the machine: XDG_CONFIG_HOME if it is set and absolute, else
/// ~/Library/Application Support/pardes on macOS and ~/.config/pardes
/// everywhere else. Printing it beats documenting it — the row is ordinary
/// text, so a right click on it opens the file, and when there is no file
/// there yet the path is still exactly what you needed to know.
pub const Config = struct {
pub const output: OutputTraits = .{ .name = config.config_buffer };
pub fn run(c: Ctx) void {
output_pane.openConfig(c.p, c.id) catch |err| c.p.reportError(c.id, "config", err);
}
};
// ---- search ----
// The two builtins that ASK for something — Find walks file NAMES under this
// pane's directory, Grep file CONTENTS under every pane's. With an argument
// there is nothing to ask: it IS the pattern, so the walk runs now (this is
// what a `Grep` executed with a selection chorded to it means). Without one
// they arm the same tag input `/` does, and Enter runs it (submitSearch).
pub const Find = struct {
pub const takes_arg = true;
pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true };
pub fn run(c: Ctx) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (pat.len > 0) return c.p.runSearch(c.id, pat, .find, .top) catch |err|
c.p.reportError(c.id, "find", err);
c.p.startSearch(c.pane, config.find_marker);
}
};
/// Find's sibling: Find matches file NAMES under this pane's directory, Grep
/// matches file CONTENTS under every pane's directory at once.
pub const Grep = struct {
pub const takes_arg = true;
pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true };
pub fn run(c: Ctx) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (pat.len > 0) return c.p.runSearch(c.id, pat, .grep, .top) catch |err|
c.p.reportError(c.id, "grep", err);
c.p.startSearch(c.pane, config.grep_marker);
}
};
// ---- the window group ----
// The DESTINATION is the name — a word, the way a tag holds Del or Save —
// because these names live in the same vocabulary as everything else here:
// `Wh` would be a leader key path leaking into the text you can middle-click.
// Plain English words are safe for exactly these five: focus is the cheapest
// thing to change by accident (nothing is edited, closed or written) and the
// way back is the opposite word.
pub const Left = struct {
pub fn run(c: Ctx) void {
c.p.focusDir(c.id, .left);
}
};
pub const Down = struct {
pub fn run(c: Ctx) void {
c.p.focusDir(c.id, .down);
}
};
pub const Up = struct {
pub fn run(c: Ctx) void {
c.p.focusDir(c.id, .up);
}
};
pub const Right = struct {
pub fn run(c: Ctx) void {
c.p.focusDir(c.id, .right);
}
};
// ---- the jump group ----
// Where focus HAS BEEN, as three verbs and a list over the one stack pardes
// keeps (Pardes.jumps — see trackJump for what gets onto it). Builtins rather
// than bare key handlers for the same reason the four directions are: one
// implementation, reachable by chord, by `SPC j ...`, and by executing the
// word wherever it is written.
/// Ctrl-o: one step back into the history.
pub const Back = struct {
pub fn run(c: Ctx) void {
c.p.jumpBy(-1);
}
};
/// Ctrl-i: one step forward again, up to wherever Back started.
pub const Forward = struct {
pub fn run(c: Ctx) void {
c.p.jumpBy(1);
}
};
/// vim's Ctrl-^: the pane you were in before this one, whichever it was — the
/// hop you press twice a minute and never want to count steps for. Body-normal
/// Esc is this, which is what makes alternating between two panes one key you
/// hold down: two files, or a file and its shell, or a file and a +Search.
///
/// It does NOT move the stack cursor: it goes somewhere, so trackJump records
/// it like any other move, and that is exactly what makes it an involution —
/// after the hop, the pane you came from is the newest OTHER pane, so pressing
/// it again comes straight back. Back/Forward walk history; this one makes it.
///
/// It replaced a `Toggleterm` that hopped specifically between the newest DOC
/// and the newest TERMINAL. That distinction never earned its keep: it made Esc
/// unpredictable (which of three panes you landed on depended on their kinds),
/// and it could not alternate between two files at all — the case you hit most.
/// "The pane before this one" needs no kinds and is the same key twice.
pub const Last = struct {
pub fn run(c: Ctx) void {
var i = c.p.njumps;
while (i > 0) {
i -= 1;
const j = c.p.jumps[i];
if (j.pane != c.id) return c.p.focusPaneLine(j.pane, .{ .line = j.line, .col = j.col });
}
}
};
/// The same stack, as text you can read and click. Not a copy of it and not a
/// second list kept in step — the buffer is RENDERED from the stack when you
/// ask, the way +Search is rendered from a walk.
pub const Jumplist = struct {
pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true };
pub fn run(c: Ctx) void {
output_pane.openJumps(c.p, c.id) catch |err| c.p.reportError(c.id, "jumplist", err);
}
};
// ---- the language group ----
// Reached as `SPC l <helix's letter>` — see leader_path for why the prefix
// exists. They are builtins rather than bare keys for the same reason Save is
// one: the word is executable wherever it appears, so a middle-click on
// `Hover` in a tag does what `SPC l k` does. The five GOTOS are not here —
// helix binds them under `g` as motions, and a motion has no business being a
// word you can click.
//
// Most of them are one call: ask, and let the answer land in lspResponse.
// Nothing here blocks or knows what a backend is — swapping backends changes
// lsp.query and not one line below.
pub const Hover = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .hover, "");
}
};
pub const CodeAction = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .code_action, "");
}
};
pub const SelectRefs = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .select_refs, "");
}
};
pub const Symbols = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .document_symbols, "");
}
};
pub const Diagnostics = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .diagnostics, "");
}
};
pub const WsDiagnostics = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .workspace_diagnostics, "");
}
};
// The two that need a word from the user, handled exactly the way Find and
// Grep are: an argument means run it now (a selection chorded onto the name),
// no argument arms the tag input and Enter submits (submitSearch).
pub const Rename = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (a.len > 0) return c.p.lspRequest(c.id, .rename, a);
c.p.startSearch(c.pane, config.rename_marker);
}
};
pub const WsSymbols = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (a.len > 0) return c.p.lspRequest(c.id, .workspace_symbols, a);
c.p.startSearch(c.pane, config.symbol_marker);
}
};
// Introspection. A language backend that answers nothing looks exactly like
// one that is broken — from the outside, `gd` doing nothing is both "there is
// no definition" and "the analyser threw and we swallowed it". These two are
// how you tell: Lspinfo says what the backend IS, Lspwhy says what it just DID
// and where it stopped.
pub const Lspinfo = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .status, "");
}
};
pub const Lspwhy = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .explain, "");
}
};
|