From e793644c7192a96ae2e39e072708b059edafaeeb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 01:30:32 -0300 Subject: jj, ansi, colors: the Changes layer and a terminal's diff draw their added and deleted rows, lanes and churn from the chrome (the themes programme's L2c; DESIGN.md R10, B6), worked out once a theme change by Chrome.of and read by `p.chrome()`, never derived again a frame, a row or a ghost line: a line a change added whole and a ghost line it added on `add.row`, a line taken away whole and a line going on `del.row`, its text in `line_number`, the words that went on `del.emph` and the words that came on `add.emph`, a description's id in the keyword's syntax ink where one change is pinned; one change pinned, its lane in the diff's own markers, `add.ink` beside a row it wrote and `del.ink` beside one it took away (the user's rulings of 2026-11-23); several, `lanes` (the sixteen's accents and the number and keyword hues, written and taken away left out, hue-sorted, R10); churn on `heat`'s eight steps from the line numbers' ink to the deleted hue, the step a count's log share of the hottest; a finished command pane's diff (ansi.recolorDiffOutput) on `add.row`/`del.row`, its markers `add.ink`/`del.ink`, its words the page's text; DELETED: jj.laneInks, laneColours and their HSV helpers (hue, hueApart, chroma, hue_apart), themeRed and its literal #cf222e and #2ea043 (the second copies of Grounds' fallbacks), heatColour's OKLab mix a row, the six Grounds.of a frame (one per ghost row, mark and going line); THE CAUSE where one moved: the old reds and greens were the palette's or two literals, so `dark` and every theme without a palette drew GitHub's red and green on rows mixed from the tag (the page's stand-in), the lane inks were pushed toward the text by 40 % steps to 3:1 on that page, and the markers on the patch view and the lanes disagreed (C1's surfaces.md §3.7); and a theme whose accents are all grey would divide by a lane count of 0 (colors: `lanes` now never empty: a theme with no accent draws its lanes in the line numbers' grey); the ring's `diff` check at B4's floor, 1.15:1 (was 1.1), unless the theme's text holds the row nearer (R10: never under its floor on the row: tokyonight_day's #3760bf on #e1e2e7, 4.9:1, leaves 1.11:1), and 0.05 apart; RUN (TEST FIRST): jj.zig's lane tests re-pinned to the chrome ("Changes draws a lane ...", "Changes draws what the text has not ...", "from the middle ...", "Churn counts ...", "Compare pins ...": the lanes `lanes[pin]`, a whole line's ground `add.row`, a going line's `del.row`, the ghost text `line_number`, the id `syntax[keyword]`, one change's lane `add.ink`/`del.ink`, churn's hottest `heat[7]` and 3-of-4's `heat[6]`), and "a diff's two lane inks in every theme" now asks every theme's markers apart and 4.5:1 on their row and words (as near as the theme reaches): on the base the four drawing tests fail (the old inks) and the ring fails tokyonight_day at 1.15, all pass now; diffview.golden re-recorded: rows 18-20 and 23-25 (the command pane's `cat change.diff`: its deleted row #302b25 -> #331a12, its added rows #263025 -> #132503: R10's rows 1.15:1 off orchard's page in the hue, where Grounds mixed the page 18 % toward the palette's colour; the markers #f1a39b and #b6ce94 unchanged, orchard's own red and green already 4.5:1 there), the diff pane's own rows (File.zig, L2b's) and diffstack.golden unchanged; GATES: core-test 1123/1296 (173 skipped; the base's count), process-test `diff` 2/2 after the update; load 3.5 to 6.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/ansi.zig | 8 +- core/colors.zig | 14 ++- core/jj.zig | 194 ++++++++++++----------------------------- test/snapshots/diffview.golden | 12 +-- 4 files changed, 79 insertions(+), 149 deletions(-) diff --git a/core/ansi.zig b/core/ansi.zig index e4fbf5da..3772de43 100644 --- a/core/ansi.zig +++ b/core/ansi.zig @@ -453,15 +453,15 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t } if (lo > hi) return; const styles = syntax.highlightDiffRows(arena, flat, lo, hi, true) catch return; - const tints: Colors.Grounds = .of(p.theme()); - const ink = p.theme().fg orelse p.theme().tag_fg; + const chrome = p.chrome(); const body_y = p.bodyTop(pane, r); shown = std.mem.splitScalar(u8, body, '\n'); for (views, 0..) |maybe, vr| { const line = shown.next() orelse break; const view = maybe orelse continue; const base = @intFromPtr(rows[view.row].ptr) - flat_start - lo; - const tint = if (base < styles.len) tints.forStyle(styles[base]) else null; + const lead: u8 = if (base < styles.len) styles[base] else 0; + const tint: ?Colors.Chrome.Diff = if (lead & syntax.ground_add != 0) chrome.add else if (lead & syntax.ground_del != 0) chrome.del else null; if (tint) |t| s.tint(tx, body_y + @as(u16, @intCast(vr)), tw, t.row, null); var c: usize = 0; var screen_c: usize = 0; @@ -478,7 +478,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t else if (panes.File.synStyle(p, @fromBackingInt(@intCast(style & syntax.syn_bits)))) |ss| ss else if (tint != null) - .{ .fg = ink, .bold = false } + .{ .fg = chrome.page.text, .bold = false } else null; if (paint) |ss| { diff --git a/core/colors.zig b/core/colors.zig index eefb2b67..4e4bd9ba 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -791,6 +791,11 @@ pub const Chrome = struct { // R10: the lanes (the accents but green and red, hue-sorted) and // churn's steps from the line numbers' ink to the deleted hue. c.lanes_len = lanesOf(.{ ansi[3], ansi[4], ansi[5], ansi[6], th.number, th.keyword }, .{ th.deleted orelse ansi[1], th.added orelse ansi[2] }, &c.lanes); + // A theme with no accent (a grey one) draws its lanes in one grey. + if (c.lanes_len == 0) { + c.lanes[0] = c.line_number; + c.lanes_len = 1; + } for (&c.heat, 1..) |*h, k| h.* = mixOklab(c.line_number, th.deleted orelse ansi[1], @as(f32, @floatFromInt(k)) / 8); return c; } @@ -2602,7 +2607,14 @@ fn ringFailures(th: *const Theme, c: *const Chrome) std.EnumSet(RingCheck) { f.setPresent(.severities4, apart4 < Chrome.severity_apart); const err = lch(c.page.severity[0]); f.setPresent(.error_red, !(err[1] >= 0.08 and (err[2] <= 50 or err[2] >= 330))); - f.setPresent(.diff, @min(contrast(c.add.row, page), contrast(c.del.row, page)) < 1.1 or de(c.add.row, c.del.row) < 0.05); + // R10: each diff row 1.15:1 off the page, unless the text holds it + // nearer (never under its floor there: tokyonight_day's text, 4.9:1, + // leaves 1.11:1), and the two 0.05 apart. + const diff_floor = @min(4.5, text * 0.9); + for ([2][3]u8{ c.add.row, c.del.row }) |row| { + if (contrast(row, page) < Chrome.row_step - 0.005 and contrast(ink, row) > diff_floor + 0.05) f.insert(.diff); + } + if (de(c.add.row, c.del.row) < 0.05) f.insert(.diff); var ansi_least: f32 = 21; for (c.ansi[1..], 1..) |a, i| { ansi_least = @min(ansi_least, contrast(a, page)); diff --git a/core/jj.zig b/core/jj.zig index 63488b8c..e9b8edd1 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -1942,9 +1942,9 @@ fn ghostLanes(ch: *const Changes, ghosts: []const Ghost, gi: usize, first_row: b /// a changed line's old text grey, the words that went red; a /// description's id and title in its lane's colour `lane`, or with one /// change pinned (no one colour a lane) its id in the theme's keyword ink, -/// its author and age grey. +/// its author and age grey. All of them the chrome's (Chrome.add, .del). fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i32, from: usize, to: usize, pad: i32, marks: []const [2]u32, lane: ?[3]u8, x: u16, y: u16, w: u16) void { - const th = p.theme(); + const chrome = p.chrome(); const tab = p.settings.tab; const said = File.sourceLine(pane, row); const Ink = struct { @@ -1975,13 +1975,13 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i3 const ink: Ink = .{ .q = p, .s = s, .pane = pane, .row = row, .from = from, .to = to, .pad = pad, .x = x, .y = y, .w = w }; _ = tab; switch (g.kind) { - .deleted => s.tint(x, y, w, pardes.colors.Grounds.of(th).del.row, th.lineno), - .added => s.tint(x, y, w, pardes.colors.Grounds.of(th).add.row, null), + .deleted => s.tint(x, y, w, chrome.del.row, chrome.line_number), + .added => s.tint(x, y, w, chrome.add.row, null), .changed => { - ink.fg(0, said.len, th.lineno); + ink.fg(0, said.len, chrome.line_number); for (marks[g.marks..][0..g.nmarks]) |m| { const c = ink.cells(m[0], m[1]); - if (c[0] < c[1]) s.tint(x + c[0], y, c[1] - c[0], pardes.colors.Grounds.of(th).del.emph, null); + if (c[0] < c[1]) s.tint(x + c[0], y, c[1] - c[0], chrome.del.emph, null); } }, .description => { @@ -1989,8 +1989,8 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, pane: *const Pane, g: Ghost, row: i3 // title) in the lane's colour, the author and the age grey. const id_end = std.mem.indexOfScalar(u8, said, ' ') orelse said.len; const author = @min(g.author, said.len); - ink.fg(0, if (lane != null) author else id_end, lane orelse th.kw); - ink.fg(author, said.len, th.lineno); + ink.fg(0, if (lane != null) author else id_end, lane orelse chrome.syntax[@intFromEnum(syntax.Syn.keyword)]); + ink.fg(author, said.len, chrome.line_number); }, } } @@ -2010,7 +2010,7 @@ fn inkCame(p: *Pardes, s: *pardes.Surface, pane: *Pane, marks: []const [2]u32, r if (lo >= hi) continue; const from = here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(lo)); const to = @min(@as(i32, w), here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(hi))); - if (from >= 0 and from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), pardes.colors.Grounds.of(p.theme()).add.emph, null); + if (from >= 0 and from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), p.chrome().add.emph, null); } } @@ -2245,82 +2245,6 @@ fn nest(lines: []Line, npins: usize) void { } } -/// A diff's two inks (one change pinned, `paintLanes`): its lane's colour -/// says the kind of the row it stands beside (the user's rulings of -/// 2026-11-23), `added` beside a row it wrote (a line added whole, a changed -/// line's new text), `taken` beside a row it took away (a line taken away, a -/// changed line's old text). -pub const Inks = struct { added: [3]u8, taken: [3]u8 }; - -/// The diff's own two colours: the theme's green and its red (the grounds' -/// and the changed words' hues), each pushed toward the ink until it reads -/// 3:1 on the page (or nearly as the ink does, where the ink reads less). -pub fn laneInks(th: *const pardes.LegacyTheme) Inks { - var inks: [2][3]u8 = .{ if (th.palette) |c| c[2] else .{ 0x2e, 0xa0, 0x43 }, themeRed(th) }; - const page = th.bg orelse th.tag_bg; - for (&inks) |*ink| { - var step: usize = 0; - while (step < 8 and pardes.colors.contrast(ink.*, page) < 3) : (step += 1) ink.* = pardes.colors.mixOklab(ink.*, th.fg orelse th.tag_fg, 0.4); - } - return .{ .added = inks[0], .taken = inks[1] }; -} - -/// The lanes' colours, a pin's the `pin % len`th, oldest first: the -/// theme's accents but the two that mean written and taken away (its green -/// and red), in hue order from the top, each a hue `hue_apart` or more from -/// the one kept before it (doom one: magenta, blue, yellow; cyan and -/// orange go). Distinct colours, never one between two. -pub fn laneColours(th: *const pardes.LegacyTheme, buf: *[8][3]u8) []const [3]u8 { - const pal = th.palette; - const grounds = [2][3]u8{ themeRed(th), if (pal) |c| c[2] else .{ 0x2e, 0xa0, 0x43 } }; - const accents: [6][3]u8 = if (pal) |c| .{ c[3], c[4], c[5], c[6], th.num, th.kw } else .{ th.kw, th.num, th.str, th.box, th.column_box orelse th.box, th.comment }; - var sorted: [6][3]u8 = undefined; - var n: usize = 0; - for (accents) |c| { - // A grey is no accent; one near written or taken away means that. - if (chroma(c) < 48 or hueApart(c, grounds[0]) < hue_apart or hueApart(c, grounds[1]) < hue_apart) continue; - sorted[n] = c; - n += 1; - } - std.sort.insertion([3]u8, sorted[0..n], {}, struct { - fn above(_: void, a: [3]u8, b: [3]u8) bool { - return hue(a) > hue(b); - } - }.above); - var kept: usize = 0; - for (sorted[0..n]) |c| { - if (kept > 0 and hueApart(c, buf[kept - 1]) < hue_apart) continue; - buf[kept] = c; - kept += 1; - } - return buf[0..kept]; -} - -/// Two hues closer than this are one colour to a lane (doom one's cyan is -/// 12 degrees from its blue, its orange 11 from its yellow). -const hue_apart = 15; - -fn chroma(c: [3]u8) u8 { - return @max(c[0], c[1], c[2]) - @min(c[0], c[1], c[2]); -} - -/// HSV's hue, in degrees. -fn hue(c: [3]u8) f32 { - const r: f32 = @floatFromInt(c[0]); - const g: f32 = @floatFromInt(c[1]); - const b: f32 = @floatFromInt(c[2]); - const hi = @max(r, g, b); - const d = hi - @min(r, g, b); - if (d == 0) return 0; - const h = if (hi == r) @mod((g - b) / d, 6) else if (hi == g) (b - r) / d + 2 else (r - g) / d + 4; - return 60 * h; -} - -fn hueApart(a: [3]u8, b: [3]u8) f32 { - const d = @abs(hue(a) - hue(b)); - return @min(d, 360 - d); -} - /// The pane's pinned changes as a view shows them, on its body's rows (body_layer.zig, while /// File.Layers.lanes is set): in the gutter's lane cells after the number a /// lane each pin whose block runs down the row, at its level, a glyph in a @@ -2333,18 +2257,13 @@ pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1 if (pane.layers.lanes > 0) paintLanes(p, s, pane, r, tx, tw, body_h); } -/// The theme's red: what a change took away; churn's top. -pub fn themeRed(th: *const pardes.LegacyTheme) [3]u8 { - return if (th.palette) |c| c[1] else .{ 0xcf, 0x22, 0x2e }; -} - -/// A count's colour on churn's gradient: smooth from the line numbers' -/// grey to the theme's red, on a log scale of the count against the -/// hottest; null for none. -fn heatColour(th: *const pardes.LegacyTheme, count: u16, hottest: u16) ?[3]u8 { +/// A count's colour on churn's eight steps from the line numbers' grey to +/// the deleted hue (Chrome.heat, worked out with the theme), on a log scale +/// of the count against the hottest; null for none. +fn heatColour(c: *const pardes.colors.Chrome, count: u16, hottest: u16) ?[3]u8 { if (count == 0 or hottest == 0) return null; const t = @log(@as(f32, @floatFromInt(count)) + 1) / @log(@as(f32, @floatFromInt(hottest)) + 1); - return pardes.colors.mixOklab(th.lineno, themeRed(th), t); + return c.heat[@min(c.heat.len, @as(usize, @intFromFloat(@ceil(t * c.heat.len)))) -| 1]; } /// The heat lane: a cell after the line number (before the changes' @@ -2362,7 +2281,7 @@ fn paintHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1 if (row < 0 or File.readOnlyRow(f, @intCast(row)) != null) continue; const line = File.fileRow(f, @intCast(row)); if (line >= heat.lines.len) continue; - const rgb = heatColour(p.theme(), heat.lines[line], heat.hottest) orelse continue; + const rgb = heatColour(p.chrome(), heat.lines[line], heat.hottest) orelse continue; var style = s.at(x, body_y + vr).style; style.fg = .{ .rgb = rgb }; s.set(x, body_y + vr, "\u{258c}", style); @@ -2380,7 +2299,7 @@ pub fn railHeat(p: *Pardes, s: *pardes.Surface, pane: *Pane, id: usize, rail: pa for (0..rail.h) |row| { const lo = row * total / rail.h; const hi = @max(lo + 1, (row + 1) * total / rail.h); - const rgb = heatColour(p.theme(), std.mem.max(u16, heat.lines[lo..@min(hi, total)]), heat.hottest) orelse continue; + const rgb = heatColour(p.chrome(), std.mem.max(u16, heat.lines[lo..@min(hi, total)]), heat.hottest) orelse continue; if (p.view().frontend.windowed) s.heat.append(p.gpa, .{ .owner = @intCast(id), .row = @intCast(row), .rgb = rgb }) catch {} else @@ -2393,18 +2312,18 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const ch = answered(p, f.layer.owner) orelse return; if (ch.lines.len == 0) return; const tab = p.settings.tab; - var buf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &buf); - if (colours.len == 0) return; - // One change pinned is a diff: its lane in the diff's own two colours, - // by the row's kind; several, a colour a change, to tell them apart. - const one: ?Inks = if (ch.pins.len == 1) laneInks(p.theme()) else null; + const chrome = p.chrome(); + const colours = chrome.lanes[0..chrome.lanes_len]; + // One change pinned is a diff: its lane in the diff's own two markers + // (the user's rulings of 2026-11-23: added beside a row it wrote, deleted + // beside one it took away); several, a colour a change, to tell them + // apart. + const one = ch.pins.len == 1; const gutter = File.gutterWidth(pane); const cells = File.laneCells(pane); if (gutter >= tw or cells == 0) return; const first = tx + gutter - cells; const windowed = p.view().frontend.windowed; - const ground = pardes.colors.Grounds.of(p.theme()).add.row; const body_y = p.bodyTop(pane, r); const nrows = File.lineCount(f.content); var vr: u16 = pane.context_rows; @@ -2424,7 +2343,7 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const next = pane.wrapAt(tab, @as(i32, vr) + 1); const to: usize = if (next.line == w.line) @intCast(next.at) else File.sourceLine(pane, w.line).len; const first_row = w.at <= 0; - inkGhost(p, s, pane, g, w.line, @intCast(@max(0, w.at)), to, w.pad, ch.marks, if (one == null) colours[g.pin % colours.len] else null, tx + gutter, y, tw - gutter); + inkGhost(p, s, pane, g, w.line, @intCast(@max(0, w.at)), to, w.pad, ch.marks, if (one) null else colours[g.pin % colours.len], tx + gutter, y, tw - gutter); if (g.kind == .description and first_row) points = @enumFromInt(g.pin); taken = g.kind == .deleted or g.kind == .changed or (g.kind == .description and takenAbove(ch.ghosts, gi)); break :ghost ghostLanes(ch, ch.ghosts, gi, first_row); @@ -2432,9 +2351,9 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u const at = File.fileRow(f, row); if (at >= ch.lines.len) continue; const line = ch.lines[at]; - if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, ground, null); + if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, chrome.add.row, null); // Going: a pin ahead takes it away. - if (line.going != .none) s.tint(tx + gutter, y, tw - gutter, pardes.colors.Grounds.of(p.theme()).del.row, null); + if (line.going != .none) s.tint(tx + gutter, y, tw - gutter, chrome.del.row, null); taken = line.going != .none; if (!line.whole and line.nmarks > 0) inkCame(p, s, pane, ch.marks[line.marks..][0..line.nmarks], w.line, vr, tx + gutter, y, tw - gutter); break :line line.lanes; @@ -2442,7 +2361,7 @@ fn paintLanes(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u for (lanes, 0..) |lane, level| { if (lane == .none) break; const arrow = lane == points; - const rgb = if (one) |d| (if (taken) d.taken else d.added) else colours[@intFromEnum(lane) % colours.len]; + const rgb = if (one) (if (taken) chrome.del.ink else chrome.add.ink) else colours[@intFromEnum(lane) % colours.len]; if (windowed) { // A body a pixel shell draws as a layer is painted on a // temporary surface first: its lanes are not drawn yet. @@ -2877,10 +2796,10 @@ test "Changes draws a lane a pinned change after the line number, nested ones a const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + before; - var buf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &buf); + const c = p.chrome(); + const colours = c.lanes[0..c.lanes_len]; try testing.expect(colours.len >= 3); - const ground = pardes.colors.Grounds.of(p.theme()).add.row; + const ground = c.add.row; // Lines 1-10, each on the row the view draws it at (ghost rows // stand between): `fn`'s spine on all; `mid` on 3-6; `shift` on 4. const want = [_][]const u8{ "0", "0", "01", "012", "01", "01", "0", "0", "0", "0" }; @@ -2917,16 +2836,15 @@ test "Changes draws a lane a pinned change after the line number, nested ones a } } -test "a diff's two lane inks in every theme: its green and its red, never one colour, each read on the page" { - for (&pardes.colors.legacy_themes) |*th| { - const inks = laneInks(th); - errdefer std.debug.print("{s}: added {any} taken {any}\n", .{ th.name, inks.added, inks.taken }); - try testing.expect(!std.meta.eql(inks.added, inks.taken)); - const page = th.bg orelse th.tag_bg; - // 3:1, or as near the theme's own ink's as it reads (hex_poison's). - const floor = @min(3, pardes.colors.contrast(th.fg orelse th.tag_fg, page)) - 0.1; - try testing.expect(pardes.colors.contrast(inks.added, page) >= floor); - try testing.expect(pardes.colors.contrast(inks.taken, page) >= floor); +test "a diff's two lane inks in every theme are its added and deleted markers (DESIGN.md R10): never one colour, each 4.5:1 on its rows, as near as the theme reaches" { + for (&pardes.colors.themes) |*th| { + const c: pardes.colors.Chrome = .of(th); + errdefer std.debug.print("{s}: added {any} deleted {any}\n", .{ th.name, c.add, c.del }); + try testing.expect(!std.meta.eql(c.add.ink, c.del.ink)); + for ([2]pardes.colors.Chrome.Diff{ c.add, c.del }) |d| for ([2][3]u8{ d.row, d.emph }) |ground| { + const reach = @max(pardes.colors.contrast(@splat(255), ground), pardes.colors.contrast(@splat(0), ground)); + try testing.expect(pardes.colors.contrast(d.ink, ground) >= @min(4.5, reach) - 0.01); + }; } } @@ -3003,9 +2921,8 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + File.gutterWidth(pane) - File.laneCells(pane); - var cbuf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &cbuf); - const grounds = pardes.colors.Grounds.of(p.theme()); + const grounds = p.chrome(); + const colours = grounds.lanes[0..grounds.lanes_len]; const lanes = [_][]const u8{ "0", "0", "02", "02", "02", "02", "01", "01", "01", "0", "0", "0" }; const Ground = enum { none, add, del }; const ground = [_]Ground{ .add, .add, .none, .none, .add, .none, .del, .del, .none, .add, .add, .none }; @@ -3048,7 +2965,7 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line try testing.expectEqual(pardes.Color{ .rgb = colours[pin] }, s.at(body.x + File.gutterWidth(pane), body.y + row).style.fg); try testing.expectEqual(pardes.Color{ .rgb = colours[pin] }, s.at(body.x + File.gutterWidth(pane) + 5, body.y + row).style.fg); } - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(body.x + File.gutterWidth(pane) + 4, body.y + 6).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = grounds.line_number }, s.at(body.x + File.gutterWidth(pane) + 4, body.y + 6).style.fg); // The changed line: on its old text the word that went (`b`) red, // on it the word that came (`b2`) green; the rest of each neither. const text_x = body.x + File.gutterWidth(pane); @@ -3071,10 +2988,9 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line const s1 = try p.render(arena.allocator()); const top = s1.region(.body, id).?.rect.y; const at = body.x + File.gutterWidth(pane) - File.laneCells(pane); - const inks = laneInks(p.theme()); - try testing.expect(!std.meta.eql(inks.added, inks.taken)); + try testing.expect(!std.meta.eql(grounds.add.ink, grounds.del.ink)); for ([_]u16{ 2, 3, 4, 5 }, [_]bool{ true, false, false, false }) |row, red| { - const ink = if (red) inks.taken else inks.added; + const ink = if (red) grounds.del.ink else grounds.add.ink; if (windowed) { var n: usize = 0; for (s1.lanes.items) |lane| if (lane.y == top + row) { @@ -3084,8 +3000,9 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line try testing.expectEqual(@as(usize, 1), n); } else try testing.expectEqual(pardes.Color{ .rgb = ink }, s1.at(at, top + row).style.fg); } - try testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, s1.at(text_x, top + 5).style.fg); - try testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.theme().kw }, s1.at(text_x + 5, top + 5).style.fg)); + const keyword = grounds.syntax[@intFromEnum(syntax.Syn.keyword)]; + try testing.expectEqual(pardes.Color{ .rgb = keyword }, s1.at(text_x, top + 5).style.fg); + try testing.expect(!std.meta.eql(pardes.Color{ .rgb = keyword }, s1.at(text_x + 5, top + 5).style.fg)); } } @@ -3299,12 +3216,12 @@ test "a description is whole, its title and its author never cut: in a pane narr const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, s.at(x, body.y + 3).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().syntax[@intFromEnum(syntax.Syn.keyword)] }, s.at(x, body.y + 3).style.fg); const last: u16 = body.y + 3 + @as(u16, @intCast(n - 1)); const end = x + @as(u16, @intCast(File.displayWidth(p.settings.tab, Ghosts.text(pane, got[3 + n - 1])))) - 1; try testing.expectEqualStrings("w", s.at(end, last).grapheme()); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(end, last).style.fg); - try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(end - 4, last).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().line_number }, s.at(end, last).style.fg); + try testing.expectEqual(pardes.Color{ .rgb = p.chrome().line_number }, s.at(end - 4, last).style.fg); const first = x - File.laneCells(pane); for (0..n) |k| { const y = body.y + 3 + @as(u16, @intCast(k)); @@ -4068,7 +3985,7 @@ test "from the middle: in a revision's pane a pin behind it shows the lines it t const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane) + 1; - const grounds = pardes.colors.Grounds.of(p.theme()); + const grounds = p.chrome(); for ([_]u16{ 1, 8 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, s.at(x, body.y + row).style.bg); for ([_]u16{ 7, 11 }) |row| try testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, s.at(x, body.y + row).style.bg); } @@ -4255,8 +4172,10 @@ test "Churn counts the changes that touched each declaration and draws them afte const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const x = body.x + File.gutterWidth(pane) - 1; - const red = themeRed(p.theme()); - const warm = pardes.colors.mixOklab(p.theme().lineno, red, @log(3.0) / @log(4.0)); + // Churn's steps (Chrome.heat): the hottest the last, f's 3 of 4's + // log, the seventh. + const red = p.chrome().heat[7]; + const warm = p.chrome().heat[6]; for (0..7) |row| { const cell = s.at(x, body.y + @as(u16, @intCast(row))); if (row == 3) { @@ -4465,8 +4384,7 @@ test "Compare pins the whole difference between each two points as one change: t const s = try p.render(arena.allocator()); const body = s.region(.body, id).?.rect; const first = body.x + File.gutterWidth(pane) - File.laneCells(pane); - var cbuf: [8][3]u8 = undefined; - const colours = laneColours(p.theme(), &cbuf); + const colours = p.chrome().lanes[0..p.chrome().lanes_len]; for ([_]u16{ 3, 7, 8 }, [_]usize{ 0, 1, 1 }) |row, pin| { if (windowed) { var n: usize = 0; diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden index 3a83fb25..c441e19c 100644 --- a/test/snapshots/diffview.golden +++ b/test/snapshots/diffview.golden @@ -136,14 +136,14 @@ |15: 0-0 d,#608269, 1-99 d,#0d1410, |16: 0-1 d,#496656, 2-99 #b2c3b8,#1d2824, |17: 0-0 d,#152019, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, -|18: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #f1a39b,#302b25,b 3-6 #f1a39b,#302b25, 7-19 #e5eee5,#302b25, 20-20 #f8c082,#302b25, 21-99 #e5eee5,#302b25, -|19: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-6 #b6ce94,#263025, 7-99 #e5eee5,#263025, -|20: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-6 #b6ce94,#263025, 7-16 #e5eee5,#263025, 17-23 #c9a7ed,#263025, 24-99 #e5eee5,#263025, +|18: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #f1a39b,#331a12,b 3-6 #f1a39b,#331a12, 7-19 #e5eee5,#331a12, 20-20 #f8c082,#331a12, 21-99 #e5eee5,#331a12, +|19: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#132503,b 3-6 #b6ce94,#132503, 7-99 #e5eee5,#132503, +|20: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#132503,b 3-6 #b6ce94,#132503, 7-16 #e5eee5,#132503, 17-23 #c9a7ed,#132503, 24-99 #e5eee5,#132503, |21: 0-0 d,#152019, 1-99 d,#0d1410, |22: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, -|23: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#302b25,b 3-10 #f1a39b,#302b25, 11-99 #b8d88a,#302b25, -|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-10 #b6ce94,#263025, 11-99 #b8d88a,#263025, -|25: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-10 #b6ce94,#263025, 11-99 #b8d88a,#263025, +|23: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#331a12,b 3-10 #f1a39b,#331a12, 11-99 #b8d88a,#331a12, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#132503,b 3-10 #b6ce94,#132503, 11-99 #b8d88a,#132503, +|25: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#132503,b 3-10 #b6ce94,#132503, 11-99 #b8d88a,#132503, |26: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, |27: 0-0 d,#608269, 1-2 d,#0d1410, 3-99 #e5eee5,#0d1410, |28: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -- cgit v1.3 From 3ace8b385e02a54830decb6aa48d1fa28d076a18 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 00:04:32 -0300 Subject: Trail, Pick, Prompt, Jump: Ctrl-o pops the walk one word at a time (UX DESIGN L'1, binding; the user: "I did spc f f then did /something but I didn't know how to get back to the previous one", "the pickers are kinda shown as a stack right? I felt like I could pop the current one"): the trail's words, left to right, are the stack, and Ctrl-o steps one word left of where the pane is, Ctrl-i one right; onto a place as before (Trail.go); onto a list's word, that kept picker unrolls again in this pane's tag as it was left (query, cursor, marks), previewing here (Pick.reopen with `walking`, its step): Esc gives rest exactly as before the Ctrl-o, Enter lands as that word's (a step from it, the steps after it dropped, its word saying where it is now), Ctrl-o, Ctrl-i and Backspace on its empty field (after its refinements) roll it up unlanded and walk on (Pick.walkOn; past the last word the jump list's step alone, Jump.listBy); Ctrl-i in it is Tab, a mark, where the terminal cannot tell them apart; onto a search's word, the caret back where the search started and its places lit (Prompt.light, Look's without the select): `Step.search` is a `Search` that holds its start, path, line and column, recorded as `/` commits (Prompt.word from Places.origin) and by `*`; the pane is then at that word (`cur` on it: Trail.backs writes it before the path, n and N walk it, keep keeps it, a step from it keeps it, go and replaceStep never write a place over it); a held pane walks its own words, a search's and a recipe's; a list no longer kept is said (`walk: that list is gone: the last 8 are kept`) and passed by; the owner is no word to walk; Jumps new-pane walks nothing, as before; D8's fold takes places only: each run of places older than the newest `whole` back steps (or past the first two forward) is one `+N` where it starts, a list's word folds only where the tag keeps its newest step alone and never the newest list's, a search's or a recipe's never (Trail.folds; draw.zig dims every run's `+N`); after a landing (Pick.listed) and a search's Enter (Prompt.land) the notice row says, as an echo never logged, what the next Ctrl-o reaches, `C-o back to Find words 1/1` (Trail.sayBack); THE CAUSE of the user's trouble (UX L1): Trail.walkBy skipped every word but a place (`if (t.steps[i] != .place) continue;`), so Ctrl-o after the search went to main.zig:1, past both the search and the list, and nothing said which key would pop; RUN (TEST FIRST): Jump.zig "Ctrl-o pops the walk one word at a time (UX L'1) ..." (W2's test extended) types the user's keys in an 84x20 session of main.zig (SPC f f words, Enter, /in_word, Enter, then Ctrl-o x3 and Ctrl-i x3) and asks after each key the file, the trail's four steps and where the pane is among them, the caret's line, Find words unrolled or not and the search lit or not, then Esc from a reopened list (as before the Ctrl-o), its Enter (the search's word and the place after it dropped, `Find words 1/1` kept) and Backspace on its empty field (walks on to main.zig): fails on the base at Jump.zig:565 on the first Ctrl-o (expected words.zig, found main.zig), passes now; Trail.zig "the fold takes places alone (UX L'1) ..." (runs of places each a `+N`, a click on each its newest, two lists with the newest step alone, a search's word never) and "a held pane walks its own words (UX L'1) ..." (Ctrl-o puts the caret at 20:3 where `/line 9` began, its places lit; past it the jump list's); the notice-row test of walk UI G 2e now reads the echo, then the caret's place once it is retired; a user hit it on every Ctrl-o after a picker's Enter or a search; goldens re-recorded: find and fsearch (the notice row after a picker's Enter and a search's Enter reads the echo); ttyhelp is the merge's placeholder (M1 re-records it); the perf cell walk-pop (test/perf.zig, run only when named: Ctrl-o onto a list word reopening it in the key's own frame, then Esc), 326 us a pair on small in ReleaseFast; core-test 1124/1298 (173 skipped; the G 2e notice-row test, failing on the echo, updated and passing alone), shell-test 1346/1349 (3 skipped), behaviour-test 280/280, pane-test 183/184, process-test 3 of 147 failed before the two goldens moved (find, fsearch: the echo; ttyhelp the placeholder); load 2.2 to 7.2 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Jump.zig | 95 ++++++++++++-- core/Pick.zig | 59 ++++++++- core/Prompt.zig | 47 +++++-- core/Trail.zig | 295 ++++++++++++++++++++++++++++++++++-------- core/draw.zig | 8 +- test/perf.zig | 28 +++- test/snapshots/find.golden | 2 +- test/snapshots/fsearch.golden | 2 +- 8 files changed, 439 insertions(+), 97 deletions(-) diff --git a/core/Jump.zig b/core/Jump.zig index 3d69d6c9..3632a039 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -274,11 +274,17 @@ pub fn trackJump(p: *Pardes) void { /// always have, at the newest entry. pub fn jumpBy(p: *Pardes, delta: i32) void { const v = p.view(); - // A reading pane's walk first (pick-ui SPEC §6.4). Past its newest + // A pane's walk first (pick-ui SPEC §6.4, UX L'1). Past its newest // step, Ctrl-i steps the Walk queue a picker left (Pick.stepQueue); // then the jump list's. if (pardes.Trail.walkBy(p, v.active, delta)) return; if (delta > 0 and pardes.Pick.stepQueue(p, v.active)) return; + listBy(p, delta); +} + +/// The jump list's step alone (`jumpBy`): past a walk's last word. +pub fn listBy(p: *Pardes, delta: i32) void { + const v = p.view(); const older = delta < 0; // At an end of the list: said, not a step that silently does nothing. if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n)) @@ -338,7 +344,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { v.jumps.cur = @min(cur, w -| 1); // The same step again, over the list without them: each // round takes one file's entries away, so it ends. - return jumpBy(p, delta); + return listBy(p, delta); } const e = found.?; const from = v.active; @@ -461,7 +467,7 @@ test "jump history terminal rectangle follows output and clears on reflow" { try std.testing.expectEqual(.none, pane.sel[0].state); } -test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC f f words, Enter, /in_word, Enter, Ctrl-o goes to the first place, a second Ctrl-o leaves the list's and the search's words where they are, and Ctrl-i goes forward again" { +test "Ctrl-o pops the walk one word at a time (UX L'1): after SPC f f words, Enter, /in_word, Enter, Ctrl-o puts the caret where the search started with its places lit, then reopens Find words as it was left, previewing here, then goes to the place before it; Ctrl-i comes back the same way; Esc leaves a reopened list as before the Ctrl-o; its Enter lands as its word's, the steps after it dropped" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 84, .rows = 20 }); defer p.deinit(); var tmp = std.testing.tmpDir(.{}); @@ -485,6 +491,12 @@ test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); } }.f; + const echo = struct { + fn f(pp: *Pardes) []const u8 { + const said = pp.messages.headline() orelse return ""; + return said.words(); + } + }.f; typeKeys(p, " ffwords"); var n: usize = 0; while (n < 50 and (pardes.Pick.busy(p) or p.stream.busyFor(pardes.Pick.live(p).?.id))) : (n += 1) { @@ -493,25 +505,80 @@ test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC } p.update(.{ .key = .{ .cp = pardes.Key.enter } }); p.sync(); + try std.testing.expectEqualStrings("C-o back to Find words 1/1", echo(p)); typeKeys(p, "/in_word"); p.update(.{ .key = .{ .cp = pardes.Key.enter } }); p.sync(); + try std.testing.expect(std.mem.startsWith(u8, echo(p), "C-o back to /in_word/ ")); + { + // The search word holds where the search started: the landing. + const t = &p.panes[p.view().active].?.trail; + try std.testing.expect(t.n == 4 and t.cur == 3 and t.steps[2] == .search); + const from = t.steps[2].search.from; + try std.testing.expectEqualStrings("words.zig", std.Io.Dir.path.basename(from.path.slice())); + try std.testing.expect(from.line == 1 and from.col == 1); + } const back: pardes.Key = .{ .cp = 'o', .ctrl = true }; const ahead: pardes.Key = .{ .cp = 'i', .ctrl = true }; - const Want = struct { file: []const u8, cur: u8 }; + // After each key: the file the pane shows, where it is in its trail, + // the caret's line, Find words unrolled or not, the search lit or not. + const Want = struct { file: []const u8, cur: u8, line: i32, picker: bool, lit: bool }; + const Check = struct { + fn f(pp: *Pardes, want: Want) !void { + const live = pardes.Pick.live(pp); + try std.testing.expectEqual(want.picker, live != null); + const id = if (live) |pk| pp.paneBySerial(pk.landing).? else pp.view().active; + const pane = pp.panes[id].?; + const t = &pane.trail; + if (live != null) try std.testing.expectEqualStrings("words", pp.view().tag_state.field.text()) else try std.testing.expectEqualStrings(want.file, std.Io.Dir.path.basename(pane.file.?.path)); + if (live) |pk| try std.testing.expectEqual(pardes.Pick.Source.find, pk.source); + try std.testing.expectEqual(@as(u8, 4), t.n); + try std.testing.expectEqual(want.cur, t.cur); + try std.testing.expect(t.steps[0] == .place and t.steps[1] == .list and t.steps[2] == .search and t.steps[3] == .place); + try std.testing.expectEqual(@as(u32, 4), t.steps[3].place.line); + if (live == null) try std.testing.expectEqual(want.line, pane.body.cur_row + 1); + const set = &pane.places; + try std.testing.expectEqual(want.lit, live == null and set.shows(pane) and set.provenance == .search and std.mem.eql(u8, set.pattern, "in_word")); + } + }; for ([_]struct { key: pardes.Key, want: Want }{ - .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } }, - .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } }, - .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } }, - .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } }, + .{ .key = back, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true } }, + .{ .key = back, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = true, .lit = false } }, + .{ .key = back, .want = .{ .file = "main.zig", .cur = 0, .line = 1, .picker = false, .lit = false } }, + .{ .key = ahead, .want = .{ .file = "main.zig", .cur = 0, .line = 1, .picker = true, .lit = false } }, + .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true } }, + .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3, .line = 4, .picker = false, .lit = true } }, }) |step| { p.update(.{ .key = step.key }); p.sync(); - const pane = p.panes[p.view().active].?; - const t = &pane.trail; - try std.testing.expectEqualStrings(step.want.file, std.Io.Dir.path.basename(pane.file.?.path)); - try std.testing.expectEqual(@as(u8, 4), t.n); - try std.testing.expectEqual(step.want.cur, t.cur); - try std.testing.expect(t.steps[1] == .list and t.steps[2] == .search); + try Check.f(p, step.want); } + // Esc from a list a walk reopened: rest exactly as before the Ctrl-o. + p.update(.{ .key = back }); + p.update(.{ .key = back }); + try Check.f(p, .{ .file = "words.zig", .cur = 2, .line = 1, .picker = true, .lit = false }); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + p.sync(); + try Check.f(p, .{ .file = "words.zig", .cur = 2, .line = 1, .picker = false, .lit = true }); + // Its Enter lands as its word's: a step from it, the search's word and + // the place after it dropped. + p.update(.{ .key = back }); + try std.testing.expect(pardes.Pick.live(p) != null); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + p.sync(); + var t = &p.panes[p.view().active].?.trail; + try std.testing.expectEqual(@as(u8, 3), t.n); + try std.testing.expectEqual(@as(u8, 2), t.cur); + try std.testing.expect(t.steps[0] == .place and t.steps[1] == .list and t.steps[2] == .place); + try std.testing.expectEqualStrings("Find words 1/1", t.steps[1].list.text.slice()); + try std.testing.expectEqualStrings("words.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path)); + // Backspace on its empty field walks on, as Ctrl-o. + p.update(.{ .key = back }); + try std.testing.expect(pardes.Pick.live(p) != null); + for (0.."words".len + 1) |_| p.update(.{ .key = .{ .cp = pardes.Key.backspace } }); + p.sync(); + try std.testing.expect(pardes.Pick.live(p) == null); + t = &p.panes[p.view().active].?.trail; + try std.testing.expectEqualStrings("main.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path)); + try std.testing.expect(t.n == 3 and t.cur == 0); } diff --git a/core/Pick.zig b/core/Pick.zig index 8669314f..c49e8682 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -147,6 +147,10 @@ act_at: u8 = 0, queue: std.ArrayList(Queued) = .empty, queue_bytes: std.ArrayList(u8) = .empty, queue_at: u32 = 0, +/// The step of its landing pane's trail a walk reopened it at (Ctrl-o, +/// UX L'1): its Ctrl-o and Ctrl-i walk on from that word, and its Enter +/// lands as that word's, the steps after it dropped. +walking: ?u8 = null, pub const Queued = struct { path: u32, len: u16, line: u32, col: u32 }; @@ -957,6 +961,7 @@ pub fn rollUp(p: *Pardes) void { pk.spine = .rows; pk.at = s.rows.at; pk.unrolled = false; + pk.walking = null; if (p.stream.target == pk.id) _ = p.stream.stop(); restore(p, pk); } @@ -1148,6 +1153,10 @@ pub fn key(p: *Pardes, k: Key) void { _ = s.field.key(k); return; } + // A list a walk reopened (UX L'1): Ctrl-o and Ctrl-i walk on from its + // word, the list rolled up unlanded. Ctrl-i is Tab where the terminal + // cannot tell them apart: a mark, as Tab. + if (pk.walking) |at| if (ctrl and (k.cp == 'o' or k.cp == 'i')) return walkOn(p, pk, at, if (k.cp == 'o') -1 else 1); if (alt and (k.cp == Key.enter or k.cp == 'l')) { pk.spine = .acts; pk.act_at = 0; @@ -1308,6 +1317,7 @@ fn back(p: *Pardes, pk: *Pick) void { if (!fuzzy(pk) and pk.source == .all) filter(p, pk); return; } + if (pk.walking) |at| return walkOn(p, pk, at, -1); const keys = pk.keys; TagState.toRest(p); if (keys.len == 0) return; @@ -1318,6 +1328,16 @@ fn back(p: *Pardes, pk: *Pick) void { s.unrolled = true; } +/// Ctrl-o (`delta` < 0) or Ctrl-i in a list a walk reopened at step `at` +/// of its landing pane's trail (UX L'1): the list rolled up unlanded, the +/// pane as it was, and the walk on from the list's word; past the last +/// word, the jump list's step. +fn walkOn(p: *Pardes, pk: *Pick, at: u8, delta: i32) void { + const id = p.paneBySerial(pk.landing) orelse return TagState.toRest(p); + TagState.toRest(p); + if (!Trail.walkFrom(p, id, at, delta)) pardes.Jump.listBy(p, delta); +} + /// C-q: the rows (the marked, else all, `Query.max_rows` at most) kept as /// text in a +Search under the asking pane, the source's word and query /// its first line, each row an address a Look opens. @@ -1379,6 +1399,7 @@ fn land(p: *Pardes, wanted: How) void { const a = arena.allocator(); const picked = pickedRows(p, pk, a) catch return; if (picked.len == 0) return; + const walking = pk.walking; // Walk: the first now, the others queued for C-i. pk.queue.clearRetainingCapacity(); pk.queue_bytes.clearRetainingCapacity(); @@ -1412,9 +1433,17 @@ fn land(p: *Pardes, wanted: How) void { _ = p.store.reopen(p, serial, from); }, .place => |at| if (k == 0 and (how == .walk or how == .queue)) { + // A list a walk reopened lands as its word's (UX L'1): a step + // from that word, the steps after it dropped. + const word: ?u8 = if (walking) |i| (if (from == landing and isWord(p.panes[from].?, i, pk.id)) i else null) else null; + if (word) |i| { + const trail = &p.panes[from].?.trail; + trail.n = i + 1; + trail.cur = i; + } switch (look.open(p, from, at.path, at.at, .replace)) { .none => {}, - else => listed(p, pk), + else => listed(p, pk, word), } } else if (k == 0 and how == .column) { // A column made only where there is no free space (UX J1). @@ -1452,11 +1481,25 @@ fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []c return buf.slice(); } +/// Whether step `i` of pane `pane`'s trail is picker `id`'s word. +fn isWord(pane: *const Pane, i: u8, id: u32) bool { + const t = &pane.trail; + return i < t.n and t.steps[i] == .list and t.steps[i].list.index == id; +} + /// The list rolled into the trail of the reading pane it landed in, its -/// word before the place: the list `n` and `N` walk there. -fn listed(p: *Pardes, pk: *const Pick) void { - const pane = p.panes[p.view().active] orelse return; +/// word before the place: the list `n` and `N` walk there; a list a walk +/// reopened at step `at` says where it is now in that word. The notice row +/// says what Ctrl-o goes back to (UX L'1). +fn listed(p: *Pardes, pk: *const Pick, at: ?u8) void { + const id = p.view().active; + const pane = p.panes[id] orelse return; if (!Trail.reading(p, pane)) return; + defer Trail.sayBack(p, id); + if (at) |i| if (isWord(pane, i, pk.id)) { + _ = wordOf(p, pk, &pane.trail.steps[i].list.text); + return; + }; var w: Trail.Word = .{ .index = pk.id }; _ = wordOf(p, pk, &w.text); Trail.through(&pane.trail, .{ .list = w }); @@ -1502,9 +1545,10 @@ pub fn walkList(p: *Pardes, id: usize, forward: bool) bool { return true; } -/// Look on a list word in pane `id`'s trail (SPEC §6.3): the list unrolled -/// again in that pane's tag, its rows, marks, cursor and query as they were. -pub fn reopen(p: *Pardes, id: usize, index: u32) void { +/// Look on a list word in pane `id`'s trail (SPEC §6.3), or a walk onto +/// it at step `walking` (UX L'1): the list unrolled again in that pane's +/// tag, its rows, marks, cursor and query as they were. +pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void { const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); const pane = p.panes[id] orelse return; TagState.toRest(p); @@ -1512,6 +1556,7 @@ pub fn reopen(p: *Pardes, id: usize, index: u32) void { pk.made = false; unroll(p, pk, pk.query.slice()); unrollRows(p, pk); + pk.walking = walking; } /// A list unrolled again: All's places found again, the cursor where it was. diff --git a/core/Prompt.zig b/core/Prompt.zig index c54bb228..afe9f78e 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -445,8 +445,10 @@ fn land(p: *Pardes, id: usize, pane: *Pane, op: Op, pat: []const u8, bad: bool) p.registers.put(p.gpa, '/', pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err); p.registers.last_search = '/'; set.provenance = .search; + const from = set.origin(pane); set.forget(p.gpa); - word(pane, if (op == .search_back) '?' else '/', pat); + word(p, pane, if (op == .search_back) '?' else '/', pat, from); + Trail.sayBack(p, id); } /// Alt-Enter in `/ ?` or `s S K A-K` (SPEC §7.2): the result kept as a @@ -688,36 +690,44 @@ pub fn execRecipe(p: *Pardes, id: usize) void { /// Pane `pane`'s search word, `/re/ 3/7`: one a pane, its `index` the /// length of its `/re/` with bit 16 set after n or N went round an end. -fn wordOf(pane: *Pane) ?*Trail.Word { +fn wordOf(pane: *Pane) ?*Trail.Search { for (pane.trail.steps[0..pane.trail.n]) |*step| if (step.* == .search) return &step.search; return null; } -fn patternOf(w: *const Trail.Word) []const u8 { +fn patternOf(w: *const Trail.Search) []const u8 { const end = patternEnd(w); return if (end < 2) "" else w.text.slice()[1 .. end - 1]; } /// Where a search word's `/re/` ends: held to its text (a damaged image's /// says anything). -fn patternEnd(w: *const Trail.Word) u16 { +fn patternEnd(w: *const Trail.Search) u16 { return std.math.clamp(@as(u16, @truncate(w.index)), @min(2, w.text.len), w.text.len); } /// Whether the places the pane's body shows are its search word's. -fn lights(pane: *const Pane, w: *const Trail.Word) bool { +fn lights(pane: *const Pane, w: *const Trail.Search) bool { const set = &pane.places; return set.shows(pane) and set.provenance == .search and !set.literal and std.mem.eql(u8, set.pattern, patternOf(w)); } /// `pat`, delimited by `delim`, as pane `pane`'s one search word, in place -/// of the one it had, written for where its places stand. -fn word(pane: *Pane, delim: u8, pat: []const u8) void { +/// of the one it had, written for where its places stand, its start the +/// byte `from` of its text (UX L'1: a walk back onto it puts the caret +/// there). +fn word(p: *Pardes, pane: *Pane, delim: u8, pat: []const u8, from: usize) void { // Its pattern and its place in the trail's room, else none. if (pat.len + 2 + 32 > Trail.max_text) return; - var w: Trail.Word = .{}; + const f = &pane.file.?; + var w: Trail.Search = .{}; _ = w.text.print("{c}{s}{c}", .{ delim, pat, delim }); w.index = w.text.len; + if (f.path.len <= Trail.max_text) if (File.lineIndex(p.gpa, f)) |index| { + const line = Places.lineOf(index, @min(from, f.content.len)); + w.from = .{ .line = @intCast(line + 1), .col = @intCast(@min(from, f.content.len) - File.lineStart(p.gpa, f, line) + 1) }; + w.from.path.set(f.path); + } else |_| {}; pane.trail.setWord(.{ .search = w }); refresh(pane, false); } @@ -796,13 +806,27 @@ pub fn stepped(p: *Pardes, id: usize, forward: bool, before: ?usize) void { /// `*`: pattern `pat`, the selection's (in `/` already), lights its places /// in `pane`'s body and is its search word, no prompt asked (SPEC §7.3). pub fn star(p: *Pardes, pane: *Pane, pat: []const u8) void { + const sel = pane.body.primaryRange(pane.file.?.content, 0); pane.places.search(p, pane, .search, 0, pat, false, null, false); - word(pane, '/', pat); + word(p, pane, '/', pat, @min(sel.anchor, sel.head)); } /// Look on pane `id`'s search word (SPEC §6.3): its places lit again and /// the one it was on selected. pub fn lookWord(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const w = wordOf(pane) orelse return; + const set = &pane.places; + light(p, id); + const rest = w.text.slice()[patternEnd(w)..]; + const n = std.fmt.parseInt(usize, std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '/') orelse rest.len], " "), 10) catch return; + if (n > 0 and n <= set.hits.items.len) set.goTo(p.settings.tab, pane, n - 1, false); +} + +/// Pane `id`'s search word's places lit again, `/` its pattern, the caret +/// where it is: a Look on the word, a walk onto it (Trail.walkFrom, the +/// caret where the search started, UX L'1). +pub fn light(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; const w = wordOf(pane) orelse return; const set = &pane.places; @@ -812,9 +836,6 @@ pub fn lookWord(p: *Pardes, id: usize) void { set.search(p, pane, .search, 0, pat, false, null, false); set.fill(p, pane, std.math.maxInt(usize), regexp.Regex.budget); p.view().active = id; - const rest = w.text.slice()[patternEnd(w)..]; - const n = std.fmt.parseInt(usize, std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '/') orelse rest.len], " "), 10) catch return; - if (n > 0 and n <= set.hits.items.len) set.goTo(p.settings.tab, pane, n - 1, false); } /// Exec on it: searched again from the caret, as its prompt and Enter @@ -841,7 +862,7 @@ pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; const whole = pardes.tagline.folded(p, pane).whole; - for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { + for (t.steps[0..t.backs()], 0..) |*step, i| if (step.* == .search) { if (lights(pane, &step.search) or t.isFolded(i, whole)) return null; return t.spanOf(i, whole); }; diff --git a/core/Trail.zig b/core/Trail.zig index 2a37d68a..cd8eb924 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -57,15 +57,17 @@ pub const Step = union(enum) { /// A list the pane came through (`Find pick 3/6 •2`, §5.6): its word /// and the pickers' index for it. Made as a picker lands (Pick.listed). list: Word, - /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by a search - /// prompt (Prompt.word). - search: Word, + /// A search made in the pane (`/dirty/ 3/7`, §7.3) and where it + /// started: a walk back onto it puts the caret there (UX L'1). Made by + /// a search prompt (Prompt.word). + search: Search, /// A chain of selection prompts as an Edit line (§7.5). Made by the sam /// prompts (Prompt.link). recipe: Word, }; pub const Place = struct { path: Kind.Buf(max_text) = .{}, line: u32 = 0, col: u32 = 0 }; pub const Word = struct { text: Kind.Buf(max_text) = .{}, index: u32 = 0 }; +pub const Search = struct { text: Kind.Buf(max_text) = .{}, index: u32 = 0, from: Place = .{} }; /// A file the walk can show: a text on its path, not an output, a /// listing, a pager, a query or a kind (§2: what is not a file is held). @@ -157,8 +159,11 @@ fn push(t: *Trail, s: Step) void { pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { const pane = p.panes[id].?; const t = &pane.trail; + // At a word (a walk onto a search's, a list's Enter, UX L'1): a step + // from it keeps the word, and is one wherever the pane is. + const word = t.cur < t.n and t.steps[t.cur] != .place; // Where it is already: no step. - if (here(pane)) |was| if (samePlace(was, path, at.line)) return show(p, id, path, at); + if (!word) if (here(pane)) |was| if (samePlace(was, path, at.line)) return show(p, id, path, at); for (t.steps[0..t.cur], 0..) |s, i| if (samePlace(s, path, at.line)) return go(p, id, @intCast(i)); if (t.n > t.cur + 1) for (t.steps[t.cur + 1 .. t.n], t.cur + 1..) |s, j| if (samePlace(s, path, at.line)) return go(p, id, @intCast(j)); const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong; @@ -166,7 +171,7 @@ pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { if (here(pane)) |was| { if (t.n > t.cur) { t.n = t.cur + 1; - t.steps[t.cur] = was; + if (!word) t.steps[t.cur] = was; } else push(t, was); } else t.n = t.cur; push(t, to); @@ -175,19 +180,27 @@ pub fn step(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { } /// Go to step `i` of reading pane `id`'s trail, back or forward (§6.4): -/// where it is now becomes the step it leaves, the ones between stay. +/// where it is now becomes the step it leaves (a word it is at stays the +/// word), the ones between stay. pub fn go(p: *Pardes, id: usize, i: u8) !usize { const pane = p.panes[id].?; const t = &pane.trail; if (i >= t.n or t.steps[i] != .place) return id; const s = t.steps[i]; - if (t.n > t.cur) if (here(pane)) |was| { - t.steps[t.cur] = was; - }; + leave(pane); t.cur = i; return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col }); } +/// Where pane `pane` is now kept as the step it leaves, when that is a +/// place: a word it is at stays the word. +fn leave(pane: *Pane) void { + const t = &pane.trail; + if (t.cur < t.n and t.steps[t.cur] == .place) if (here(pane)) |was| { + t.steps[t.cur] = was; + }; +} + /// A list the pane's newest step came through (§6.2: a picker's Enter, /// Pick.zig): its word before the step's place. pub fn through(t: *Trail, s: Step) void { @@ -210,7 +223,7 @@ pub fn through(t: *Trail, s: Step) void { pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong; const t = &p.panes[id].?.trail; - if (t.cur < t.n) t.steps[t.cur] = to; + if (t.cur < t.n and t.steps[t.cur] == .place) t.steps[t.cur] = to; return show(p, id, path, at); } @@ -327,7 +340,7 @@ pub fn keep(pane: *Pane) void { if (t.held) return; t.held = true; var w: u8 = 0; - for (t.steps[0..t.cur]) |s| if (s == .search or s == .recipe) { + for (t.steps[0..t.backs()]) |s| if (s == .search or s == .recipe) { t.steps[w] = s; w += 1; }; @@ -350,23 +363,96 @@ pub fn edited(p: *Pardes, f: *const panes.File.State) void { } -/// Back (`delta` < 0) or forward one place in reading pane `id`'s walk, -/// as Ctrl-o and Ctrl-i go first (pick-ui SPEC §6.4): true when it had -/// one that way, false to leave the step to the jump list (Jump.jumpBy). +/// Back (`delta` < 0) or forward one word in pane `id`'s walk, as Ctrl-o +/// and Ctrl-i go first (pick-ui SPEC §6.4, UX L'1): true when it had one +/// that way, false to leave the step to the jump list (Jump.jumpBy). pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool { const pane = p.panes[id] orelse return false; - if (!reading(p, pane)) return false; + return walkFrom(p, id, pane.trail.cur, delta); +} + +/// One word `delta`'s way from step `from` of pane `id`'s walk (UX L'1: +/// the trail's words are the stack): onto a place, there (`go`); onto a +/// list's word, that list unrolled again as it was left, previewing here, +/// its Ctrl-o and Ctrl-i going on from its word (Pick.reopen); onto a +/// search's, the caret where the search started and its places lit +/// (Prompt.light); a held pane onto its own words, a search's and a +/// recipe's (its selections back). A list no longer kept is said and +/// passed by. +pub fn walkFrom(p: *Pardes, id: usize, from: usize, delta: i32) bool { + const pane = p.panes[id] orelse return false; const t = &pane.trail; - var i: usize = t.cur; - while (if (delta < 0) i > 0 else i + 1 < t.n) { - i = if (delta < 0) i - 1 else i + 1; - if (t.steps[i] != .place) continue; - _ = go(p, id, @intCast(i)) catch |err| p.reportError(.at(id), "walk", err); + var at = from; + while (reach(p, pane, at, delta)) |i| { + switch (t.steps[i]) { + .owner => return false, // reach passes it by + .place => _ = go(p, id, i) catch |err| p.reportError(.at(id), "walk", err), + .list => |w| { + if (pardes.Pick.byId(p, w.index) == null) { + p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); + at = i; + continue; + } + pardes.Pick.reopen(p, id, w.index, i); + }, + .search => |*s| { + leave(pane); + t.cur = i; + // Its place copied: a step to another file frees this pane. + const start = s.from; + var to = id; + if (start.path.len > 0 and !t.held) { + to = show(p, id, start.path.slice(), .{ .line = start.line, .col = start.col }) catch |err| { + p.reportError(.at(id), "walk", err); + return true; + }; + } else if (start.path.len > 0 and std.mem.eql(u8, start.path.slice(), pane.file.?.path)) { + look.focusPaneLine(p, id, .{ .line = start.line, .col = start.col }, .center); + } + pardes.Prompt.light(p, to); + }, + .recipe => { + t.cur = i; + pardes.Prompt.lookRecipe(p, id); + }, + } return true; } return false; } +/// The step a walk from step `from` of pane `pane`'s trail reaches +/// `delta`'s way (UX L'1): a place, a list's word or a search's of a +/// reading pane; a held pane's own words, a search's and a recipe's; never +/// the owner. Only where it walks: a file, in a session whose jumps walk. +fn reach(p: *const Pardes, pane: *const Pane, from: usize, delta: i32) ?u8 { + if (p.settings.jumps != .walk or !isFile(pane)) return null; + const t = &pane.trail; + var i = from; + while (if (delta < 0) i > 0 else i + 1 < t.n) { + i = if (delta < 0) i - 1 else i + 1; + switch (t.steps[i]) { + .owner => {}, + .search => return @intCast(i), + .place, .list => if (!t.held) return @intCast(i), + .recipe => if (t.held) return @intCast(i), + } + } + return null; +} + +/// After a landing and a search's Enter in pane `id` (UX L'1): the word +/// its next Ctrl-o reaches, said on the notice row as an echo, `C-o back +/// to Find words 1/1`, never logged. +pub fn sayBack(p: *Pardes, id: usize) void { + const pane = p.panes[id] orelse return; + const i = reach(p, pane, pane.trail.cur, -1) orelse return; + var buf: [max_text + 16]u8 = undefined; + var said: [max_text + 32]u8 = undefined; + const text = std.fmt.bufPrint(&said, "C-o back to {s}", .{wordOf(&pane.trail, i, &buf)}) catch return; + _ = pardes.Messages.keep(p, .echo, pane.serial, "", text); +} + // ---- the words ---- /// `newest`: out of rest (UX D1), the owner's word and the newest back @@ -387,7 +473,8 @@ fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { while (from > 0 and shared(t, i, path[from..])) from = if (std.mem.lastIndexOfScalar(u8, path[0 .. from - 1], '/')) |slash| slash + 1 else 0; break :place std.fmt.bufPrint(buf, "{s}:{d}", .{ path[from..], at.line }) catch unreachable; // a path and a u32 fit }, - .list, .search, .recipe => |*w| w.text.slice(), + .list, .recipe => |*w| w.text.slice(), + .search => |*s| s.text.slice(), }; } @@ -406,10 +493,17 @@ fn shared(t: *const Trail, i: usize, end: []const u8) bool { const sep = " › "; +/// The end of the steps written before the path: the back steps, and the +/// word the pane is at when a walk stepped onto one (UX L'1: a search's, +/// its caret where the search started). +pub fn backs(t: *const Trail) usize { + return if (t.cur < t.n and t.steps[t.cur] != .place) t.cur + 1 else t.cur; +} + /// The steps a part writes. fn range(t: *const Trail, part: Part) [2]usize { return switch (part) { - .back, .newest => .{ 0, t.cur }, + .back, .newest => .{ 0, t.backs() }, .forward => .{ @min(t.n, t.cur + 1), t.n }, }; } @@ -417,20 +511,34 @@ fn range(t: *const Trail, part: Part) [2]usize { /// The forward steps written whole after the path at rest; the rest fold. pub const shown_ahead = 2; -/// Steps [lo, hi) of `part` folded into one dim `+N` word where the first -/// of them is (UX D8): at rest the back steps older than the newest -/// `whole` (never the owner), the forward steps past `shown_ahead`. -fn foldOf(t: *const Trail, part: Part, whole: usize) [2]usize { +/// Whether step `i` folds into a dim `+N` in `part`, one `+N` a run of them +/// where its first is (UX D8, L'1: the fold takes places): at rest a place +/// older than the newest `whole` back steps, or past the first +/// `shown_ahead` forward steps; a list's word only where the tag keeps its +/// newest step alone (`whole` 1), and never the newest list's; the owner's, +/// a search's and a recipe's never. +fn folds(t: *const Trail, part: Part, whole: usize, i: usize) bool { + const end = t.backs(); return switch (part) { - .back => back: { - const lo: usize = @intFromBool(t.cur > 0 and t.steps[0] == .owner); - break :back .{ lo, @max(lo, t.cur -| whole) }; + .newest => false, + .forward => t.steps[i] == .place and i > t.cur + shown_ahead, + .back => i + whole < end and switch (t.steps[i]) { + .place => true, + .list => whole == 1 and for (t.steps[i + 1 .. end]) |s| { + if (s == .list) break true; + } else false, + .owner, .search, .recipe => false, }, - .forward => .{ @min(t.n, t.cur + 1 + shown_ahead), t.n }, - .newest => .{ 0, 0 }, }; } +/// The first of step `i`'s run of folded steps in `part`. +fn runStart(t: *const Trail, part: Part, whole: usize, i: usize) usize { + var at = i; + while (at > range(t, part)[0] and folds(t, part, whole, at - 1)) at -= 1; + return at; +} + /// The cells of the newest step's word out of rest: a longer one is cut /// in its middle (UX D1: `Find pick…3/6`). const newest_cells = 24; @@ -440,9 +548,13 @@ const newest_cells = 24; /// of rest the owner's and the newest step's alone, a word longer than /// `newest_cells` keeping its first and last cells around a `…`. fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) ?[]const u8 { - if (part == .newest and t.steps[i] != .owner and i + 1 != t.cur) return null; - const fold = foldOf(t, part, whole); - if (i >= fold[0] and i < fold[1]) return if (i == fold[0]) std.fmt.bufPrint(buf, "+{d}", .{fold[1] - fold[0]}) catch unreachable else null; + if (part == .newest and t.steps[i] != .owner and i + 1 != t.backs()) return null; + if (folds(t, part, whole, i)) { + if (runStart(t, part, whole, i) != i) return null; + var end = i; + while (end < range(t, part)[1] and folds(t, part, whole, end)) end += 1; + return std.fmt.bufPrint(buf, "+{d}", .{end - i}) catch unreachable; // a count fits + } const word = wordOf(t, i, buf); if (part != .newest or word.len <= newest_cells) return word; const tab = 8; // a step's word holds no tab @@ -455,7 +567,7 @@ fn wordIn(t: *const Trail, part: Part, whole: usize, i: usize, buf: *[max_text + /// The back steps' words, each with the separator after it (before the /// path), or the forward steps', each with one before it (after the path), -/// the folded ones as one `+N` (`foldOf`); out of rest (`newest`) the +/// each run of folded ones as one `+N` (`folds`); out of rest (`newest`) the /// owner's and the newest's. pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void { var buf: [max_text + 16]u8 = undefined; @@ -482,7 +594,7 @@ pub fn bytes(t: *const Trail, part: Part, whole: usize) usize { /// The back step `n` and N walk (Pick.walkList, Prompt): the newest list /// or search; its word is underlined (UX D8). pub fn walked(t: *const Trail) ?u8 { - var i: usize = t.cur; + var i: usize = t.backs(); while (i > 0) { i -= 1; if (t.steps[i] == .list or t.steps[i] == .search) return @intCast(i); @@ -503,21 +615,18 @@ pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool { pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize { var buf: [max_text + 16]u8 = undefined; var cut: [max_text + 16]u8 = undefined; + const at = if (folds(t, .back, whole, i)) runStart(t, .back, whole, i) else i; var x: usize = 0; - for (0..i) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| { + for (0..at) |j| if (wordIn(t, .back, whole, j, &buf, &cut)) |word| { x += word.len + sep.len; }; - const fold = foldOf(t, .back, whole); - const at = if (i >= fold[0] and i < fold[1]) fold[0] else i; - if (at < i) return spanOf(t, at, whole); - const word: []const u8 = wordIn(t, .back, whole, i, &buf, &cut) orelse ""; + const word: []const u8 = wordIn(t, .back, whole, at, &buf, &cut) orelse ""; return .{ x, x + word.len }; } -/// Whether back step `i` is in the fold's `+N`. +/// Whether back step `i` is in a fold's `+N`. pub fn isFolded(t: *const Trail, i: usize, whole: usize) bool { - const fold = foldOf(t, .back, whole); - return i >= fold[0] and i < fold[1]; + return folds(t, .back, whole, i); } /// The step whose word in `part` is at byte `off` of what `write` wrote @@ -527,12 +636,17 @@ pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 { var cut: [max_text + 16]u8 = undefined; var x: usize = 0; const r = range(t, part); - const fold = foldOf(t, part, whole); for (r[0]..r[1]) |i| { const word = wordIn(t, part, whole, i, &buf, &cut) orelse continue; if (part == .forward) x += sep.len; // A fold's `+N` is the step nearest the path of those it holds. - if (off >= x and off < x + word.len) return @intCast(if (i == fold[0] and fold[0] < fold[1]) (if (part == .back) fold[1] - 1 else fold[0]) else i); + if (off >= x and off < x + word.len) { + var near = i; + if (part == .back and folds(t, part, whole, i)) while (near + 1 < r[1] and folds(t, part, whole, near + 1)) { + near += 1; + }; + return @intCast(near); + } x += word.len; if (part != .forward) x += sep.len; } @@ -550,7 +664,7 @@ pub fn lookStep(p: *Pardes, id: usize, i: u8) void { .owner => |serial| if (p.paneBySerial(serial)) |owner| { p.view().active = owner; } else p.reportFailure(id, "walk: its owner is closed"), - .list => |w| pardes.Pick.reopen(p, id, w.index), + .list => |w| pardes.Pick.reopen(p, id, w.index, null), .search => pardes.Prompt.lookWord(p, id), .recipe => pardes.Prompt.lookRecipe(p, id), } @@ -867,14 +981,18 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); // The reader's tag in the reading tint, the held one's not; the notice - // row, nothing said, where the reader's caret is. + // row says what Ctrl-o goes back to (UX L'1), and with nothing said, + // where the reader's caret is. try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, rd)); try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, f.held))); - const s = try p.render(arena.allocator()); - const foot = s.region(.notice_row, pardes.Region.none).?.rect; - var row: std.ArrayList(u8) = .empty; - for (0..s.cols) |x| try row.appendSlice(arena.allocator(), s.at(@intCast(x), foot.y).grapheme()); - try std.testing.expect(std.mem.indexOf(u8, row.items, try std.fmt.bufPrint(&want, "{s}/place.zig:8", .{f.dir})) != null); + for ([_][]const u8{ "C-o back to Refs 1/2", try std.fmt.bufPrint(&want, "{s}/place.zig:8", .{f.dir}) }) |said| { + const s = try p.render(arena.allocator()); + const foot = s.region(.notice_row, pardes.Region.none).?.rect; + var row: std.ArrayList(u8) = .empty; + for (0..s.cols) |x| try row.appendSlice(arena.allocator(), s.at(@intCast(x), foot.y).grapheme()); + try std.testing.expect(std.mem.indexOf(u8, row.items, said) != null); + _ = p.messages.retire(&.{.echo}); + } // n: the list's next place, in place of the current step. typeKeys(p, "n"); p.sync(); @@ -1320,3 +1438,74 @@ test "a walk step never closes a file with unsaved changes: a reading pane chang try std.testing.expectEqualStrings("changed\n", kept.file.?.content); try std.testing.expect(kept.trail.held); } + +test "the fold takes places alone (UX L'1): a list's and a search's words are never in a `+N`, a run of places between them each its own; where the tag keeps its newest step alone, older lists fold with the places, the newest list never" { + const Make = struct { + fn place(line: u32) Step { + var at: Place = .{ .line = line, .col = 1 }; + at.path.set("/x/a.zig"); + return .{ .place = at }; + } + fn list(text: []const u8) Step { + var w: Word = .{}; + w.text.set(text); + return .{ .list = w }; + } + fn written(t: *const Trail, part: Part, whole: usize, out: []u8) ![]const u8 { + var w: std.Io.Writer = .fixed(out); + try t.write(part, whole, &w); + return w.buffered(); + } + }; + var out: [1024]u8 = undefined; + var t: Trail = .{}; + for ([_]Step{ Make.place(1), Make.place(2), Make.list("A 1/2"), Make.place(3), Make.place(4), Make.place(5), Make.place(6) }) |s| push(&t, s); + t.cur = 6; + try std.testing.expectEqualStrings("+2 › A 1/2 › a.zig:3 › a.zig:4 › a.zig:5 › ", try Make.written(&t, .back, 3, &out)); + try std.testing.expectEqualStrings("+2 › A 1/2 › +2 › a.zig:5 › ", try Make.written(&t, .back, 1, &out)); + // Each `+N` is its run's: a click on the second goes to its newest. + try std.testing.expectEqual(@as(?u8, 1), t.stepAt(.back, 1, 0)); + try std.testing.expectEqual(@as(?u8, 4), t.stepAt(.back, 1, "+2 › A 1/2 › ".len)); + try std.testing.expectEqualDeep([2]usize{ "+2 › A 1/2 › ".len, "+2 › A 1/2 › +2".len }, t.spanOf(3, 1)); + try std.testing.expect(t.isFolded(4, 1) and !t.isFolded(2, 1) and !t.isFolded(5, 1)); + // Two lists: with the newest step alone the older folds, the newer not. + t = .{}; + for ([_]Step{ Make.place(1), Make.list("A 1/2"), Make.place(2), Make.list("B 1/1"), Make.place(3), Make.place(4) }) |s| push(&t, s); + t.cur = 5; + try std.testing.expectEqualStrings("+3 › B 1/1 › a.zig:3 › ", try Make.written(&t, .back, 1, &out)); + try std.testing.expectEqualStrings("+1 › A 1/2 › a.zig:2 › B 1/1 › a.zig:3 › ", try Make.written(&t, .back, 3, &out)); + // A search's word never folds; forward, the places past two alone. + t = .{}; + var s: Search = .{}; + s.text.set("/s/ 1/1"); + for ([_]Step{ Make.place(1), Make.place(2), .{ .search = s }, Make.place(3), Make.place(4), Make.place(5), Make.list("C 1/1"), Make.place(6), Make.place(7) }) |x| push(&t, x); + t.cur = 4; + try std.testing.expectEqualStrings("+2 › /s/ 1/1 › a.zig:3 › ", try Make.written(&t, .back, 1, &out)); + try std.testing.expectEqualStrings(" › a.zig:5 › C 1/1 › +2", try Make.written(&t, .forward, 1, &out)); +} + +test "a held pane walks its own words (UX L'1): Ctrl-o onto its search's word puts the caret where the search started, its places lit; past it, the jump list's" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + const held = p.panes[f.held].?; + pardes.look.focusPaneLine(p, f.held, .{ .line = 20, .col = 3 }, .center); + typeKeys(p, "/line 9"); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + p.sync(); + try std.testing.expectEqual(@as(i32, 89), held.body.cur_row); + try std.testing.expect(held.trail.n == 1 and held.trail.cur == 1 and held.trail.steps[0] == .search); + try std.testing.expectEqualStrings("C-o back to /line 9/ 2/11", p.messages.headline().?.words()); + held.places.clear(p.gpa); + p.update(.{ .key = .{ .cp = 'o', .ctrl = true } }); + p.sync(); + try std.testing.expectEqual(@as(usize, f.held), p.view().active); + try std.testing.expectEqual(@as(i32, 19), held.body.cur_row); + try std.testing.expectEqual(@as(i32, 2), held.body.cur_col); + try std.testing.expectEqual(@as(u8, 0), held.trail.cur); + try std.testing.expect(held.places.shows(held) and std.mem.eql(u8, held.places.pattern, "line 9")); + // Its word still before its path, the search's. + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, held), "/line 9/ ")); + try std.testing.expect(!walkBy(p, f.held, -1)); +} diff --git a/core/draw.zig b/core/draw.zig index 2553d5be..b666fc15 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -1122,11 +1122,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) { const kept = tagline.folded(p, pane).whole; const t = &pane.trail; - const first: usize = @intFromBool(t.steps[0] == .owner); - if (t.isFolded(first, kept)) { - const fold = t.spanOf(first, kept); + // Each run of folded places' `+N` (UX L'1: words never fold). + for (0..t.backs()) |i| if (t.isFolded(i, kept) and !(i > 0 and t.isFolded(i - 1, kept))) { + const fold = t.spanOf(i, kept); inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), inks.dim, false); - } + }; if (t.walked()) |i| if (!t.isFolded(i, kept)) { const word = t.spanOf(i, kept); inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.roles.key, true); diff --git a/test/perf.zig b/test/perf.zig index 00a5524a..2ea666c4 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -86,12 +86,16 @@ const Op = enum { /// the tag states' keys compare with (key-down's frames each draw /// another place of the file). rest_keys, + /// Ctrl-o from a list's landing onto its word (UX L'1): the list + /// reopened as it was left, its head and band drawn in the key's frame; + /// Esc back to rest and its frame (two keys, two frames). + walk_pop, /// Run only when named (`--op`): a full run, its cells and the sums a /// gate takes over them (perfops' "terminal on all") are as before. fn named(o: Op) bool { return switch (o) { - .spc, .spc_down, .help_type, .describe, .rest_keys => true, + .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => true, else => false, }; } @@ -118,6 +122,7 @@ const Op = enum { .help_type => "help-type", .describe => "describe", .rest_keys => "rest-keys", + .walk_pop => "walk-pop", }; } }; @@ -622,7 +627,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u switch (op) { .image_frame => return measureImage(std.fs.path.dirname(path).?, samples, warmup), .client_key_down, .client_edit_char, .client_delete_undo => return measureClient(op, path, reps), - .spc, .spc_down, .help_type, .describe, .rest_keys => return measureTag(op, path, reps), + .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => return measureTag(op, path, reps), else => {}, } if (op == .open) { @@ -677,7 +682,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u const wheel_row = rect.y + pardes.BOX_H; const t0 = nowNs(); switch (op) { - .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => unreachable, .render, .deep_selection => {}, .key_down => core.update(.{ .key = .{ .cp = 'j', .text = "j" } }), .key_right => core.update(.{ .key = .{ .cp = 'l', .text = "l" } }), @@ -691,7 +696,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u _ = try frame(core); const dt = nowNs() -| t0; switch (op) { - .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys => unreachable, + .open, .image_frame, .client_key_down, .client_edit_char, .client_delete_undo, .spc, .spc_down, .help_type, .describe, .rest_keys, .walk_pop => unreachable, .body_write => if (pane.file.?.content.len != before.len + 8 * body_chunk.len) return error.BodyWriteWasNotAppended, .body_appends => if (pane.file.?.content.len != before.len + append_count * append_chunk_len) return error.BodyAppendsWereNotAppended, .render, .deep_selection => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col or pane.file.?.content.len != before.len) @@ -790,8 +795,17 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { pump(core); const id = filePane(core) orelse return error.OpenDidNotOpenFile; core.view().active = id; + // A list of two places in the file, landed on its first (a reading + // pane's step): the list's word in its trail before the place. + if (op == .walk_pop) { + core.settings.jumps = .walk; + const rows = try std.fmt.allocPrint(gpa, "{s}:10:1 a\n{s}:20:1 b\n", .{ path, path }); + defer gpa.free(rows); + pardes.Pick.open(core, id, .list, "Refs", "", rows); + } const enter: []const Key = switch (op) { .spc, .rest_keys => &.{}, + .walk_pop => &.{.{ .cp = Key.enter }}, .spc_down => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = Key.down } }, .help_type => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = '?', .text = "?" } }, .describe => &.{ .{ .cp = ' ', .text = " " }, .{ .cp = 'h', .text = "h" }, .{ .cp = 'k', .text = "k" } }, @@ -806,8 +820,11 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { .help_type => &.{ .{ .cp = 'e', .text = "e" }, .{ .cp = Key.backspace } }, .describe => &.{ .{ .cp = 'g', .text = "g" }, .{ .cp = 'd', .text = "d" } }, .rest_keys => &.{ .{ .cp = 'j', .text = "j" }, .{ .cp = 'k', .text = "k" } }, + .walk_pop => &.{ .{ .cp = 'o', .ctrl = true }, .{ .cp = Key.escape } }, else => unreachable, }; + const landed = core.panes[id].?.trail.cur; + if (op == .walk_pop and (landed == 0 or core.panes[id].?.trail.steps[landed - 1] != .list)) return error.ListDidNotLand; const s = &core.view().tag_state; for (0..warmup + samples.len) |n| { const t0 = nowNs(); @@ -822,6 +839,8 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { if (!pardes.TagState.shown(core, core.view())) return error.LevelNotShown; _ = try frame(core); } + // The list reopened by the key itself, drawn in its frame. + if (op == .walk_pop and k.ctrl and pardes.Pick.live(core) == null) return error.ListNotReopened; } const dt = nowNs() -| t0; const held = switch (op) { @@ -830,6 +849,7 @@ fn measureTag(op: Op, path: []const u8, reps: usize) !Cell { .help_type => s.kind == .help and s.field.len == 0 and s.nhits > 0, .describe => s.kind == .describe and s.found, .rest_keys => s.kind == .rest and s.root == null and core.panes[id].?.body.cur_row == 0, + .walk_pop => s.kind == .rest and core.panes[id].?.trail.cur == landed and core.panes[id].?.body.cur_row == 9, else => unreachable, }; if (!held) return error.TagStateLost; diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index e9a50dec..82686991 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -72,7 +72,7 @@ |7: |8: |9: -|40: ✓ /tmp/pardes-snap/find/cwd/here.txt Find 1 message · SPC h m +|40: ✓ C-o back to Find zqm 2/3 1 message · SPC h m == snap nomatch grid=120x41 cursor=30,2 |2: ^ Find zqm 2/3 › ␣ f Find zzqq 0 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 8fbf0221..6a70d3c4 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -113,7 +113,7 @@ |27: 11 l11 |28: 12 l12 |29: -|30: · @p1 a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program) 1 message · SPC h m +|30: ✓ C-o back to /MARK/ 2/3 1 message · SPC h m == snap n grid=180x31 cursor=97,27 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 3/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll |18: g.txt 1 l1 -- cgit v1.3 From f6f02bab7554e50241faa1a0c81517126bd06b94 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 00:21:48 -0300 Subject: Pick, Core, keys: SPC ' steps back through the kept pickers (UX DESIGN L'2, binding; the user liked L-b): Resume reopens the newest kept picker as before, and again as the next leader sequence after an Esc from the one it opened, nothing typed between, the one before it; Ctrl-o in a picker Resume opened steps to the next older kept one (its field, cursor and marks its own, where Resume opens them: Pick.resumeAt), Ctrl-i the next newer, each end said (`Resume: no picker before it: the last 8 are kept`, `Resume: the newest picker`); the head reads `Resume 2/5` before the picker's own word (`Resume 2/5 Find words`); the walk is `Pardes.resume_at` beside `picks` (0 for none, the newest 1): any other picker opened, reopened or landed ends it, and so does any key at rest but the leader and Resume's after it (Pick.keyAtRest, called beside Prompt.keyAtRest in keys.handleKey); the order is a picker's `used` (L': made, landed, or reopened by a walk, the newest the highest, Pick.touch), not its serial, and the picker the ring drops for a new one is the least used of them (Pick.rank: `used`, then the serial, for pickers a dump made before `used`); a list word naming a dropped picker says `walk: that list is gone: the last 8 are kept` (item L'1's walk passes it by); RUN (TEST FIRST): Pick.zig "SPC ' steps back through the kept pickers (UX L'2) ..." keeps three lists A, B, C and asks after each of SPC ', Esc SPC ', Ctrl-o, Ctrl-o (said: no picker before it), Ctrl-i, Ctrl-i, Esc j SPC ' (a key between: the newest again), Esc SPC ' the live picker and its head's `Resume k/3`, then Enter on B (the walk over, B the newest: SPC ' opens it as `1/3 B`), then Ctrl-o onto a list word whose picker is gone (said, passed by, the walk on to the first place): fails on L'1's tree at Pick.zig:2915 on the first SPC ' (expected `1/3 C`, the head has no Resume word), passes now; a user hit it whenever the picker wanted was not the last one; core-test 1126/1299 (173 skipped), shell-test 1347/1350 (3 skipped); load 3.9 to 4.6 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 4 ++ core/Pick.zig | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- core/keys.zig | 1 + 3 files changed, 154 insertions(+), 9 deletions(-) diff --git a/core/Core.zig b/core/Core.zig index f47cc5d8..f9c4d6c9 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -413,6 +413,10 @@ stream: Stream = .{}, /// The pickers: the one live in a view's tag, and the last ones rolled /// up, which their list words and Resume reopen (Pick.zig). picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null), +/// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none: +/// `SPC '` again after an Esc from it, nothing typed between, opens the +/// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2). +resume_at: u8 = 0, /// The panes' `Changes` (jj.zig): what was asked of jj, and what it /// answered for each pane, by its serial: the session's, not a field of /// every pane (a digest and a rollback copy walk every pane's fields at diff --git a/core/Pick.zig b/core/Pick.zig index c49e8682..85c16a69 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -147,6 +147,9 @@ act_at: u8 = 0, queue: std.ArrayList(Queued) = .empty, queue_bytes: std.ArrayList(u8) = .empty, queue_at: u32 = 0, +/// Where it stands among the kept pickers, the newest the highest +/// (`touch`): Resume's order (`nth`), and the oldest goes for a new one. +used: u32 = 0, /// The step of its landing pane's trail a walk reopened it at (Ctrl-o, /// UX L'1): its Ctrl-o and Ctrl-i walk on from that word, and its Enter /// lands as that word's, the steps after it dropped. @@ -211,6 +214,7 @@ pub fn previewing(p: *const Pardes, id: usize) bool { pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void { const asker = p.panes[from] orelse return; TagState.toRest(p); + p.resume_at = 0; const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err); pk.word.set(if (word.len > 0) word else words.get(source).word); pk.keys.set(words.get(source).keys); @@ -235,7 +239,7 @@ fn make(p: *Pardes, source: Source) !*Pick { if (slot == null) { // The oldest not live. var oldest: ?usize = null; - for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or pk.id < p.picks[oldest.?].?.id)) { + for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) { oldest = i; }; const i = oldest orelse return error.NoPickerSlots; @@ -248,9 +252,46 @@ fn make(p: *Pardes, source: Source) !*Pick { p.next_serial += 1; pk.* = .{ .id = p.next_serial, .source = source }; p.picks[slot.?] = pk; + touch(p, pk); return pk; } +/// Picker `pk` the newest kept (UX L': made, landed, reopened by a walk). +fn touch(p: *Pardes, pk: *Pick) void { + var top: u32 = 0; + for (p.picks) |slot| if (slot) |o| { + top = @max(top, o.used); + }; + pk.used = top +| 1; +} + +/// Where picker `pk` stands among the kept ones, newer higher: its `used`, +/// then its serial (pickers a dump made before `used` was kept). +fn rank(pk: *const Pick) u64 { + return @as(u64, pk.used) << 32 | pk.id; +} + +/// The `k`th newest kept picker, the newest 1. +fn nth(p: *const Pardes, k: usize) ?*Pick { + var below: u64 = std.math.maxInt(u64); + var found: ?*Pick = null; + for (0..k) |_| { + found = null; + for (p.picks) |slot| if (slot) |pk| if (rank(pk) < below and (found == null or rank(pk) > rank(found.?))) { + found = pk; + }; + below = rank(found orelse return null); + } + return found; +} + +/// The pickers kept. +fn nkept(p: *const Pardes) usize { + var n: usize = 0; + for (p.picks) |slot| n += @intFromBool(slot != null); + return n; +} + /// Picker `pk` asked from pane `from`: the pane it lands in is `from` when /// it reads; its reader when it is held and has one; else an untouched /// pane, `from` itself first (UX J1), which previews as a reading pane does @@ -651,6 +692,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const text = &b.text; // SPC's cell, then its keys': `␣ f`. if (pk.keys.len > 0) try b.keyCells(.leader, pk.keys.slice()); + // One Resume opened: where it stands among the kept (UX L'2). + if (p.resume_at != 0) try text.print(arena, "Resume {d}/{d} ", .{ p.resume_at, nkept(p) }); try text.appendSlice(arena, pk.word.slice()); try text.append(arena, ' '); for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()}); @@ -1157,6 +1200,8 @@ pub fn key(p: *Pardes, k: Key) void { // word, the list rolled up unlanded. Ctrl-i is Tab where the terminal // cannot tell them apart: a mark, as Tab. if (pk.walking) |at| if (ctrl and (k.cp == 'o' or k.cp == 'i')) return walkOn(p, pk, at, if (k.cp == 'o') -1 else 1); + // One Resume opened: the next older or newer kept one (UX L'2). + if (p.resume_at != 0 and ctrl and (k.cp == 'o' or k.cp == 'i')) return resumeAt(p, p.paneBySerial(pk.owner) orelse p.view().active, if (k.cp == 'o') p.resume_at + 1 else p.resume_at - 1); if (alt and (k.cp == Key.enter or k.cp == 'l')) { pk.spine = .acts; pk.act_at = 0; @@ -1400,6 +1445,8 @@ fn land(p: *Pardes, wanted: How) void { const picked = pickedRows(p, pk, a) catch return; if (picked.len == 0) return; const walking = pk.walking; + touch(p, pk); + p.resume_at = 0; // Walk: the first now, the others queued for C-i. pk.queue.clearRetainingCapacity(); pk.queue_bytes.clearRetainingCapacity(); @@ -1552,6 +1599,8 @@ pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void { const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); const pane = p.panes[id] orelse return; TagState.toRest(p); + p.resume_at = 0; + touch(p, pk); pk.landing = pane.serial; pk.made = false; unroll(p, pk, pk.query.slice()); @@ -1575,19 +1624,36 @@ pub fn rerun(p: *Pardes, id: usize, index: u32) void { open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows); } -/// Resume (`SPC '`): the last picker reopened as it was, from pane `from`, -/// in the tag of the pane its Enter lands in. +/// Resume (`SPC '`): the newest kept picker reopened as it was, from pane +/// `from`, in the tag of the pane its Enter lands in; again after an Esc +/// from it, nothing typed between, the one before it (UX L'2). pub fn resumeFrom(p: *Pardes, from: usize) void { - var newest: ?*Pick = null; - for (p.picks) |slot| if (slot) |pk| if (newest == null or pk.id > newest.?.id) { - newest = pk; - }; - const pk = newest orelse return p.setMessage(.at(from), "Resume: no picker yet"); - TagState.toRest(p); + if (p.resume_at == 0 and nkept(p) == 0) return p.setMessage(.at(from), "Resume: no picker yet"); if (p.panes[from] == null) return; + resumeAt(p, from, p.resume_at + 1); +} + +/// The `k`th newest kept picker reopened as it was, asked from pane +/// `from`, in the tag of the pane its Enter lands in. +fn resumeAt(p: *Pardes, from: usize, k: usize) void { + const pk = (if (k > 0) nth(p, k) else null) orelse + return p.setMessage(.at(from), if (k == 0) "Resume: the newest picker" else "Resume: no picker before it: the last 8 are kept"); + TagState.toRest(p); hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "Resume", err); unroll(p, pk, pk.query.slice()); unrollRows(p, pk); + p.resume_at = @intCast(k); +} + +/// A key the tag at rest takes (keys.handleKey): any but the leader and +/// Resume's after it ends a Resume walk, so that `SPC '` opens the newest +/// again (UX L'2). +pub fn keyAtRest(p: *Pardes, k: Key) void { + const v = p.view(); + if (p.resume_at == 0) return; + if (v.prefix == .none and pardes.hit(k, config.leader)) return; + if (v.prefix == .leader and v.leader_n == 0 and !k.ctrl and !k.alt and k.cp == config.leader_path.get(.Resume).?[0]) return; + p.resume_at = 0; } /// B3 on a picker's row (mouse.zig bandPress): Enter on it. @@ -2860,3 +2926,77 @@ test "a picker's preview starts under its band: its landing line ⌈visible/3⌉ try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) }); try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "own 1\n")); } + +test "SPC ' steps back through the kept pickers (UX L'2): again after an Esc, nothing typed between, the one before; Ctrl-o and Ctrl-i in it the next older and newer, its head `Resume 2/3`; a key between, the newest again; a list word naming a picker no longer kept says so and the walk passes it by" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "base.zig", "text\n"); + const base = try p.setTestFile("text\n"); + p.gpa.free(base.file.?.path); + base.file.?.path = b_path; + const id = p.view().active; + const row = try std.fmt.allocPrint(p.gpa, "{s}:2:1 two\n", .{a_path}); + defer p.gpa.free(row); + // Three lists kept, C the newest. + for ([_][]const u8{ "A", "B", "C" }) |word| { + open(p, id, .list, word, "", row); + p.update(.{ .key = .{ .cp = Key.escape } }); + } + try std.testing.expect(live(p) == null); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const Shown = struct { + /// The live picker's word and its head's `Resume k/N`, as `2/3 B`. + fn of(pp: *Pardes, a: std.mem.Allocator) ![]const u8 { + const pk = live(pp) orelse return "none"; + const h = (try head(pp, a, pp.panes[pp.paneBySerial(pk.landing).?].?)).?; + const at = std.mem.indexOf(u8, h.text, "Resume ") orelse return pk.word.slice(); + const end = std.mem.indexOfScalarPos(u8, h.text, at + "Resume ".len, ' ').?; + return std.fmt.allocPrint(a, "{s} {s}", .{ h.text[at + "Resume ".len .. end], pk.word.slice() }); + } + }; + const Step = struct { keys: []const u8, want: []const u8 }; + for ([_]Step{ + .{ .keys = " '", .want = "1/3 C" }, + .{ .keys = "\x1b '", .want = "2/3 B" }, + .{ .keys = "o", .want = "3/3 A" }, + .{ .keys = "o", .want = "3/3 A" }, + .{ .keys = "i", .want = "2/3 B" }, + .{ .keys = "i", .want = "1/3 C" }, + .{ .keys = "\x1bj '", .want = "1/3 C" }, + .{ .keys = "\x1b '", .want = "2/3 B" }, + }, 0..) |step, n| { + for (step.keys) |c| switch (c) { + 0x1b => p.update(.{ .key = .{ .cp = Key.escape } }), + // Ctrl-o and Ctrl-i alone in a step: in the picker. + 'o', 'i' => p.update(.{ .key = .{ .cp = c, .ctrl = true } }), + else => p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }), + }; + errdefer std.debug.print("step {d}\n", .{n}); + try std.testing.expectEqualStrings(step.want, try Shown.of(p, frame.allocator())); + if (n == 3) try std.testing.expect(std.mem.indexOf(u8, p.messages.headline().?.words(), "no picker before it") != null); + } + // Its Enter lands as any list's: the walk over, it the newest. + p.update(.{ .key = .{ .cp = Key.enter } }); + p.sync(); + p.update(.{ .key = .{ .cp = ' ', .text = " " } }); + p.update(.{ .key = .{ .cp = '\'', .text = "'" } }); + try std.testing.expectEqualStrings("1/3 B", try Shown.of(p, frame.allocator())); + p.update(.{ .key = .{ .cp = Key.escape } }); + // A list word naming a picker no longer kept: said, and passed by. + const reader = p.view().active; + const t = &p.panes[reader].?.trail; + try std.testing.expect(t.n == 3 and t.cur == 2 and t.steps[1] == .list); + t.steps[1].list.index = 999_999; + p.update(.{ .key = .{ .cp = 'o', .ctrl = true } }); + p.sync(); + try std.testing.expect(std.mem.indexOf(u8, p.messages.headline().?.words(), "that list is gone: the last 8 are kept") != null); + try std.testing.expect(live(p) == null); + try std.testing.expectEqualStrings("base.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path)); + try std.testing.expectEqual(@as(u8, 0), p.panes[p.view().active].?.trail.cur); +} diff --git a/core/keys.zig b/core/keys.zig index e9be2461..ea25c2f7 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -232,6 +232,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { // A tag in a typing state takes every key (TagState: Help, describe-key). if (p.view().tag_state.kind != .rest) return tagStateKey(p, key); Prompt.keyAtRest(p, key); + @import("Pick.zig").keyAtRest(p, key); // Esc takes a hover's ghost lines away (SPEC §3.5) before anything else // it does. if (p.lsp_ask.hover != null and hit(key, config.escape)) { -- cgit v1.3 From d75f8947fde8d2fa425ee0b60c7a687a0ff9f314 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 00:28:55 -0300 Subject: Pick, builtins, config, Core, docs: Lists, a picker of the kept pickers (UX DESIGN L'3, binding; the user liked L-c): `SPC f l`, the word Lists, and `'` among a picker's sources (M-h) open it from the asking pane (Source.lists; from a live picker, one of its own where that one was asked: switchTo); its rows, newest first (Pick.nth), are the kept pickers' list words, the source word, the query (refinements joined by ` | `), `cursor/matches` and `•N` when marked (Pick.wordOf), each with where it last landed at its right, dim, `@p2 › words.zig:16` (Pick.landed, written by land); the body previews the picker's current row as any place (its row's target); the band's second step, a doc, shows that picker's rows around its cursor, which is marked `▶`, read only (Pick.listedStep); Enter (and B3 on a row) reopens that picker as it was left, where Lists was asked from, the newest now (Pick.reopenListed); Esc to rest; no acts and no sources in it (head `⏎ reopen it · esc`; execWord passes it by); Lists itself is never kept: Pardes.picks has one more slot, Lists takes the one Lists had or a free one, never drops a kept picker for its room, is never in Resume's order, in Lists' rows or the count of the kept (Pick.make, nth, nkept); Resume's doc says its walk; docs: the reference's "Back to a picker" (the three ways and what Ctrl-o, Resume and Lists do), the cheatsheet's Ctrl-o row and `SPC f l`, `SPC '`; builtins-tui.json regenerated (Lists, Resume); RUN (TEST FIRST): Pick.zig "Lists (UX L'3) ..." keeps eight lists (G left on its second row, H landed), opens Lists and asks that none was dropped and it is none of the kept, its rows `H 1/2` .. `A 1/2` newest first with H's `@pN › alpha.zig:2`, on G the body previewing beta.zig at line 2 and its rows beside with the second marked, Enter reopening G on its second row as the newest, a ninth picker dropping the oldest kept and never for Lists' room, and M-h `'` from a live J opening Lists with J first: does not build on L'2's tree (no Lists source), passes now; goldens: find (the SPC f level shows `l Lists`); with L'1 and L'2 under it: core-test 1127/1300 (173 skipped; the docs test caught `#key("Backspace")` and `#key("'")`, which name no binding: written as text, passing alone), shell-test 1348/1351 (3 skipped, the same), pane-test 183/184, behaviour-test 280/280 and --replay 280/280, process-test 2 of 147 failed before find moved (find; ttyhelp the placeholder), term-test 17/17, kitty-test 45/45; the dump fuzz (Step.search, Pick.used, landed, walking, Pardes.resume_at, picks one more) at 40,000 join seeds twice and 1,779 image seeds 13/13; the soak replicas --clients 5 --rtt 30,80,207: diverged 0, unequal 0, quiet checks 351/0 481/0 564/0, stops not on may_wait 0, the corpus 22 of 22 scenes the same, no leak; the frame and perf gate on the stack's top; load 2.4 to 13.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Core.zig | 5 +- core/Pick.zig | 182 +++++++++++++++++++++++++++++++++++++++++---- core/builtins.zig | 16 +++- core/config.zig | 1 + docs/typ/builtins-tui.json | 3 +- docs/typ/cheatsheet.typ | 4 +- docs/typ/reference.typ | 21 ++++++ test/snapshots/find.golden | 2 +- 8 files changed, 212 insertions(+), 22 deletions(-) diff --git a/core/Core.zig b/core/Core.zig index f9c4d6c9..cbcf4324 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -411,8 +411,9 @@ pipe: Pipe = .{}, /// A query pane's Grep, and its Find's listing, on a worker (Stream.zig). stream: Stream = .{}, /// The pickers: the one live in a view's tag, and the last ones rolled -/// up, which their list words and Resume reopen (Pick.zig). -picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null), +/// up, which their list words, Resume and Lists reopen (Pick.zig); Lists +/// itself in the one more, never kept. +picks: [pardes.Pick.max_lists + 1]?*pardes.Pick = @splat(null), /// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none: /// `SPC '` again after an Esc from it, nothing typed between, opens the /// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2). diff --git a/core/Pick.zig b/core/Pick.zig index 85c16a69..0c6b1c68 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -54,8 +54,9 @@ const Key = pardes.Key; /// answer, SPC e's places), titled by their word, the messages' history /// (SPC h m), the themes (SPC t t, the window wearing the one under /// the cursor), and a language server's code actions for the caret's place -/// (SPC l a, the body showing the one under the cursor as its edit). -pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions }; +/// (SPC l a, the body showing the one under the cursor as its edit), and +/// the kept pickers (Lists, UX L'3). +pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions, lists }; /// Each source's word in the tag and its key cells (`␣ f Find`); a /// source whose Backspace leaves it (`back`) goes back to the SPC level of @@ -72,9 +73,11 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 .messages = .{ .word = "Messages", .keys = "h" }, .themes = .{ .word = "Themes", .keys = "t" }, .actions = .{ .word = "Actions", .keys = "la" }, + .lists = .{ .word = "Lists", .keys = "f" }, }); -/// The pickers kept after they roll up, for their list words and Resume. +/// The pickers kept after they roll up, for their list words, Resume and +/// Lists (Lists itself never one of them: Pardes.picks has one more). pub const max_lists = 8; /// Refinements a picker stacks (C-SPC). pub const max_refine = 3; @@ -147,6 +150,8 @@ act_at: u8 = 0, queue: std.ArrayList(Queued) = .empty, queue_bytes: std.ArrayList(u8) = .empty, queue_at: u32 = 0, +/// Where it last landed, `@p2 › words.zig:16` (Lists' meta, UX L'3). +landed: Kind.Buf(80) = .{}, /// Where it stands among the kept pickers, the newest the highest /// (`touch`): Resume's order (`nth`), and the oldest goes for a new one. used: u32 = 0, @@ -232,14 +237,23 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] /// A new picker in the ring, the oldest kept one dropped for it. fn make(p: *Pardes, source: Source) !*Pick { var slot: ?usize = null; - for (p.picks, 0..) |s, i| if (s == null) { + // Lists is never kept (UX L'3): the one it had goes, and it drops none + // of the kept for its room. + for (p.picks, 0..) |s, i| if (s) |pk| if (source == .lists and pk.source == .lists) { + pk.deinit(p.gpa); + p.gpa.destroy(pk); + p.picks[i] = null; + slot = i; + break; + }; + if (slot == null and (source == .lists or nkept(p) < max_lists)) for (p.picks, 0..) |s, i| if (s == null) { slot = i; break; }; if (slot == null) { // The oldest not live. var oldest: ?usize = null; - for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) { + for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and pk.source != .lists and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) { oldest = i; }; const i = oldest orelse return error.NoPickerSlots; @@ -277,7 +291,7 @@ fn nth(p: *const Pardes, k: usize) ?*Pick { var found: ?*Pick = null; for (0..k) |_| { found = null; - for (p.picks) |slot| if (slot) |pk| if (rank(pk) < below and (found == null or rank(pk) > rank(found.?))) { + for (p.picks) |slot| if (slot) |pk| if (pk.source != .lists and rank(pk) < below and (found == null or rank(pk) > rank(found.?))) { found = pk; }; below = rank(found orelse return null); @@ -285,10 +299,12 @@ fn nth(p: *const Pardes, k: usize) ?*Pick { return found; } -/// The pickers kept. +/// The pickers kept: not Lists. fn nkept(p: *const Pardes) usize { var n: usize = 0; - for (p.picks) |slot| n += @intFromBool(slot != null); + for (p.picks) |slot| if (slot) |pk| { + n += @intFromBool(pk.source != .lists); + }; return n; } @@ -376,6 +392,13 @@ fn start(p: *Pardes, pk: *Pick) void { addRows(p, pk, out.written()); }, .list => addRows(p, pk, pk.rows), + // The kept pickers, newest first, each by its list word. + .lists => for (1..max_lists + 1) |k| { + const kp = nth(p, k) orelse break; + var word: Kind.Buf(Trail.max_text) = .{}; + const text = wordOf(p, kp, &word); + pk.names.add(p.gpa, text, 0, text.len, 0, kp.id) catch return; + }, .messages => { var out: std.Io.Writer.Allocating = .init(p.gpa); defer out.deinit(); @@ -560,7 +583,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp /// `arena`. const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; -fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { +fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.mem.Allocator.Error!Row { const dir = pk.dir.slice(); if (!fuzzy(pk) and pk.source == .all) { var order: [pardes.MAX_PANES]usize = undefined; @@ -626,6 +649,14 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const f = owner.file orelse return row; row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; }, + // A kept picker: where it last landed, its current row's place the + // preview (UX L'3). + .lists => { + const kp = byId(p, cand.ref) orelse return row; + row.meta = kp.landed.slice(); + const n = count(p, kp); + if (n > 0) row.target = (try rowAt(p, kp, arena, @min(kp.at, n - 1))).target; + }, // The theme in use says so, whichever the window wears (POLISH 12). .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) { row.meta = "in use"; @@ -707,10 +738,15 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n }); if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len}); if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯"); - // Themes and actions have no acts and no other sources: no second row. - if (pk.source == .themes or pk.source == .actions) { + // Themes, actions and Lists have no acts and no other sources: no + // second row. + if (pk.source == .themes or pk.source == .actions or pk.source == .lists) { const hints = text.items.len; - try b.styled(if (pk.source == .themes) "⏎ wear it · esc" else "⏎ or 1-9 apply it · esc", .dim); + try b.styled(switch (pk.source) { + .themes => "⏎ wear it · esc", + .lists => "⏎ reopen it · esc", + else => "⏎ or 1-9 apply it · esc", + }, .dim); try b.right(counted, hints); var h = b.done(); h.caret = caret; @@ -732,7 +768,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const nacts = nw; offer[nw] = "|"; nw += 1; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != pk.source) { + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != .lists and src != pk.source) { offer[nw] = words.get(src).word; nw += 1; }; @@ -778,8 +814,9 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const pk = live(p) orelse return &.{}; const s = &p.view().tag_state; const n = count(p, pk); - const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts) 2 else 1); + const out = try arena.alloc(Band.Step, if (pk.spine == .sources or pk.spine == .acts or pk.source == .lists) 2 else 1); if (pk.spine == .acts) out[1] = try actStep(p, pk, arena); + if (pk.source == .lists) out[1] = try listedStep(p, pk, arena); if (pk.spine == .sources) { const rows = try arena.alloc(Band.Row, spine_rows.len); for (spine_rows, rows, 0..) |src, *row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ src.key, src.word }), .key = 1, .index = @intCast(i), .dim = src.source == pk.source }; @@ -825,6 +862,18 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { return out; } +/// Lists' second step (UX L'3): the kept picker under its cursor, its +/// rows around its own cursor, which is marked `▶`; read, never a list. +fn listedStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step { + const kp = byId(p, @intCast(refAt(p, pk) orelse return .{ .doc = true })) orelse return .{ .doc = true }; + const n = count(p, kp); + const lo = if (kp.at < Band.Cursor.shown) 0 else kp.at + 1 - Band.Cursor.shown; + const hi = @min(n, lo + Band.Cursor.shown); + const rows = try arena.alloc(Band.Row, hi -| lo); + for (rows, lo..) |*row, i| row.* = .{ .text = try std.fmt.allocPrint(arena, "{s}{s}", .{ if (i == kp.at) "▶ " else " ", (try rowAt(p, kp, arena, i)).text }) }; + return .{ .rows = rows, .doc = true }; +} + // ---- the preview ---- /// The line (from 0) pane `pane`'s body lands the live picker's cursor row @@ -854,7 +903,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi /// previewing. pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { const pk = live(p) orelse return null; - if (!pk.previews or pk.source == .themes or pk.source == .actions) return null; + if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists) return null; if (pk.landing == pk.owner) { w.writeAll("⏎ lands here") catch return null; } else { @@ -1170,7 +1219,8 @@ pub fn key(p: *Pardes, k: Key) void { // Themes: Enter wears the one under the cursor; actions: Enter, or an // action's digit with the field empty, applies it; the rows and the // field. - if (pk.source == .themes or pk.source == .actions) { + if (pk.source == .themes or pk.source == .actions or pk.source == .lists) { + if (plain and k.cp == Key.enter and pk.source == .lists) return reopenListed(p, pk); if (plain and k.cp == Key.enter and pk.source == .themes) { const at = refAt(p, pk) orelse return; TagState.toRest(p); @@ -1246,6 +1296,7 @@ const spine_rows = [_]struct { key: u8, word: []const u8, source: ?Source }{ .{ .key = 'b', .word = "Panes", .source = .panes }, .{ .key = 's', .word = "Symbols", .source = .symbols }, .{ .key = '/', .word = "All", .source = .all }, + .{ .key = '\'', .word = "Lists", .source = .lists }, .{ .key = '?', .word = "Help", .source = null }, }; @@ -1261,6 +1312,13 @@ fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void { p.view().tag_state.field.set(query.slice()); return TagState.filter(p); }; + // Lists is a picker of the kept ones, this one among them: one of its + // own, from where this one was asked (UX L'3). + if (to == .lists) { + const from = p.paneBySerial(pk.owner) orelse p.view().active; + TagState.toRest(p); + return open(p, from, to, "", "", ""); + } if (p.stream.target == pk.id) _ = p.stream.stop(); for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa); for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa); @@ -1505,6 +1563,9 @@ fn land(p: *Pardes, wanted: How) void { _ = look.open(p, from, at.path, at.at, .below); }, }; + if (picked[0] == .place) if (p.panes[v.active]) |at| if (at.file) |f| { + _ = pk.landed.print(config.pane_addr ++ "{d} › {s}:{d}", .{ at.serial, std.Io.Dir.path.basename(f.path), at.body.cur_row + 1 }); + }; if (how == .queue and pk.queue.items.len > 0) { var said: Kind.Buf(64) = .{}; p.setMessage(.at(v.active), said.print("Walk: {d} more places here, C-i for the next", .{pk.queue.items.len})); @@ -1659,9 +1720,22 @@ pub fn keyAtRest(p: *Pardes, k: Key) void { /// B3 on a picker's row (mouse.zig bandPress): Enter on it. pub fn landHere(p: *Pardes) void { const pk = live(p) orelse return; + if (pk.source == .lists) return reopenListed(p, pk); if (pk.spine == .rows) land(p, .walk); } +/// Enter in Lists (UX L'3): the kept picker under its cursor unrolled again +/// as it was left, where Lists was asked from, and the newest now. +fn reopenListed(p: *Pardes, pk: *Pick) void { + const kp = byId(p, @intCast(refAt(p, pk) orelse return)) orelse return; + const from = p.paneBySerial(pk.owner) orelse p.view().active; + TagState.toRest(p); + touch(p, kp); + hostIn(p, kp, from) catch |err| return p.reportError(.at(from), "Lists", err); + unroll(p, kp, kp.query.slice()); + unrollRows(p, kp); +} + /// The rows an act or Enter takes: the marked, else the current. fn pickedRows(p: *Pardes, pk: *const Pick, a: std.mem.Allocator) ![]Target { const s = &p.view().tag_state; @@ -1860,6 +1934,8 @@ fn editRows(p: *Pardes, pk: *Pick) void { /// picker's. pub fn execWord(p: *Pardes, txt: []const u8) bool { const pk = live(p) orelse return false; + // Lists offers no acts and no sources (UX L'3). + if (pk.source == .lists) return false; const word = std.mem.trim(u8, txt, " \t\n"); for (spine_rows) |src| if (std.mem.eql(u8, word, src.word)) { switchTo(p, pk, src.source); @@ -3000,3 +3076,77 @@ test "SPC ' steps back through the kept pickers (UX L'2): again after an Esc, no try std.testing.expectEqualStrings("base.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path)); try std.testing.expectEqual(@as(u8, 0), p.panes[p.view().active].?.trail.cur); } + +test "Lists (UX L'3): a picker of the kept pickers, newest first, each its list word and where it last landed; the body previews the one under the cursor at its current row, its rows beside, its cursor's marked; Enter reopens it as it was left, the newest now; Lists is never kept and drops none of the eight for its room" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "one\ntwo\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "b1\nb2\n"); + defer p.gpa.free(b_path); + const base = try p.setTestFile("text\n"); + p.gpa.free(base.file.?.path); + base.file.?.path = try testFile(p, &tmp, "base.zig", "text\n"); + const rows = try std.fmt.allocPrint(p.gpa, "{s}:2:1 two\n{s}:2:1 b2\n", .{ a_path, b_path }); + defer p.gpa.free(rows); + // Eight kept: A to F, G left on its second row, H landed, the newest. + for ("ABCDEFG") |c| { + open(p, p.view().active, .list, &[_]u8{c}, "", rows); + if (c == 'G') p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + } + open(p, p.view().active, .list, "H", "", rows); + p.update(.{ .key = .{ .cp = Key.enter } }); + p.sync(); + const at = p.view().active; + var ids: [max_lists]u32 = undefined; + for (&ids, 1..) |*id, k| id.* = nth(p, max_lists + 1 - k).?.id; + exec.runBuiltin(p, .Lists, at, "", null); + const lists = live(p).?; + try std.testing.expectEqual(Source.lists, lists.source); + // None dropped for it, and it is none of the kept. + try std.testing.expectEqual(@as(usize, max_lists), nkept(p)); + for (ids) |id| try std.testing.expect(byId(p, id) != null); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + try std.testing.expectEqual(@as(usize, max_lists), count(p, lists)); + var buf: [64]u8 = undefined; + for ("HGFEDCBA", 0..) |c, i| { + const row = try rowAt(p, lists, a, i); + try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{c} {d}/2", .{ c, @as(u8, if (c == 'G') 2 else 1) }), row.text); + if (c == 'H') try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "@p{d} › alpha.zig:2", .{p.panes[at].?.serial}), row.meta); + } + // On G: the body previews its current row, beta.zig's line 2; its rows + // beside, its cursor's marked. + p.update(.{ .key = .{ .cp = Key.down } }); + settle(p); + const host = p.panes[p.paneBySerial(lists.landing).?].?; + try std.testing.expectEqualStrings(b_path, host.file.?.path); + try std.testing.expectEqual(@as(i32, 1), host.body.cur_row); + const band = try steps(p, a); + try std.testing.expect(band.len == 2 and band[1].doc and band[1].rows.len == 2); + try std.testing.expect(std.mem.startsWith(u8, band[1].rows[1].text, "▶ ") and std.mem.startsWith(u8, band[1].rows[0].text, " ")); + // Enter: G as it was left, the newest now; Lists rolled up. + p.update(.{ .key = .{ .cp = Key.enter } }); + const g = live(p).?; + try std.testing.expectEqualStrings("G", g.word.slice()); + try std.testing.expectEqual(@as(u16, 1), p.view().tag_state.rows.at); + try std.testing.expect(nth(p, 1).? == g); + p.update(.{ .key = .{ .cp = Key.escape } }); + // A ninth picker drops the oldest kept, never for Lists' room. + open(p, p.view().active, .list, "I", "", rows); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(usize, max_lists), nkept(p)); + try std.testing.expect(byId(p, ids[0]) == null and byId(p, ids[1]) != null); + // `'` among a picker's sources (M-h): Lists, from where it was asked. + open(p, p.view().active, .list, "J", "", rows); + p.update(.{ .key = .{ .cp = 'h', .alt = true } }); + p.update(.{ .key = .{ .cp = '\'', .text = "'" } }); + try std.testing.expectEqual(Source.lists, live(p).?.source); + try std.testing.expectEqualStrings("J 1/2", (try rowAt(p, live(p).?, a, 0)).text); + p.update(.{ .key = .{ .cp = Key.escape } }); +} diff --git a/core/builtins.zig b/core/builtins.zig index 7aaeee40..829935c7 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -2045,13 +2045,27 @@ pub const Forward = struct { /// Reopen the last picker as it was: its rows, marks, cursor and query. /// /// In the tag of the pane its Enter lands in from this one: this pane if it -/// reads, else its reader. `SPC '`. +/// reads, else its reader. `SPC '`; again after its Esc, nothing typed +/// between, the one before it; Ctrl-o and Ctrl-i in it, the older and newer. pub const Resume = struct { pub fn run(c: Ctx) void { pardes.Pick.resumeFrom(c.p, c.id); } }; +/// Pick from the last pickers kept, newest first: Enter reopens one as it was left. +/// +/// A row each: its source, query, cursor and marks, where it last landed at +/// its right. The body previews its current row; beside the rows, its +/// first rows. `SPC f l`, or `'` in a picker's sources (M-h). +pub const Lists = struct { + pub const scope: Scope = .session; + pub fn run(c: Ctx) void { + if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Lists: open a pane to pick from"); + pardes.Pick.open(c.p, c.id, .lists, "", "", ""); + } +}; + /// Keep this pane: a reading pane, which a jump steps, is held from now on. /// /// Its walk leaves its tag (its places, its owner): the next jump from its diff --git a/core/config.zig b/core/config.zig index d916b677..03cb6044 100644 --- a/core/config.zig +++ b/core/config.zig @@ -148,6 +148,7 @@ pub const leader_path = paths: { .Forward = "ji", .Keep = "jk", .Resume = "'", + .Lists = "fl", .Last = "jj", .Jumplist = "jl", .History = "fh", diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 9d726dc5..91757231 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -59,6 +59,7 @@ {"name": "Kill", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Stop the commands pardes started that are still running.", "text": "Stop the commands pardes started that are still running.\nThey are the lines pardes typed into a terminal (from an exec, a middle click, a pty/run) and its command panes. Bare, every one; `Kill make ls`, those whose line starts with one of the words. Each gets SIGTERM: a command pane's whole command, a terminal's foreground job, never its shell, which stays."}, {"name": "Last", "leader": "SPC j j", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Go back to the last place jumped from in another pane.", "text": "Go back to the last place jumped from in another pane.\nWith none, to the pane beside this one."}, {"name": "Left", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the left.", "text": "Move the keyboard to the pane, or column tag, to the left."}, + {"name": "Lists", "leader": "SPC f l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Pick from the last pickers kept, newest first: Enter reopens one as it was left.", "text": "Pick from the last pickers kept, newest first: Enter reopens one as it was left.\nA row each: its source, query, cursor and marks, where it last landed at its right. The body previews its current row; beside the rows, its first rows. `SPC f l`, or `'` in a picker's sources (M-h)."}, {"name": "LocationsConfig", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Set how a list's location rows are drawn: `LocationsConfig layout:inline context:2`.", "text": "Set how a list's location rows are drawn: `LocationsConfig layout:inline context:2`.\nIts fields: `context:` around each, `tscontext:on|off`, `tslocations:on|off`, `layout:inline|stacked`; those not given stay. Bare, it shows them in a +LocationsConfig."}, {"name": "Look", "leader": null, "also": ["enter", "right-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Look at its argument as B3 does: open the file or address it names, else find the word.", "text": "Look at its argument as B3 does: open the file or address it names, else find the word.\n`Look notes.txt:12` opens the file at line 12, or goes to the pane already showing it; an address may be a line, `:12:5`, `/re/`, a directory (a pane listing it) or a URL (the browser, by a plumbing rule). A relative path is found in the directory of the pane looked from, then of each pane on the jump list. Bare (Enter): the selection, else what is under the cursor."}, {"name": "LookNext", "leader": "SPC j n", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the next thing a Look would open: a place in a list, a word that names a file.", "text": "Select the next thing a Look would open: a place in a list, a word that names a file.\nThe walk goes on through the panes in order, the keyboard with it; Enter opens what it selected."}, @@ -87,7 +88,7 @@ {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor to its argument, wherever the language server finds it.", "text": "Rename the symbol under the cursor to its argument, wherever the language server finds it.\nBare, it asks for the new name. Within this file it is done at once, saying how many places changed; one that reaches other files changes nothing and lists its edits in a +Search to look over."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.", "text": "Bind this terminal as a language's REPL: an exec on that language's files is typed into it.\n`Repl python` binds it (the language named as a code fence names it: `py`, `Python`, `sh`); `Repl -` unbinds it; bare, it says what it is bound as. An exec made on the body of a file in that language (a middle click, the execute key, a single word like `ls` as much as a selection), and one made on this terminal's own body, is typed into it (bracketed paste if its program asked for that, else line by line, then Enter) instead of run. With several bound for a language, the exec asks which.\nStill commands, whatever is bound: a word in a tag, `Exec `, a ctl line, and a command word @`cmd` in the text, looked at or clicked."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump.", "text": "Replace every pane with those of a dump.\n`Restore