diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-06 20:58:04 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | 49f8c696ea208d2653521699d77d7e8f48cac183 (patch) | |
| tree | 522a74735b2507399c2fc913a8bdc4287584f98f | |
| parent | 513938c1cfb216a3bc4a3559cf7731b8e44a952f (diff) | |
| download | pardes-49f8c696ea208d2653521699d77d7e8f48cac183.tar.gz pardes-49f8c696ea208d2653521699d77d7e8f48cac183.zip | |
rework tty n/N: a pure token MOTION (normal mode only) — select the next/prev whitespace-separated token that look.resolve can open (several per line: the greet ls row hops big.txt -> plain.txt -> sub), park the cursor at the token start, open NOTHING. Enter's existing normal-mode handler does the look on the selection (dir -> shell+ls there, file -> pane), so navigation continues with n/N+Return inside whatever opened. Wraps when nothing lies in the motion direction (first n out of tty mode starts at the prompt row and lands on the first token — lookStep pins the cursor first). vsel anchors the token end, cursor at its start (vselText is end-inclusive). File-pane search n/N untouched. ttylook.snap rewritten for the new semantics: token hops with selection styling, insert-mode n still types, Return-opens-dir, empty-dir no-op, cursor-word Enter opens a file. 29/29.
| -rw-r--r-- | src/pardes.zig | 50 | ||||
| -rw-r--r-- | test/snapshots/ttylook.golden | 252 | ||||
| -rw-r--r-- | test/snapshots/ttylook.snap | 91 |
3 files changed, 200 insertions, 193 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index a2cfe1c6..ebc54426 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1708,28 +1708,54 @@ pub const Pardes = struct { /// chosen row gets the real look. The modal cursor is the position, so /// the walk continues from wherever j/k left it. The look may focus what /// it opened; focus comes back here so the next n keeps stepping. + /// n/N on a terminal pane: a MOTION over lookable tokens. Select the + /// next/prev whitespace-separated token that look.resolve can turn into a + /// file/dir (several per line: an ls row hops big.txt -> plain.txt), park + /// the cursor at its start, open NOTHING — Enter's normal-mode handler + /// looks the selection. Wraps around when nothing lies in the direction + /// (fresh out of tty mode the cursor sits below the output, so the first + /// n lands on the first token). fn lookStep(p: *Pardes, pane: *Pane, pl: PaneLines, delta: i32) void { - const id = p.active; + _ = p; // a pure motion now: Enter's normal-mode handler does the look + pane.pinCursor(); // fresh out of tty mode the cursor still tracks the shell const nrows: i32 = @intCast(pl.lines.len); + if (nrows == 0) return; var realbuf: [4096]u8 = undefined; - var r = pane.cur_row + delta; - while (r >= 0 and r < nrows) : (r += delta) { + var k: i32 = 0; + while (k < nrows) : (k += 1) { + const r = @mod(pane.cur_row + delta * k, nrows); const ln = pl.lines[@intCast(r)]; - var hi: usize = 0; - while (hi < ln.len and look.isFileChar(ln[hi])) hi += 1; - if (hi == 0 or look.resolve(ln[0..hi], pane.cwdSlice(), &realbuf) == .none) continue; - pane.msel = .{ .active = true, .r0 = r, .r1 = r }; - pane.vsel.active = false; + var hit_t0: usize = 0; + var hit_t1: usize = 0; + var i: usize = 0; + while (i < ln.len) { + while (i < ln.len and (ln[i] == ' ' or ln[i] == '\t')) i += 1; + const t0 = i; + while (i < ln.len and ln[i] != ' ' and ln[i] != '\t') i += 1; + if (i == t0) break; + // on the cursor's own row (no wrap yet) only tokens strictly + // past the cursor count, in the motion's direction + if (k == 0) { + if (delta > 0 and @as(i32, @intCast(t0)) <= pane.cur_col) continue; + if (delta < 0 and @as(i32, @intCast(t0)) >= pane.cur_col) continue; + } + if (look.resolve(ln[t0..i], pane.cwdSlice(), &realbuf) == .none) continue; + hit_t0 = t0; + hit_t1 = i; + if (delta > 0) break; // first token forward; keep the last one backward + } + if (hit_t1 == 0) continue; + // anchor the selection at the token's end, cursor at its START + pane.vsel = .{ .active = true, .row = r, .col = @intCast(hit_t1 - 1) }; + pane.msel.active = false; pane.cur_row = r; - pane.cur_col = 0; + pane.cur_col = @intCast(hit_t0); pane.cur_off = 0; pane.cur_pinned = true; pane.ensureCursorVisible(); - p.actOnSelection(.right, id, ln[0..hi], null); - p.active = id; return; } - // nothing lookable that way: stay put + // nothing lookable anywhere: stay put } const InsertAt = enum { at, append, line_start, line_end, open_below, open_above }; diff --git a/test/snapshots/ttylook.golden b/test/snapshots/ttylook.golden index 8465dbea..1233118d 100644 --- a/test/snapshots/ttylook.golden +++ b/test/snapshots/ttylook.golden @@ -1,19 +1,19 @@ -== snap lsrow grid=120x30 cursor=2,2 +== snap tok1 grid=120x30 cursor=2,3 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 1 line 1 -| 2 line 2 big.txt plain.txt sub -| 3 line 3 -| 4 line 4 -| 5 line 5 -| 6 line 6 -| NOR /tmp/pardes-snap/ttylook/cwd Del +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| +| +| +| +| +| +| +| | -| plain.txt -| big.txt:33 -| zz | -| DONE | | NOR /tmp/pardes-snap/ttylook/cwd Del | @@ -29,23 +29,23 @@ | | | -== style lsrow +== style tok1 |0: 0-44 #969696,#2c2a3e, 45-119 d,#2c2a3e, -|1: 0-1 d,#383c54, 2-50 #969696,#2c2a3e, 51-59 d,#2c2a3e, 60-61 d,#383c54, 62-97 #969696,#2c2a3e, 98-119 d,#2c2a3e, -|2: 0-1 d,#525252, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|3: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|4: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|5: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|6: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|7: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|8: 0-1 d,#6e4fd0, 2-37 #969696,#2c2a3e, 38-59 d,#2c2a3e, 60-61 d,#525252, 62-119 d,d, -|9: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|10: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|11: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|1: 0-1 d,#6e4fd0, 2-37 #969696,#2c2a3e, 38-59 d,#2c2a3e, 60-61 d,#383c54, 62-97 #969696,#2c2a3e, 98-119 d,#2c2a3e, +|2: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|3: 0-1 d,#525252, 2-8 #d8c8a8,#4a3a1e, 9-59 d,d, 60-61 d,#525252, 62-119 d,d, +|4: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|5: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|6: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|7: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|8: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|9: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|10: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|11: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |12: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |13: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |14: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|15: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, +|15: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |16: 0-1 d,#383c54, 2-37 #969696,#2c2a3e, 38-59 d,#2c2a3e, 60-61 d,#525252, 62-119 d,d, |17: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |18: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, @@ -60,23 +60,54 @@ |27: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |28: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, |29: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -== snap line20 grid=120x30 cursor=2,12 +== snap tok2 grid=120x30 cursor=11,3 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 17 line 17 -| 18 line 18 big.txt plain.txt sub -| 19 line 19 -| 20 line 20 -| 21 line 21 -| 22 line 22 +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| +| +| +| +| +| +| +| +| +| +| | NOR /tmp/pardes-snap/ttylook/cwd Del +| | big.txt plain.txt sub | -| zz -| big.txt:20 -| ww | -| plain.txt +| +| +| +| +| +| +| +| +| +== snap tokback grid=120x30 cursor=2,3 +|Kill Newcol Tutor Debug Colors NextColor Dump +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| +| +| +| +| +| +| +| +| +| +| | NOR /tmp/pardes-snap/ttylook/cwd Del | | big.txt plain.txt sub @@ -91,22 +122,22 @@ | | | -== snap plain grid=120x30 cursor=2,12 +== snap insert grid=120x30 cursor=2,3 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 17 line 17 -| 18 line 18 big.txt plain.txt sub -| NOR /tmp/pardes-snap/ttylook/cwd/plain.txt Save Del -| 1 just text +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| nnbig.txt plain.txt sub big.txt plain.txt sub +| +| +| +| +| +| +| +| | | -| NOR /tmp/pardes-snap/ttylook/cwd Del -| big.txt:20 -| ww | -| plain.txt -| big.txt:33 -| zz | | NOR /tmp/pardes-snap/ttylook/cwd Del | @@ -122,23 +153,23 @@ | | | -== snap line33 grid=120x30 cursor=2,12 +== snap tok3 grid=120x30 cursor=22,3 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 32 line 32 -| 33 line 33 big.txt plain.txt sub -| NOR /tmp/pardes-snap/ttylook/cwd/plain.txt Save Del -| 1 just text +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| +| +| +| +| +| +| | | -| NOR /tmp/pardes-snap/ttylook/cwd Del -| ww | -| plain.txt -| big.txt:33 -| zz | -| DONE | NOR /tmp/pardes-snap/ttylook/cwd Del | | big.txt plain.txt sub @@ -153,22 +184,22 @@ | | | -== snap back grid=120x30 cursor=2,12 +== snap diropen grid=120x30 cursor=4,7 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 32 line 32 -| 33 line 33 big.txt plain.txt sub -| NOR /tmp/pardes-snap/ttylook/cwd/plain.txt Save Del -| 1 just text +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| NOR /tmp/pardes-snap/ttylook/cwd/sub Del +| +| +| +| +| +| | | -| NOR /tmp/pardes-snap/ttylook/cwd Del -| big.txt:20 -| ww | -| plain.txt -| big.txt:33 -| zz | | NOR /tmp/pardes-snap/ttylook/cwd Del | @@ -184,53 +215,22 @@ | | | -== style back -|0: 0-44 #969696,#2c2a3e, 45-119 d,#2c2a3e, -|1: 0-1 d,#383c54, 2-50 #969696,#2c2a3e, 51-59 d,#2c2a3e, 60-61 d,#383c54, 62-97 #969696,#2c2a3e, 98-119 d,#2c2a3e, -|2: 0-1 d,#2a2a2a, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|3: 0-1 d,#525252, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|4: 0-1 d,#383c54, 2-52 #969696,#2c2a3e, 53-59 d,#2c2a3e, 60-61 d,#525252, 62-119 d,d, -|5: 0-1 d,#525252, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|6: 0-1 d,#525252, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|7: 0-1 d,#525252, 2-6 #5a5a5a,d, 7-59 d,d, 60-61 d,#525252, 62-119 d,d, -|8: 0-1 d,#6e4fd0, 2-37 #969696,#2c2a3e, 38-59 d,#2c2a3e, 60-61 d,#525252, 62-119 d,d, -|9: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|10: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|11: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|12: 0-1 d,#525252, 2-59 #d8c8a8,#4a3a1e, 60-61 d,#525252, 62-119 d,d, -|13: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|14: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|15: 0-1 d,#2a2a2a, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|16: 0-1 d,#383c54, 2-37 #969696,#2c2a3e, 38-59 d,#2c2a3e, 60-61 d,#525252, 62-119 d,d, -|17: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|18: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|19: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|20: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|21: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|22: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|23: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|24: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|25: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|26: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|27: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|28: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -|29: 0-1 d,#525252, 2-59 d,d, 60-61 d,#525252, 62-119 d,d, -== snap insert grid=120x30 cursor=2,12 +== snap noop grid=120x30 cursor=4,7 |Kill Newcol Tutor Debug Colors NextColor Dump -| NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 32 line 32 -| 33 line 33 big.txt plain.txt sub -| NOR /tmp/pardes-snap/ttylook/cwd/plain.txt Save Del -| 1 just text +| NOR /tmp/pardes-snap/ttylook/cwd Del NOR /tmp/pardes-snap/ttylook/cwd Del +| +| big.txt plain.txt sub big.txt plain.txt sub +| +| NOR /tmp/pardes-snap/ttylook/cwd/sub Del +| +| +| +| +| +| | | -| NOR /tmp/pardes-snap/ttylook/cwd Del -| big.txt:20 -| ww | -| nnplain.txt -| big.txt:33 -| zz | | NOR /tmp/pardes-snap/ttylook/cwd Del | @@ -246,22 +246,22 @@ | | | -== snap noop grid=120x30 cursor=2,13 +== snap fileopen grid=120x30 cursor=7,2 |Kill Newcol Tutor Debug Colors NextColor Dump | NOR /tmp/pardes-snap/ttylook/cwd/big.txt Save Del NOR /tmp/pardes-snap/ttylook/cwd Del -| 32 line 32 -| 33 line 33 big.txt plain.txt sub -| NOR /tmp/pardes-snap/ttylook/cwd/plain.txt Save Del -| 1 just text +| 1 line 1 +| NOR /tmp/pardes-snap/ttylook/cwd Del big.txt plain.txt sub +| +| NOR /tmp/pardes-snap/ttylook/cwd/sub Del +| +| +| +| | | -| NOR /tmp/pardes-snap/ttylook/cwd Del | -| DONE | -| NOR /tmp/pardes-snap/ttylook/cwd/sub Del | -| big.txt plain.txt sub | | NOR /tmp/pardes-snap/ttylook/cwd Del | diff --git a/test/snapshots/ttylook.snap b/test/snapshots/ttylook.snap index 0779d3f0..f22cd0d1 100644 --- a/test/snapshots/ttylook.snap +++ b/test/snapshots/ttylook.snap @@ -1,51 +1,31 @@ -# tty n/N look-motion (normal mode only): n selects the next output row of -# the terminal whose leading file-ish word looks somewhere (file, path:NNN — -# resolved by the look machinery, prompt/echo rows blanked via the OSC 133 -# marks) and looks it; plain rows are skipped; N steps back up. Insert-mode -# n still types (run splice); with nothing lookable n is a no-op. +# tty n/N token motion (normal mode only): n/N SELECT the next/prev +# whitespace-separated token that look resolves — several per line, so the +# greet ls row hops big.txt -> plain.txt -> sub — moving the cursor to the +# token start and opening NOTHING. Return looks the selection (dir -> shell +# +ls there, file -> pane) and navigation continues in what opened. The first +# n wraps from the prompt row to the first token; insert-mode n still types; +# with nothing lookable n is a no-op. lines big.txt 40 file plain.txt just text dirmk sub start 30 120 -n 3 wait 8000 big.txt stable 700 20000 -# real shell output mixing lookable and plain rows (two short printfs so the -# echoes never wrap; echo rows are prompt-marked and invisible to the walk) -key c-b -stable 600 8000 -text printf 'zz\nbig.txt:20\nww\n' -key enter -text printf 'plain.txt\nbig.txt:33\nzz\n' -key enter -text echo DO''NE -key enter -wait 8000 DONE -stable 700 15000 -key c-b -stable 600 8000 -# from the top: n skips nothing-rows, lands on the ls row (big.txt ...) first -key g g -stable 400 5000 -key n -stable 700 15000 -snap lsrow -snapstyle lsrow -# next hits: big.txt:20 (file pane scrolls there), plain.txt, big.txt:33 +# first n: cursor sits at the shell prompt below the output — wrap lands on +# the ls row's first token, big.txt; nothing opens key n -stable 700 15000 -snap line20 -key n -stable 700 15000 -snap plain +stable 400 5000 +snap tok1 +snapstyle tok1 +# same row, next token: plain.txt key n -stable 700 15000 -snap line33 -# N walks back up to the plain.txt row +stable 400 5000 +snap tok2 +# N steps back to big.txt key N -stable 700 15000 -snap back -snapstyle back -# insert mode: n types (a run splice), it does not step +stable 400 5000 +snap tokback +# insert-mode n still types (a run splice), no stepping; undo it key i text nn key esc @@ -54,24 +34,25 @@ stable 400 5000 snap insert key u stable 400 5000 -# a shell with nothing lookable: cd into the empty subdir (the old ls row no -# longer resolves from there), print plain rows — n has nowhere to go -key a-n -stable 700 15000 -key c-b -stable 600 8000 -text cd sub -key enter -text printf 'qq\nrr\n' -key enter -text echo O''VER +# resume the walk from big.txt's start: plain.txt, then sub +key n +stable 400 5000 +key n +stable 400 5000 +snap tok3 +# Return looks the selected dir: a shell opens below in sub and ls's it key enter -wait 8000 OVER stable 700 15000 -key c-b -stable 600 8000 -key g g -stable 400 5000 +snap diropen +# the fresh pane's dir is empty: n has nothing lookable, stays put key n stable 400 5000 snap noop +# back in the first pane, Enter with the cursor ON a token looks it (no +# selection: the cursor word expands) — big.txt opens as a file pane +press left 4 4 +release left 4 4 +stable 400 5000 +key enter +stable 700 15000 +snap fileopen |
