diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-11 18:30:13 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-12 13:04:32 -0300 |
| commit | b424164922842796619cb6894ec46d729a8a6826 (patch) | |
| tree | bd4653accfaeb67012f4e7257c61eaf4fb12c892 /src/look.zig | |
| parent | 08f32cdde672740b71608f3dfccd629dcbac78f7 (diff) | |
| download | pardes-b424164922842796619cb6894ec46d729a8a6826.tar.gz pardes-b424164922842796619cb6894ec46d729a8a6826.zip | |
clipboard, n/N and the tty prompt: three things that were half-wired
Three changes that all turned out to be the same shape -- a feature that
worked in one direction, or for one pane kind, and quietly did not in the
others.
CLIPBOARD. Every register write emitted set_clipboard, so deleting one
character threw away whatever the desktop was holding; multi-cursor yank took
the join's early return and emitted nothing at all, so the same key reached
the clipboard on one cursor and not on two. Nothing could READ the clipboard:
the SDL shell had no SDL_GetClipboardText anywhere in it, and the tty shell
never asked for OSC 52, so `p` from another application was dead in both.
Now it is helix's split. y/d/c/p/P/R and the acme chords are the DEFAULT
REGISTER and nothing else; the system clipboard is five words on helix's own
letters -- SPC y, SPC Y, SPC p, SPC P, SPC R -- spelled as builtins so they
land in Help and are executable like every other verb. The one exception is
the tag `y` chord, which still mirrors out because a tag is always insert, so
SPC cannot be pressed there, and copying the path out is the whole point of
the chord.
Reading is a new read_clipboard effect answered by an ordinary Event.paste, so
the round trip is honest about being one: SDL and NSPasteboard answer inside
the same drain, the browser answers a promise, and a terminal answers over
OSC 52 or -- far more often -- refuses. A refused read is a paste that does
not happen, and the request dies at the next keystroke rather than landing
minutes late in whatever pane is focused by then.
The tty shell also enables BRACKETED PASTE now and coalesces
paste_start..paste_end into one event. Before this a paste arrived as a flood
of individual key presses: plausible in insert mode, and in normal mode every
pasted character ran as a command.
n/N. They stepped the armed results buffer and immediately Looked each row, so
you could not walk past a hit without opening it. They are a MOTION now:
select the next look-able text, open nothing, and let Enter decide. What they
step is the largest whitespace-delimited run look.resolve can act on
(look.lookableSpan, wrapper punctuation peeled), over a RING of panes -- every
pane that has performed a look, most recent first, then the output buffers
that have not, newest first, and only if both are empty the pane in front of
you. N is the exact inverse of n, computed rather than remembered: both
directions ask the same question about the same spans and compare against the
column the walk parks on, so x presses one way and x back land exactly where
you started, pane boundaries and the ring's seam included.
A ring rather than a list with two ends because a shell's cursor sits at the
prompt, below everything it has printed, so a walk that could not come round
would have nowhere to go on the very first press -- which is the case n/N were
written for.
One motion everywhere, no pane-kind or buffer-kind special case. The only
thing a buffer may change is the GRAIN of what a step selects, and it does it
with one flag rather than a branch: output_pane.Traits.commands (renamed from
`executes`, which named one reader's behaviour rather than the fact) makes a
row select WHOLE, because a ThemeSel line is a word to run and has no path
inside it to pick out. `]d`/`[d` are not n/N -- they are helix's diagnostic
motions, their job is to ARRIVE, and they still reach searchStep.
THE TTY PROMPT. Leaving raw tty blanked the prompt row, and the command you
had typed at that prompt shares the row, so it went too -- a shell out of tty
read as output only. OSC 133 marks the row CELL by cell, so the two are
separable: config.tty_blank = .prompt cuts the prompt's own columns and leaves
the command, left-hugged at column 0 in line with the output under it rather
than in a bay of blanks. .prompt_and_input is the old behaviour, kept.
Because the row is now something you can put a cursor in, enterTty adds the
hidden prompt width back before asking ghostty to walk the shell's own cursor
to it -- the modal column on a cut row is short by exactly that much.
Verified: unit-test 186/186 (nine new), snap 87/87 (new ttyprompt.snap),
hxdiff 481 and hxparity 561 with 0 mismatches, tty and gui both build. And
against the real binaries rather than the harness: in a pty, SPC y emits OSC
52 carrying exactly the selection while plain y emits nothing, SPC p issues
the read and pastes the reply, and a bracketed paste of "dd..." inserts text
instead of deleting two lines. In a real SDL window, SPC y then SPC p round
trips through the system clipboard while the default register holds different
text. Setting tty_blank back to .prompt_and_input reproduces all 86 old
goldens byte for byte.
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/look.zig b/src/look.zig index 7169cf8b..36390ec2 100644 --- a/src/look.zig +++ b/src/look.zig @@ -225,6 +225,82 @@ test ".pdf Look paths are ordinary files when MuPDF is disabled" { } } +/// Where a look-able word actually SITS inside a run of non-whitespace. +pub const Span = struct { start: usize, end: usize }; + +/// The punctuation a path wears in prose and never owns. Two sets, because +/// the two ends are not alike: a directory may legally END in `/`, and the +/// `:` that closes `grep -n`'s `main.zig:100:` is junk on the right and +/// meaningful nowhere on the left. +const lead_trim = "([{<\"'`*"; +const trail_trim = ")]}>\"'`*,;:.!?"; + +/// The largest look-able span inside one whitespace-delimited `word`, or null +/// when nothing in it resolves. This is the whole heuristic behind n/N: split +/// on whitespace, and take the biggest piece of each run that Look can act on. +/// +/// TWO resolve attempts at most, which is what keeps a motion across a +/// screenful of prose from being a hundred realpaths: the run with every +/// wrapper character peeled off BOTH ends at once, then — only if that found +/// nothing — the run exactly as written. +/// +/// PEELED FIRST, which is the ordering that matters. `resolve` is lenient +/// about a tail it cannot parse (`main.zig:12:3,` yields the FILE and drops +/// the position, by design), so asking it about the raw run first would +/// happily answer yes and swallow the comma along with the `:3`. Peeling +/// first hands it `main.zig:12:3` and the look lands on the column. The raw +/// run stays as the fallback for the file genuinely named `foo,` or `..`, +/// where the peel eats something real. +/// +/// Deliberately NOT a search for the longest resolving substring: that costs +/// a syscall per prefix to find a path hiding inside a word nobody typed as +/// one. A run needing a cleverer peel is still one Enter away with the cursor +/// parked on it. +/// +/// Direction-free on purpose: n and N ask this the same question about the +/// same run and get the same span back, which is what lets the two motions be +/// exact inverses of each other. +pub fn lookableSpan(word: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span { + if (word.len == 0) return null; + var lo: usize = 0; + var hi: usize = word.len; + while (lo < hi and std.mem.indexOfScalar(u8, lead_trim, word[lo]) != null) lo += 1; + while (hi > lo and std.mem.indexOfScalar(u8, trail_trim, word[hi - 1]) != null) hi -= 1; + if (lo < hi and resolve(word[lo..hi], cwd, realbuf) != .none) return .{ .start = lo, .end = hi }; + // nothing came off, so the peeled attempt WAS the raw one + if (lo == 0 and hi == word.len) return null; + if (resolve(word, cwd, realbuf) == .none) return null; + return .{ .start = 0, .end = word.len }; +} + +test "lookableSpan peels prose punctuation off a path, largest first" { + if (!platform_has_fs) return; + var realbuf: [4096]u8 = undefined; + // the bare run resolves whole, wrappers and all left alone + try std.testing.expectEqualDeep( + @as(?Span, .{ .start = 0, .end = "src/look.zig".len }), + lookableSpan("src/look.zig", ".", &realbuf), + ); + // ...and a wrapped one gives back the span INSIDE the wrappers + try std.testing.expectEqualDeep( + @as(?Span, .{ .start = 1, .end = 1 + "src/look.zig".len }), + lookableSpan("(src/look.zig),", ".", &realbuf), + ); + // the `:LINE:COL` tail is part of the span: it is what a look READS + try std.testing.expectEqualDeep( + @as(?Span, .{ .start = 0, .end = "src/look.zig:12:3".len }), + lookableSpan("src/look.zig:12:3,", ".", &realbuf), + ); + // grep -n's trailing delimiter comes off, the line number stays + try std.testing.expectEqualDeep( + @as(?Span, .{ .start = 0, .end = "src/look.zig:12".len }), + lookableSpan("src/look.zig:12:", ".", &realbuf), + ); + try std.testing.expectEqual(@as(?Span, null), lookableSpan("nothing-here", ".", &realbuf)); + try std.testing.expectEqual(@as(?Span, null), lookableSpan("", ".", &realbuf)); + try std.testing.expectEqual(@as(?Span, null), lookableSpan("((()))", ".", &realbuf)); +} + /// Resolve a looked-at word against the pane's directory. `realbuf` must /// outlive the returned Target (native paths point into it; web paths are /// process-lifetime slices in the embedded source archive). |
