From 7e7d9569a008124cb7ea01b6720a8d5963b0a42f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 18:54:18 -0300 Subject: walk (pick-ui SPEC §2, §6.1, §6.5, item 1 of the Walk UI line B): a pane is held or reading: Pane.trail (core/Trail.zig: a fixed walk, max_steps 16 of max_text 256 bytes, its steps a union of place, owner, list, search and recipe, `cur` held by walk.zig, in the digest and the dumps) and `held`, set by Keep (a new builtin, `SPC j k`) and by any edit of the file (File.edit, Trail.edited, twins too); a reading pane (a file not held: no output, listing, pager, query or kind) shows Keep after its path in its tag and its tag in the reading tint (a new theme role tag_reading_bg, derived from the page and the search ground, acme the spec's #f3f0cc), under the new setting `Jumps walk|new-pane`, whose default is new-pane until the walk's pickers are in, so every tag, frame and golden is as before (a walk default changes 74 of 102 process goldens and 21 behaviour tests by the Keep word alone); TEST FIRST: Trail.zig "a file's pane is reading ..." and "Keep holds a reading pane ..."; draw.zig's three-row tag test reads its band through tagGround; docs/typ/builtins-tui.json refreshed; core-test 993/1159 (166 skipped), pane-test 183/184, behaviour-test 277/277 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/draw.zig | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'core/draw.zig') diff --git a/core/draw.zig b/core/draw.zig index ff76aa75..f00a7583 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -454,7 +454,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: // its ring. A pixel shell draws the ring (gui.zig gripDecor); a grid, // which cannot, marks dirty in the grip's second cell with a bold `*` // on the dirty colour, a cue that survives any palette. - const band = if (active) chrome.tag_active_bg else chrome.tag_bg; + const band = tagGround(p, pane, active); const dirty = tagline.dirty(pane); const box_bg = gripBg(p, active); const box_style: CellStyle = .{ @@ -776,7 +776,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r layer.cols = columns; layer.rows = rows; layer.context_rows = 0; - layer.bg = if (v.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg; + layer.bg = if (v.window_pick == id) p.theme().sel_bg else tagGround(p, pane, active); layer.cursor = if (v.header != null) null else if (temporary.cursor) |cursor| .{ .x = cursor.x - TAG_TEXT_INSET, .y = cursor.y, .bar = cursor.bar } else @@ -793,6 +793,14 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r } } +/// A pane's tag's ground: a reading pane's tint (its focus is its grip's), +/// else the focused tag's or the tag's. +fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 { + const chrome = p.chromeTheme(); + if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg; + return if (active) chrome.tag_active_bg else chrome.tag_bg; +} + fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { const th = p.theme(); const chrome = p.chromeTheme(); @@ -802,7 +810,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const rows = pane.tag_rows; const page_rgb = th.bg orelse th.tag_bg; // Focus is visible along the tag without changing its live text grid. - const tag_bg = if (active) chrome.tag_active_bg else chrome.tag_bg; + const tag_bg = tagGround(p, pane, active); const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg; const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }; // Padding belongs to the same font row but keeps its default ink: a @@ -1046,7 +1054,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil const top = p.tagTop(pane, r); try std.testing.expect(pane.tag_rows >= 3); const chrome = p.chromeTheme(); - const band = chrome.tag_active_bg; + const band = tagGround(p, pane, true); for (0..config.GUTTER) |dx| { const x = r.x + @as(u16, @intCast(dx)); try std.testing.expectEqual(Color{ .rgb = chrome.box }, s.at(x, top).style.bg); -- cgit v1.3 From 1c4aea3b0298f6f59ffec9b49f4d5e5f38c8af0f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 19:24:44 -0300 Subject: walk (pick-ui SPEC §6.3, §6.4, item 3 of the Walk UI line B): a reader's trail is words of its tag: its back steps before its path (`‹@p3 › rank.zig:14 › `, the owner's word written so that its Look is `@p3`, the newest shown_steps 3 whole and older ones folded to `·`, still their steps), its forward steps after it, dimmed in the theme's lineno ink (draw.zig inkTag, the name's tint loop made one with it), then Keep; the prefix is made in the room Trail.bytes measures (tagline.pathPrefix, no allocation past it), and the name's place after the words is tagline.nameAt (onName, typedIntoName, tagTintRange, the drafted name's caret); a click on a step's word is that step's Look (B1 with no drag, the one place it does more than select, and B3) or Exec (B2): a place gone back to (the later steps kept as forward steps) or forward to, the owner focused; a list, a search or a recipe word says it is not walked yet (their makers are D's and E's: Trail.lookStep, Trail.execStep); TEST FIRST: Trail.zig "the session of pick-ui §6.7: four jumps across three files, back by a click on a trail word, the later steps kept dimmed after the path, forward again, Keep, and a new reader on the next jump" and "a trail keeps its newest three back steps whole, older ones fold to ·, and a click on a · goes back to its step"; core-test 998/1164 (166 skipped), pane-test 183/184, behaviour-test 277/277 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Trail.zig | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ core/draw.zig | 44 ++++++++------ core/mouse.zig | 16 +++++- core/tagline.zig | 70 +++++++++++++++++++---- 4 files changed, 270 insertions(+), 30 deletions(-) (limited to 'core/draw.zig') diff --git a/core/Trail.zig b/core/Trail.zig index 63a57c2c..a198cae5 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -222,6 +222,92 @@ pub fn edited(p: *Pardes, f: *const panes.File.State) void { } +// ---- the words ---- + +pub const Part = enum { back, forward }; + +/// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's +/// own text; `·` when it is folded. +fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { + const s = t.steps[i]; + if (s != .owner and i < t.cur and t.cur - i > shown_steps) return "·"; + return switch (s) { + .owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits + .place => |at| std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(at.path.slice()), at.line }) catch unreachable, // a basename and a u32 fit + .list, .search, .recipe => |w| w.text.slice(), + }; +} + +const sep = " › "; + +/// The steps a part writes. +fn range(t: *const Trail, part: Part) [2]usize { + return switch (part) { + .back => .{ 0, t.cur }, + .forward => .{ @min(t.n, t.cur + 1), t.n }, + }; +} + +/// 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). +pub fn write(t: *const Trail, part: Part, w: *std.Io.Writer) std.Io.Writer.Error!void { + var buf: [max_text + 16]u8 = undefined; + const r = range(t, part); + for (r[0]..r[1]) |i| switch (part) { + .back => try w.print("{s}" ++ sep, .{wordOf(t, i, &buf)}), + .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, &buf)}), + }; +} + +/// The bytes `write` writes for `part`. +pub fn bytes(t: *const Trail, part: Part) usize { + var buf: [max_text + 16]u8 = undefined; + var n: usize = 0; + const r = range(t, part); + for (r[0]..r[1]) |i| n += wordOf(t, i, &buf).len + sep.len; + return n; +} + +/// The step whose word in `part` is at byte `off` of what `write` wrote +/// for it, null on a separator or past them. +pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 { + var buf: [max_text + 16]u8 = undefined; + var x: usize = 0; + const r = range(t, part); + for (r[0]..r[1]) |i| { + if (part == .forward) x += sep.len; + const n = wordOf(t, i, &buf).len; + if (off >= x and off < x + n) return @intCast(i); + x += n; + if (part == .back) x += sep.len; + } + return null; +} + +/// Look on step `i` of pane `id`'s trail (§6.3): a place is gone back or +/// forward to, the owner focused; a list, a search or a recipe is the +/// pickers' and the prompts' to take (not yet: said). +pub fn lookStep(p: *Pardes, id: usize, i: u8) void { + const pane = p.panes[id] orelse return; + switch (pane.trail.steps[i]) { + .place => _ = go(p, id, i) catch |err| p.reportError(.at(id), "walk", err), + .owner => |serial| if (p.paneBySerial(serial)) |owner| { + p.view().active = owner; + } else p.reportFailure(id, "walk: its owner is closed"), + .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not walked yet"), + } +} + +/// Exec on step `i` (§6.3): a place and the owner as Look; a list runs its +/// source again, a search searches again, a recipe replays (not yet). +pub fn execStep(p: *Pardes, id: usize, i: u8) void { + const pane = p.panes[id] orelse return; + switch (pane.trail.steps[i]) { + .place, .owner => lookStep(p, id, i), + .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not run again yet"), + } +} + fn typeKeys(p: *Pardes, keys: []const u8) void { for (keys) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); } @@ -416,3 +502,87 @@ test "the reader of a held pane too short to halve goes to the bottom of the nex const reader_id = f.p.view().active; try std.testing.expectEqual(col + 1, layout.findPane(f.p, reader_id).?.col); } + +/// Where `word` starts in pane `id`'s tag, on the screen. +fn tagCell(p: *Pardes, id: usize, word: []const u8) ![2]u16 { + const pane = p.panes[id].?; + const tag = try tagOf(p, pane); + const i = std.mem.indexOf(u8, tag, word) orelse return error.NotInTag; + const r = p.view().rects[id]; + return .{ r.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, tag[0..i]))), p.tagTop(pane, r) }; +} + +/// A click with `button` on `word` in pane `id`'s tag: a press and a +/// release on its first cell. +fn clickTag(p: *Pardes, id: usize, word: []const u8, button: pardes.Mouse.Button) !void { + const at = try tagCell(p, id, word); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| p.update(.{ .mouse = .{ .button = button, .kind = kind, .col = at[0], .row = at[1] } }); + p.sync(); +} + +test "the session of pick-ui §6.7: four jumps across three files, back by a click on a trail word, the later steps kept dimmed after the path, forward again, Keep, and a new reader on the next jump" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + const owner = p.panes[f.held].?.serial; + var buf: [4096 + 128]u8 = undefined; + var at: [64]u8 = undefined; + // 1 · g d on rank from the held pane: its reader, made below it. + f.look(f.held, "rank.zig", 12); + // 2 · Look at Place.of from line 14 of rank.zig: the reader walks. + typeKeys(p, "2j"); + f.look(p.view().active, "place.zig", 8); + // 3 · g d on Span from line 9: one more step in the same file. + typeKeys(p, "j"); + f.look(p.view().active, "place.zig", 40); + var r = p.view().active; + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:14 › place.zig:9 › {s}/place.zig Keep ", .{ owner, f.dir }))); + // 4 · a click on rank.zig:14: back, the later steps after the path, + // dimmed. + try clickTag(p, r, "rank.zig:14", .left); + r = p.view().active; + try std.testing.expectEqualStrings("rank.zig:14", f.at(&at)); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "‹@p{d} › {s}/rank.zig › place.zig:9 › place.zig:40 Keep ", .{ owner, f.dir }))); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const dim = try tagCell(p, r, "place.zig:40"); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().lineno }, s.at(dim[0], dim[1]).style.fg); + // A click on a forward step goes forward to it. + try clickTag(p, r, "place.zig:9", .left); + r = p.view().active; + try std.testing.expectEqualStrings("place.zig:9", f.at(&at)); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:14 › {s}/place.zig › place.zig:40 Keep ", .{ owner, f.dir }))); + // Exec (B2) on the owner's word: the owner has the keyboard. + try clickTag(p, r, "‹@p", .middle); + try std.testing.expectEqual(f.held, p.view().active); + // A new step from the reader drops the forward steps. + f.look(r, "rank.zig", 50); + r = p.view().active; + try std.testing.expectEqual(p.panes[r].?.trail.cur + 1, p.panes[r].?.trail.n); + // 5 · Keep: the walk leaves its tag; the next jump from the owner + // makes a new reader. + pardes.exec.runBuiltin(p, .Keep, r, "Keep", null); + p.sync(); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "{s}/rank.zig Save", .{f.dir}))); + f.look(f.held, "place.zig", 20); + const fresh = p.view().active; + try std.testing.expect(fresh != r and fresh != f.held and p.panes[r] != null); + try std.testing.expectEqual(owner, p.panes[fresh].?.trail.steps[0].owner); +} + +test "a trail keeps its newest three back steps whole, older ones fold to ·, and a click on a · goes back to its step" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + const owner = p.panes[f.held].?.serial; + for ([_]usize{ 10, 20, 30, 40, 50 }) |line| f.look(f.held, "rank.zig", line); + const r = p.view().active; + var buf: [4096 + 128]u8 = undefined; + var at: [64]u8 = undefined; + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "‹@p{d} › · › rank.zig:20 › rank.zig:30 › rank.zig:40 › {s}/rank.zig Keep ", .{ owner, f.dir }))); + try clickTag(p, r, "·", .right); + try std.testing.expectEqualStrings("rank.zig:10", f.at(&at)); +} diff --git a/core/draw.zig b/core/draw.zig index f00a7583..91a14c98 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -619,7 +619,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { } return null; } - var start: usize = 0; + var start: usize = tagline.nameAt(pane); const name = if (pane.file) |file| if (pane.prompt == .name) pane.input.own orelse file.path else file.path else if (pane.addon) |k| blk: { @@ -793,6 +793,25 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r } } +/// Bytes `lo` to `hi` of a tag's text in `ink`, over whichever of its +/// shown rows (`lines`, from shown row `top`, drawn at `x`, `y`, `w` +/// wide) they wrapped onto. +fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const u8, top: usize, x: u16, y: u16, w: u16, lo: usize, hi: usize, ink: [3]u8) void { + const a = modal.positionAt(shown.text, shown.fromReal(lo)); + const b = modal.positionAt(shown.text, shown.fromReal(hi)); + var row = @max(a.row, top); + while (row <= b.row and row < top + lines.len) : (row += 1) { + const line = lines[row - top]; + const from = if (row == a.row) a.col else 0; + const to = if (row == b.row) b.col else line.len; + var col = panes.File.rawDisplayCol(p.settings.tab, line, @min(from, line.len)); + const end = panes.File.rawDisplayCol(p.settings.tab, line, @min(to, line.len)); + const row_y = y + @as(u16, @intCast(row - top)); + while (col < end and col < w) : (col += 1) + s.at(x + @as(u16, @intCast(col)), row_y).style.fg = .{ .rgb = ink }; + } +} + /// A pane's tag's ground: a reading pane's tint (its focus is its grip's), /// else the focused tag's or the tag's. fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 { @@ -840,7 +859,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, else if (pane.prompt == .name) caret: { // A drafted name is the prefix: its caret is on row 0 of the tag, // the rows it wrapped onto included. - const at = modal.positionAt(shown.text, shown.fromReal(@intCast(@max(0, pane.input.cur_col)))); + const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); if (at.row < top or at.row >= top + rows) break :caret null; break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) }; } else if (pane.focus == .tag and pane.prompt == .none) caret: { @@ -860,22 +879,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, // The name's tint, in the tag's first line, over whichever rows it // wrapped onto. const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len]; - if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi) { - const name_fg = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg; - const a = modal.positionAt(shown.text, shown.fromReal(name.lo)); - const b = modal.positionAt(shown.text, shown.fromReal(@min(name.hi, first_line.len))); - var row = @max(a.row, top); - while (row <= b.row and row < top + rows) : (row += 1) { - const line = lines[row - top]; - const from = if (row == a.row) a.col else 0; - const to = if (row == b.row) b.col else line.len; - var col = panes.File.rawDisplayCol(p.settings.tab, line, @min(from, line.len)); - const end = panes.File.rawDisplayCol(p.settings.tab, line, @min(to, line.len)); - const y = tag_y + @as(u16, @intCast(row - top)); - while (col < end and col < tw) : (col += 1) - s.at(tx + @as(u16, @intCast(col)), y).style.fg = .{ .rgb = name_fg }; - } - }; + if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi) + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg); + // A walk's forward steps, after the name, dimmed (Trail.zig). + const ahead = tagline.forwardSpan(pane); + if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno); // The tag's own selections, while it has the keyboard, a line at a // time. A range of one grapheme is the block cursor, not a selection. if (pane.focus == .tag) { diff --git a/core/mouse.zig b/core/mouse.zig index 14700995..1356ace4 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -1211,8 +1211,12 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { // click on the path, if it can be renamed, drafts a name. const row: usize = @intCast(@max(0, sl.r1)); const col: usize = @intCast(@max(0, sl.c1)); - if (!dragged and tagline.onName(p.settings.tab, pane, row, col)) { - tagline.draftName(p, pane, col); + // A plain click on a word of its walk is its Look + // (pick-ui SPEC §6.3): the one place B1 does more than + // select. + if (!dragged and tagline.trailClick(p, s.id, row, col, false)) return; + if (if (dragged) null else tagline.onName(p.settings.tab, pane, row, col)) |at| { + tagline.draftName(p, pane, at); } else if (tagline.tagOffsetAt(p, pane, row, col)) |cursor| { pane.tag.cur_row = @intCast(cursor.row); pane.tag.cur_col = @intCast(cursor.col); @@ -1278,6 +1282,14 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { return; } }; + // On a word of the tag's walk: that step's Look or Exec + // (Trail.zig), not the word's. + if (clk.r0 >= 0 and clk.r0 < pane.tag_rows and clk.r0 == clk.r1 and clk.c0 == clk.c1 and clk.c0 >= 0 and + tagline.trailClick(p, s.id, @intCast(clk.r0), @intCast(clk.c0), s.button == config.exec_button)) + { + pane.sel[b].state = .none; + return; + } var operand = exec.operandAt(p, pane, clk, true, s.button == config.look_button); if (operand.expanded) |expanded| pane.sel[b] = expanded diff --git a/core/tagline.zig b/core/tagline.zig index 1cab2166..451198fd 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -157,8 +157,18 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co // while a jump would step it (Trail.zig). if (pane.file) |f| { const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; - if (!pardes.Trail.reading(p, pane)) return name; - return std.mem.concat(arena, u8, &.{ name, " Keep" }); + const keep = pardes.Trail.reading(p, pane); + if (pane.trail.n == 0 and !keep) return name; + // Its walk's back steps before the name, its forward steps after + // it (Trail.zig), in the room `bytes` measures them. + const keep_word = if (keep) " Keep" else ""; + const room = try arena.alloc(u8, pane.trail.bytes(.back) + name.len + pane.trail.bytes(.forward) + keep_word.len); + var w: std.Io.Writer = .fixed(room); + pane.trail.write(.back, &w) catch return error.OutOfMemory; + w.writeAll(name) catch return error.OutOfMemory; + pane.trail.write(.forward, &w) catch return error.OutOfMemory; + w.writeAll(keep_word) catch return error.OutOfMemory; + return w.buffered(); } // A terminal showing kitty graphics says how it draws them, as an image // pane does, and so does one drawing them as glyph art by choice. @@ -171,6 +181,37 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co return (try shownDir(arena, pane)); } +/// Where a file's name starts in its tag: after its walk's back steps. +pub fn nameAt(pane: *const Pane) usize { + return if (pane.file != null) pane.trail.bytes(.back) else 0; +} + +/// The bytes of a file's tag its walk's forward steps take, after its name. +pub fn forwardSpan(pane: *const Pane) [2]usize { + const f = pane.file orelse return .{ 0, 0 }; + const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; + const lo = pane.trail.bytes(.back) + name.len; + return .{ lo, lo + pane.trail.bytes(.forward) }; +} + +/// A click at shown row `row`, display column `col` of pane `id`'s tag on +/// a word of its walk: that step's Look, or with `run` its Exec +/// (Trail.zig, pick-ui SPEC §6.3). True when it was on one. +pub fn trailClick(p: *Pardes, id: usize, row: usize, col: usize, run: bool) bool { + const pane = p.panes[id] orelse return false; + if (pane.trail.n == 0 or pane.file == null) return false; + const at = tagOffsetAt(p, pane, row, col) orelse return false; + if (at.row != 0) return false; + const lead = nameAt(pane); + const ahead = forwardSpan(pane); + const step = if (at.col < lead) + pane.trail.stepAt(.back, at.col) + else if (at.col >= ahead[0] and at.col < ahead[1]) pane.trail.stepAt(.forward, at.col - ahead[0]) else null; + const i = step orelse return false; + if (run) pardes.Trail.execStep(p, id, i) else pardes.Trail.lookStep(p, id, i); + return true; +} + pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 { return prefixIn(p, p.scratch.allocator(), pane); } @@ -347,14 +388,20 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso return modal.positionAt(whole, @min(shown.toReal(off), whole.len)); } -/// Whether display column `col` of the tag's shown row `row` is on a name -/// a click drafts: a saving file's path. -pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) bool { - if (row + pane.tag_top != 0) return false; - const f = pane.file orelse return false; - if (!panes.Output.fileTraits(f.output).saves) return false; +/// The display column in the name a click drafts at display column `col` +/// of the tag's shown row `row`: on a saving file's path, after its walk's +/// words; null off it. +pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) ?usize { + if (row + pane.tag_top != 0) return null; + const f = pane.file orelse return null; + if (!panes.Output.fileTraits(f.output).saves) return null; const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; - return col < panes.File.displayWidth(tab, name); + var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; + var w: std.Io.Writer = .fixed(&room); + pane.trail.write(.back, &w) catch return null; + const lead = panes.File.displayWidth(tab, w.buffered()); + if (col < lead or col >= lead + panes.File.displayWidth(tab, name)) return null; + return col - lead; } /// A key typed into a saving file's path, with the tag's cursor there, @@ -364,7 +411,10 @@ pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) bool { pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { const f = pane.file orelse return false; if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false; - const at: usize = @intCast(@max(0, pane.tag.cur_col)); + // The name starts after its walk's words. + const col: usize = @intCast(@max(0, pane.tag.cur_col)); + if (col < nameAt(pane)) return false; + const at = col - nameAt(pane); const back = key.cp == pardes.Key.backspace or pardes.hit(key, config.insert_backspace_alias); const forward = key.cp == pardes.Key.delete or pardes.hit(key, config.insert_delete_alias); const typed = key.text.len > 0 and !key.ctrl and !key.alt; -- cgit v1.3