From 920aaa6e6c2317aa775937b01f727fa9418b7db2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 04:58:53 -0300 Subject: tagline, Trail, Core, layout: the tag out of rest is the owner's word, the newest step's and the head, nothing else (walk UI polish P1, UX DESIGN.md D1, the coordinator's R1-CORRECTED: the user's "why the tagline is still showing the regular tagline text?"): out of rest the path, Keep, the forward steps, the progress and the tag's own words were drawn before the head, so the key cells and the band's spines hung 40-50 columns in (shot 02's spines at column 50) and a picker's tag named the PREVIEWED file as the pane's own (shot 04: `/tmp/.../core/Store.zig ␣ f Find re 2/3`); now `‹@p1 › rank.zig:20 › ␣ ▸ b buffer…`, the head from the tag's first text column when there is no walk (`␣ f Find re`), the spines at columns 2-4; THE CHANGE: Trail.Part `.newest` writes the owner's word and the newest back step's alone, each with ` › `, a word past 24 cells cut in its middle with `…` (D1 item 4), and `stepAt(.newest)` maps a Look or Exec on any of its cells to that step; tagline.pathPrefix returns it while Trail.outOfRest (the live view's host is the pane: asking is rest and keeps its path), the old body now `restPath`; `restPrefix`, the prefix as at rest whatever the state, is what Core.sync measures `tag_lead` by (the tag's cursor and selections are offsets in its text at rest: a head over its own text moves none of them; on the shown prefix they were shifted by the path's length and back, and `| in a tag pipes the tag's own text` piped 4 wrong bytes) and what layout.wantedTagRows counts the rest rows with (a tag out of rest keeps them at least); the heads no longer lead with a space (TagState's Help/Keys/Rename/level, Pick.head, Prompt.head: the out-of-rest prefix ends in its own ` › `); no name tint, forward-step ink, unlit search word or progress out of rest (draw.zig tagTintRange, paintPaneTag; Prompt.unlit); tagline.onName and forwardSpan are off out of rest; `Trail.folded` is gone (it only told out of rest, now `.newest`: at rest it is `shown_steps`), `nameAt` takes no Pardes; TEST FIRST: Trail.zig "Enter on a word of the walk ...": out of rest `‹@pN › rank.zig:20 › ␣ ▸ ` with no older step, no directory, no Keep (on the base `‹@pN › · › rank.zig:20 › /rank.zig`: fails), a step back hides its forward step out of rest, Look maps the newest word and the owner's to their steps, and the tag at rest byte-identical after Esc; Pick.zig's reader test: the picker's head starts the tag's text (`␣ f Find pick 1/1`), no previewed path; the heads' other tests drop their leading space; test/behaviour keys.zig's prompt case reads the tag file out of rest as the head alone (`s zq`, no `/test.txt`); behaviour-test 277/277; core-test 1062/1232 (170 skipped); process-test: 8 goldens regenerated and read, each changed row the out-of-rest tag with no path (leader, pipe, msg, selregex, find, fsearch, lsp, ttyhelp: the band's spines at columns 2-4, the steps right of them, the rows no longer pushed onto a second tag row; msg's `s EXT` head and fsearch's `/` head still wrap their hints mid-word: D3's); a user meets it in every state out of rest 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/Band.zig | 2 +- core/Command.zig | 18 +++++------ core/Core.zig | 5 ++- core/Pick.zig | 5 +-- core/Prompt.zig | 22 ++++++------- core/TagState.zig | 38 +++++++++++------------ core/Trail.zig | 93 +++++++++++++++++++++++++++++++++++++++++++++---------- core/bindings.zig | 10 +++--- core/draw.zig | 11 ++++--- core/layout.zig | 2 +- core/lsp/Ask.zig | 2 +- core/tagline.zig | 51 +++++++++++++++++++++++------- 12 files changed, 176 insertions(+), 83 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 835c249f..2fcf4a3b 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -555,7 +555,7 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme()); try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null); // The head names the level and says how to roll it up. - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, frame.allocator(), pane), " ␣ SPC ↑ roll up · ? field · esc")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, frame.allocator(), pane), "␣ SPC ↑ roll up · ? field · esc")); // Down moves the cursor; Up back to the first row, then rolls up. p.update(.{ .key = .{ .cp = Key.down } }); try std.testing.expectEqual(@as(u8, 'c'), p.view().tag_state.hi); diff --git a/core/Command.zig b/core/Command.zig index 55c336f1..334d49a2 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -685,7 +685,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqual(Prompt.Op.command, s.prompt.op); try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus); // The head: its key cell, the field, the count, the hints. - try std.testing.expect(has(try tagOf(p), " : 16 commands Tab complete · ⏎ run · C-r history · esc")); + try std.testing.expect(has(try tagOf(p), ": 16 commands Tab complete · ⏎ run · C-r history · esc")); // The rows: the tag's words in its order, `in the tag`, the last ruled // off; then the commands, each what it takes. try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save ")); @@ -700,7 +700,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expect(has(first[7].text, "theme") and has(first[7].text, "")); // Typing filters both, by the scorer, in their order. typeKeys(p, "th"); - try std.testing.expect(has(try tagOf(p), " : th = Exec th 1 command ")); + try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command ")); try std.testing.expect(has(try bandRow(p, a, 0), "▶ theme ")); // Tab: the command, a space after it; the field's plain word is its // pardes word once it is whole. @@ -708,7 +708,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqualStrings("theme ", s.field.text()); typeKeys(p, "acme"); const worn = colors.themes[p.theme_preview.?].name; - try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, " : theme acme = Exec Theme {s} ", .{worn}))); + try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn}))); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(TagState.Kind.rest, s.kind); try std.testing.expectEqualStrings(worn, p.theme().name); @@ -718,7 +718,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, // `:sort`: the selections piped through sort, as `|sort` does. while (p.nextEffect()) |_| {} typeKeys(p, "%:sort"); - try std.testing.expect(has(try tagOf(p), " : sort = Exec Edit |sort 1 command")); + try std.testing.expect(has(try tagOf(p), ": sort = Exec Edit |sort 1 command")); p.update(.{ .key = .{ .cp = Key.enter } }); var asked: ?u32 = null; while (p.nextEffect()) |effect| if (effect == .pipe) { @@ -727,7 +727,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqualStrings("sort", p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?.command); // `:goto 2`: Look `:2`. typeKeys(p, ":goto 2"); - try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 ")); + try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 ")); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); // S-Tab: the last row; Tab after it, round to the first. A tag word @@ -819,9 +819,9 @@ test ":theme lists the themes and the whole window wears the current one, none d try std.testing.expectEqual(Rows.values, s.prompt.command.rows); try std.testing.expectEqual(@as(u16, 2), s.nhits); try std.testing.expect(has(try bandRow(p, a, 0), "▶ on now")); - try std.testing.expect(has(try tagOf(p), " : set Wrap = Exec Wrap 2 values ")); + try std.testing.expect(has(try tagOf(p), ": set Wrap = Exec Wrap 2 values ")); typeKeys(p, "of"); - try std.testing.expect(has(try tagOf(p), " : set Wrap of = Exec Wrap of 1 value ")); + try std.testing.expect(has(try tagOf(p), ": set Wrap of = Exec Wrap of 1 value ")); p.update(.{ .key = .{ .cp = Key.tab } }); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(!p.settings.wrap); @@ -843,7 +843,7 @@ test ":theme lists the themes and the whole window wears the current one, none d // :open: the line goes to Find, the rest of it the query, the keys // after it typed into Find's field. typeKeys(p, ":o"); - try std.testing.expect(has(try tagOf(p), " : o = Exec Find ")); + try std.testing.expect(has(try tagOf(p), ": o = Exec Find ")); typeKeys(p, " te"); try std.testing.expectEqual(TagState.Kind.pick, s.kind); try std.testing.expectEqual(pardes.Pick.Source.find, pardes.Pick.live(p).?.source); @@ -885,7 +885,7 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne typeKeys(p, ":"); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("goto 2", s.field.text()); - try std.testing.expect(has(try tagOf(p), " : goto 2 = Look :2 ")); + try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 ")); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("set Wrap off", s.field.text()); try std.testing.expectEqual(Rows.values, s.prompt.command.rows); diff --git a/core/Core.zig b/core/Core.zig index 2c04cc64..e43f9e83 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2010,7 +2010,10 @@ pub fn sync(p: *Pardes) void { var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); const wa = wrap_fba.allocator(); const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null; - const lead = if (prefix) |made| made.len else pane.tag_lead; + // The tag's cursor and selections are offsets in its text at rest: + // a head shown over its own text moves none of them (UX D1). + const at_rest = if (pardes.Trail.outOfRest(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; + const lead = if (at_rest) |made| made.len else pane.tag_lead; if (lead != pane.tag_lead) { const t = &pane.tag; const old: i32 = @intCast(pane.tag_lead); diff --git a/core/Pick.zig b/core/Pick.zig index 3bab0970..f4e26527 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -566,7 +566,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const s = &p.view().tag_state; var text: std.ArrayList(u8) = .empty; var spans: std.ArrayList(TagState.Span) = .empty; - try text.append(arena, ' '); var cells: [4][2]u32 = undefined; var ncells: usize = 0; // SPC's cell, then its keys': `␣ f`. @@ -1528,7 +1527,9 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the defer frame.deinit(); const a = frame.allocator(); const tag = try tagOf(p, a, reader); - try std.testing.expect(std.mem.indexOf(u8, tag, " ␣ f Find pick 1/1\n") != null); + // Out of rest no path (UX D1): not the previewed file's, not Keep; + // the head starts the tag's text. + try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick 1/1\n")); try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null); // The body previews the row's file, after a frame of its own. p.update(.tick); diff --git a/core/Prompt.zig b/core/Prompt.zig index 64e030e0..10886606 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -809,8 +809,9 @@ pub fn execWord(p: *Pardes, id: usize) void { /// The span of pane `pane`'s tag its search word takes while its places no /// longer light it (the first Esc cleared them): drawn dimmed (draw.zig). pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { + if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; - const whole = Trail.folded(p, pane); + const whole = Trail.shown_steps; for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { if (lights(pane, &step.search) or t.cur - i > whole) return null; return t.spanOf(i, whole); @@ -1056,14 +1057,13 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_: } } -/// The head of the prompt's tag: ` s self▌ = Exec Edit x/self/ 4 +/// The head of the prompt's tag: `s self▌ = Exec Edit x/self/ 4 /// selections in 6 lines ⏎ select · M-⏎ as a list · C-r history · esc`. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { const s = &p.view().tag_state; const pr = &s.prompt; var text: std.ArrayList(u8) = .empty; var spans: std.ArrayList(TagState.Span) = .empty; - try text.append(arena, ' '); try styled(arena, &text, &spans, info.get(pr.op).cell, .key); try text.append(arena, ' '); const caret: u32 = @intCast(text.items.len + s.field.caret); @@ -1269,9 +1269,9 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind); // No chip on the notice band: the prompt is the tag's. try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); - try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " s ⏎ select · M-⏎ as a list · C-r history · esc")); + try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc")); typeKeys(p, "self"); - try std.testing.expect(has(try tagOf(p), " s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); + try std.testing.expect(has(try tagOf(p), "s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); try std.testing.expect(selecting(p, pane).?.dim == false); // No match: 0, and the selection it began with. @@ -1310,10 +1310,10 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba typeKeys(p, "K"); p.update(.{ .key = .{ .cp = Key.up } }); try std.testing.expectEqualStrings("self..", p.view().tag_state.field.text()); - try std.testing.expect(has(try tagOf(p), " K self.. = Exec Edit g/self../ keeps 2 of 2")); + try std.testing.expect(has(try tagOf(p), "K self.. = Exec Edit g/self../ keeps 2 of 2")); p.update(.{ .key = .{ .cp = Key.down } }); typeKeys(p, "b"); - try std.testing.expect(has(try tagOf(p), " K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep")); + try std.testing.expect(has(try tagOf(p), "K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep")); // Ctrl-r: the history under the tag, a row a line. p.update(.{ .key = .{ .cp = 'r', .ctrl = true } }); try std.testing.expectEqual(@as(u16, 1), Band.takes(p, p.view().active)); @@ -1325,7 +1325,7 @@ test "Enter keeps what s found, the pattern in / and in the history Up brings ba typeKeys(p, "|"); try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); - try std.testing.expect(has(try tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?); var asked: ?u32 = null; @@ -1362,7 +1362,7 @@ test "/ searches the body as it is typed: the current place selected, the gutter pane.body.cur_row = 2; pane.body.cur_col = 6; typeKeys(p, "/dirty"); - try std.testing.expect(has(try tagOf(p), " / dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); + try std.testing.expect(has(try tagOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); try std.testing.expectEqual(@as(?usize, 2), pane.places.current); try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 0)); try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1)); @@ -1409,7 +1409,7 @@ test "? searches back from the caret; no match is 0; a pattern that is no regex pane.body.cur_col = 6; const was = pane.body.primaryRange(pane.file.?.content, 0); typeKeys(p, "?dirty"); - try std.testing.expect(has(try tagOf(p), " ? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land")); + try std.testing.expect(has(try tagOf(p), "? dirty = Look ?dirty? 2/7 · 5 lines ⏎ land")); typeKeys(p, "x"); try std.testing.expect(has(try tagOf(p), "= Look ?dirtyx? 0 ⏎ land")); try std.testing.expectEqualDeep(was, pane.body.primaryRange(pane.file.?.content, 0)); @@ -1497,7 +1497,7 @@ test "a pipe prompt runs a known filter live, a run a selection: the outputs gho p.update(.{ .key = .{ .cp = Key.enter } }); typeKeys(p, "|"); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); - try std.testing.expect(has(try tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); + try std.testing.expect(has(try tagOf(p), "| tr a-z A-Z = Exec Edit |tr a-z A-Z ⋯ ⏎ replace")); const first = lastPipe(p) orelse return error.MissingLiveRun; const asked = p.pipe.pipeRequest(first).?; try std.testing.expectEqual(@as(usize, 2), asked.inputs.len); diff --git a/core/TagState.zig b/core/TagState.zig index 3bd79176..938a45d1 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -497,9 +497,10 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { switch (s.kind) { .rest => {}, // `Help`, its scope's keys, the field, its count: - // ` Help ␣ l hov 2/17`. + // `Help ␣ l hov 2/17` (out of rest the head starts the tag's + // text, after the owner's and the newest step's words: UX D1). .help => { - try b.put(" Help "); + try b.put("Help "); if (s.scope_root) |r| try b.keyCells(r, s.scope[0..s.scope_n]); var h = b.done(); h.caret = @intCast(b.text.items.len + s.field.caret); @@ -512,7 +513,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { // `Keys`, then the keys replayed: `Keys g ▸ d Def`; struck, // `runs nothing`. .describe => { - try b.put(" Keys "); + try b.put("Keys "); if (s.missed) { var buf: [64]u8 = undefined; const keys = if (s.scope_root) |r| bindings.chord(r, s.scope[0..s.scope_n], &buf) else bindings.keyName(s.scope[0]); @@ -540,9 +541,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { .pick => return @import("Pick.zig").head(p, arena, pane), .prompt => return try Prompt.head(p, arena, pane), // `Rename`, the name under the caret struck, the new one typed: - // ` Rename best → top▌ ⏎ rename · esc` (SPEC §3.5). + // `Rename best → top▌ ⏎ rename · esc` (SPEC §3.5). .rename => { - try b.put(" Rename "); + try b.put("Rename "); try b.styled(Ask.renamedWord(pane) orelse "", .strike); try b.put(" → "); var h = b.done(); @@ -555,7 +556,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { }, } const cur = current(p, v) orelse return null; - try b.put(" "); try b.keyCells(cur.root, cur.path); if (!shown(p, v)) { try b.put("…"); @@ -628,7 +628,7 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing const rest = try a.dupe(u8, try testTag(p, a)); // SPC: its cell at once, the own words gone under the head. p.update(.{ .key = .{ .cp = ' ' } }); - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " ␣ …")); + try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); // Its time is the next advance's; the level waits 250 ms from it, and // the loop wakes for it then. try std.testing.expectEqual(asked, p.view().tag_state.due_ns); @@ -638,15 +638,15 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing const woken = p.nextWake().?; try std.testing.expect(woken >= due and woken < due + pardes.frame_ns); p.clock.now_ns = due - 1; - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " ␣ …")); + try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); p.clock.now_ns = due; const level = try testTag(p, a); - try std.testing.expect(std.mem.indexOf(u8, level, " ␣ ▸ b buffer…") != null); + try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null); try std.testing.expect(std.mem.indexOf(u8, level, "l lsp…") != null); try std.testing.expect(std.mem.endsWith(u8, level, "↓ unroll · ? help")); // Down a level: its keys, its children. p.update(.{ .key = .{ .cp = 'l' } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " ␣ l ▸ a CodeAction b Callstack") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "␣ l ▸ a CodeAction b Callstack")); // Esc: rest, the tag as it was. p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqualStrings(rest, try testTag(p, a)); @@ -662,7 +662,7 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing p.clock.now_ns = g_due - 1; try std.testing.expectEqualStrings(rest, try testTag(p, a)); p.clock.now_ns = g_due; - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " g ▸ ") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "g ▸ ") != null); try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "d Def") != null); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqualStrings(rest, try testTag(p, a)); @@ -750,7 +750,7 @@ test "SPC ? is Help over every root's leaves: typed in its head, filtered by the var buf: [row_max]u8 = undefined; try std.testing.expectEqualStrings("SPC t w · Wrap · view", helpLeaf(p, s.hits[0], &buf).row); const tag = try testTag(p, a); - try std.testing.expect(std.mem.indexOf(u8, tag, " Help wrap ") != null); + try std.testing.expect(std.mem.indexOf(u8, tag, "Help wrap ") != null); // Its box says it is typed in; the band holds its rows and a doc. _ = try p.render(a); const r = p.view().rects[p.view().active]; @@ -804,10 +804,10 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc for (" hk") |c| p.update(.{ .key = .{ .cp = c } }); const s = &p.view().tag_state; try std.testing.expectEqual(Kind.describe, s.kind); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys …") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys …")); for ("gd") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(s.found); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys g ▸ d Def") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys g ▸ d Def")); // The level unrolled under the tag, the leaf on the cursor, its doc. try std.testing.expect(pane.band_rows >= 4); _ = try p.render(a); @@ -818,9 +818,9 @@ test "SPC h k is describe-key: g d replays `g ▸ d Def` with its level and doc try std.testing.expect(std.mem.indexOf(u8, text.items, "keys g d") != null); // Another sequence from the next key: ] f, then SPC l r. for ("]f") |c| p.update(.{ .key = .{ .cp = c } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ] ▸ f function") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys ] ▸ f function")); for (" lr") |c| p.update(.{ .key = .{ .cp = c } }); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " Keys ␣ l ▸ r Rename") != null); + try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "Keys ␣ l ▸ r Rename")); // Unbound: struck, runs nothing. for ("gq") |c| p.update(.{ .key = .{ .cp = c } }); try std.testing.expect(s.missed); @@ -848,14 +848,14 @@ test "C-w's level is window mode's, shown at once and kept while its keys move t const a = frame.allocator(); p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); try std.testing.expect(p.view().window_pick != null); - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), " C-w …")); + try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), "C-w …")); p.advance(p.clock.now_ns); p.clock.now_ns = p.view().tag_state.due_ns; - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null); // Sticky: a move keeps the level. p.update(.{ .key = .{ .cp = 'k' } }); try std.testing.expect(p.view().window_pick != null); - try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), " C-w ▸ ") != null); + try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "C-w ▸ ") != null); p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(p.view().window_pick == null); try std.testing.expect(p.view().tag_state.root == null); diff --git a/core/Trail.zig b/core/Trail.zig index 9223d1d3..58a72256 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -15,6 +15,7 @@ const config = @import("config.zig"); const layout = @import("layout.zig"); const panes = @import("panes.zig"); const look = @import("look.zig"); +const modal = @import("modal.zig"); const Pardes = pardes.Pardes; const Pane = panes.Pane; const Spot = look.Spot; @@ -27,7 +28,8 @@ pub const max_steps = 16; /// The bytes of a step's path or word. A jump to a longer path is no step: /// it opens a pane as `Jumps new-pane` does (look.zig open). pub const max_text = 256; -/// The newest back steps written whole; older ones fold to `·` (§6.3). +/// The newest back steps written whole at rest; older ones fold to `·` +/// (§6.3). Out of rest the owner's and the newest alone (`.newest`). pub const shown_steps = 3; /// `cur` held to the steps there are (walk.zig `.place`). @@ -311,7 +313,9 @@ pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool { // ---- the words ---- -pub const Part = enum { back, forward }; +/// `newest`: out of rest (UX D1), the owner's word and the newest back +/// step's alone, each with the separator after it. +pub const Part = enum { back, forward, newest }; /// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's /// own text; `·` when it is folded. @@ -331,19 +335,43 @@ const sep = " › "; /// The steps a part writes. fn range(t: *const Trail, part: Part) [2]usize { return switch (part) { - .back => .{ 0, t.cur }, + .back, .newest => .{ 0, t.cur }, .forward => .{ @min(t.n, t.cur + 1), t.n }, }; } +/// Whether step `i` is in what `part` writes: out of rest the owner and +/// the newest back step only. +fn writes(t: *const Trail, part: Part, i: usize) bool { + return part != .newest or t.steps[i] == .owner or i + 1 == t.cur; +} + +/// 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; + +/// Step `i`'s word as `part` writes it: out of rest a word longer than +/// `newest_cells` keeps its first and last cells around a `…`. +fn shownWord(t: *const Trail, part: Part, i: usize, whole: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) []const u8 { + const word = wordOf(t, i, whole, buf); + if (part != .newest or word.len <= newest_cells) return word; + const tab = 8; // a step's word holds no tab + if (panes.File.displayWidth(tab, word) <= newest_cells) return word; + const head = panes.File.byteAtDisplay(tab, word, newest_cells / 2); + var tail = word.len; + while (tail > head and panes.File.displayWidth(tab, word[tail..]) < newest_cells / 2 - 1) tail = modal.prevGrapheme(word, tail); + return std.fmt.bufPrint(cut, "{s}…{s}", .{ word[0..head], word[tail..] }) catch word; +} + /// 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 newest `whole` back steps whole, older ones `·` (`folded`). 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; + var cut: [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, whole, &buf)}), + for (r[0]..r[1]) |i| if (writes(t, part, i)) switch (part) { + .back, .newest => try w.print("{s}" ++ sep, .{shownWord(t, part, i, whole, &buf, &cut)}), .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, whole, &buf)}), }; } @@ -351,18 +379,21 @@ pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.I /// The bytes `write` writes for `part`. pub fn bytes(t: *const Trail, part: Part, whole: usize) usize { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; var n: usize = 0; const r = range(t, part); - for (r[0]..r[1]) |i| n += wordOf(t, i, whole, &buf).len + sep.len; + for (r[0]..r[1]) |i| if (writes(t, part, i)) { + n += shownWord(t, part, i, whole, &buf, &cut).len + sep.len; + }; return n; } -/// The back steps pane `pane`'s tag writes whole: `shown_steps` at rest, -/// the newest alone while its tag is out of rest (SPEC §3.4.3), so a -/// state's head and the band's spines keep their room. -pub fn folded(p: *const Pardes, pane: *const Pane) usize { - const host = TagState.hostOf(p) orelse return shown_steps; - return if (p.panes[host] == pane) 1 else shown_steps; +/// Whether pane `pane`'s tag is out of rest in the live view (UX D1: its +/// path, its forward steps and its own words hidden, the owner and the +/// newest step before the head). Asking is rest. +pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool { + const host = TagState.hostOf(p) orelse return false; + return p.panes[host] == pane; } /// Where back step `i`'s word is in what `write` writes for the back @@ -378,14 +409,16 @@ pub fn spanOf(t: *const Trail, i: usize, whole: usize) [2]usize { /// for it, null on a separator or past them. pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 { var buf: [max_text + 16]u8 = undefined; + var cut: [max_text + 16]u8 = undefined; var x: usize = 0; const r = range(t, part); for (r[0]..r[1]) |i| { + if (!writes(t, part, i)) continue; if (part == .forward) x += sep.len; - const n = wordOf(t, i, whole, &buf).len; + const n = shownWord(t, part, i, whole, &buf, &cut).len; if (off >= x and off < x + n) return @intCast(i); x += n; - if (part == .back) x += sep.len; + if (part != .forward) x += sep.len; } return null; } @@ -841,12 +874,38 @@ test "Enter on a word of the walk, the keyboard in the tag, goes back to its ste var at: [64]u8 = undefined; const rest = try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:10 › rank.zig:20 › {s}/rank.zig Keep", .{ owner, f.dir }); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest)); - // SPC: out of rest, the older steps are `·`, the owner and the newest - // whole; back at rest, as they were. + // SPC, its level shown: out of rest the tag is the owner, the newest + // step and the head (UX D1): no older step, no path, no Keep, none of + // its own words; back at rest, as they were. + const whole_rest = try p.gpa.dupe(u8, try tagOf(p, pane)); + defer p.gpa.free(whole_rest); p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); var folded_buf: [4096 + 128]u8 = undefined; - try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › · › rank.zig:20 › {s}/rank.zig", .{ owner, f.dir }))); + const out = try tagOf(p, pane); + try std.testing.expect(std.mem.startsWith(u8, out, try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:20 › ␣ ▸ ", .{owner}))); + try std.testing.expect(std.mem.indexOf(u8, out, "rank.zig:10") == null and std.mem.indexOf(u8, out, f.dir) == null and std.mem.indexOf(u8, out, "Keep") == null); + // Look on the newest step's word is that step. + try std.testing.expectEqual(@as(?u8, pane.trail.cur - 1), pardes.tagline.trailAt(p, pane, std.mem.indexOf(u8, out, "rank.zig:20").? + 3)); + try std.testing.expectEqual(@as(?u8, 0), pardes.tagline.trailAt(p, pane, 1)); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings(whole_rest, try tagOf(p, pane)); + // Back a step (a forward step after the path at rest): out of rest the + // forward step is hidden as the path is. + pardes.Trail.lookStep(p, r, pane.trail.cur - 1); + p.sync(); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") != null); + p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › rank.zig:10 › ␣ ▸ ", .{owner}))); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "rank.zig:30") == null); p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + pardes.Trail.lookStep(p, r, pane.trail.cur + 1); + p.sync(); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest)); // The keyboard in the tag, its cursor on `rank.zig:10`: Enter goes back // to that step, the keyboard in the body again. diff --git a/core/bindings.zig b/core/bindings.zig index 2df51945..43145b15 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -568,12 +568,12 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi p.sync(); // Its key cell at once, the level 300 ms on. p.update(.{ .key = .{ .cp = '"' } }); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), " \" …")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), "\" …")); p.advance(p.clock.now_ns); try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns); p.clock.now_ns = p.view().tag_state.due_ns; const rolled = try tagline.tagText(p, a, pane); - try std.testing.expect(std.mem.indexOf(u8, rolled, " \" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); + try std.testing.expect(std.mem.indexOf(u8, rolled, "\" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null); try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null); // Down unrolls: a row each, the cursor on the default, its value // beside them. @@ -596,13 +596,13 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi try std.testing.expect(std.mem.indexOf(u8, band.items, "return best;") != null); // Enter chooses it: its verbs, rolled. p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after P before R replace y into") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after P before R replace y into") != null); try std.testing.expect(!p.view().tag_state.unrolled); // Backspace: the registers again; a register's own key goes down too. p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" ▸ \" self.dirty") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" ▸ \" self.dirty") != null); p.update(.{ .key = .{ .cp = 'a' } }); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), " \" a ▸ p after") != null); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, a, pane), "\" a ▸ p after") != null); // p pastes it after the selection, and the tag is at rest. p.update(.{ .key = .{ .cp = 'p' } }); try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "const best = rank(q, name) orelse continue;") != null); diff --git a/core/draw.zig b/core/draw.zig index 68778667..179b7cfc 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -690,6 +690,8 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u } fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } { + // Out of rest no name is shown (UX D1). + if (pardes.Trail.outOfRest(p, pane)) return null; if (pane.isTerminal()) { // `tag` is the first row; a prefix longer than it ran to a second. var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n"); @@ -700,7 +702,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len } return null; } - var start: usize = tagline.nameAt(p, pane); + 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: { @@ -1013,7 +1015,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(tagline.nameAt(p, pane) + @as(usize, @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 and head == null) caret: { @@ -1031,8 +1033,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } // The pane's progress at its first row's right end, where the row has - // room for it (SPEC §10.2). - if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + // room for it (SPEC §10.2); out of rest the head's right block is + // there (UX D1). + if (top == 0 and rows > 0 and !pardes.Trail.outOfRest(p, pane)) for (p.messages.live[0..p.messages.live_len]) |*said| { if (said.kind != .progress or said.pane != pane.serial) continue; var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; diff --git a/core/layout.zig b/core/layout.zig index c0d21d6d..0a773cab 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -594,7 +594,7 @@ pub fn wantedTagRows(p: *Pardes, id: usize) u16 { var wrap_room: [32 * 1024]u8 = undefined; var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); const wa = wrap_fba.allocator(); - const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows; + const prefix = tagline.restPrefix(p, wa, pane) catch return pane.tag_rows; const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows; const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index bb1eccb6..6e6f87e5 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -761,7 +761,7 @@ test "SPC l r types the new name in the pane's own tag, the body showing each pl var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), " Rename best → bester") != null); + try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, a, pane), "Rename best → bester") != null); p.sync(); const sf = try p.render(a); const body = sf.region(.body, id).?.rect; diff --git a/core/tagline.zig b/core/tagline.zig index e95d68de..3256f824 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -124,6 +124,22 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { /// PDF's page, a terminal's directory -- without the space that parts it /// from the tag's own text. It is never stored, and never edited. pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { + // Out of rest (UX D1) the owner's word and the newest step's, each with + // its ` › `, before the head: the path, the forward steps and Keep + // hidden until rest (a picker's preview is no name of the pane's). + if (pardes.Trail.outOfRest(p, pane)) { + if (pane.trail.n == 0) return ""; + const room = try arena.alloc(u8, pane.trail.bytes(.newest, 1)); + var w: std.Io.Writer = .fixed(room); + pane.trail.write(.newest, 1, &w) catch return error.OutOfMemory; + return w.buffered(); + } + return restPath(p, arena, pane); +} + +/// The computed start of a pane's tag at rest, whatever its state: what +/// the tag's own text follows. +fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { // What is drawn: with no graphics, glyph art whatever `Petscii` says. if (pane.addon != null) return pardes.Kind.prefix(p, arena, pane); // A command pane: its directory, the line it runs, and how that went. @@ -163,7 +179,7 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co // 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 whole = pardes.Trail.folded(p, pane); + const whole = pardes.Trail.shown_steps; const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len); var w: std.Io.Writer = .fixed(room); pane.trail.write(.back, whole, &w) catch return error.OutOfMemory; @@ -184,15 +200,15 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co } /// Where a file's name starts in its tag: after its walk's back steps. -pub fn nameAt(p: *const Pardes, pane: *const Pane) usize { - return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.folded(p, pane)) else 0; +pub fn nameAt(pane: *const Pane) usize { + return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.shown_steps) else 0; } /// The bytes of a file's tag its walk's forward steps take, after its name. pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { const f = pane.file orelse return .{ 0, 0 }; - if (pane.trail.n == 0) return .{ 0, 0 }; - const whole = pardes.Trail.folded(p, pane); + if (pane.trail.n == 0 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 }; + const whole = pardes.Trail.shown_steps; const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; const lo = pane.trail.bytes(.back, whole) + name.len; return .{ lo, lo + pane.trail.bytes(.forward, whole) }; @@ -202,9 +218,10 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { /// text, if one is there. pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 { if (pane.trail.n == 0 or pane.file == null) return null; - const whole = pardes.Trail.folded(p, pane); + if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at); + const whole = pardes.Trail.shown_steps; const ahead = forwardSpan(p, pane); - if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at); + if (at < nameAt(pane)) return pane.trail.stepAt(.back, whole, at); if (at >= ahead[0] and at < ahead[1]) return pane.trail.stepAt(.forward, whole, at - ahead[0]); return null; } @@ -227,7 +244,17 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 { /// The prefix as the tag shows it, built in `arena`. pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - const prefix = try pathPrefix(p, arena, pane); + // Out of rest the head follows: its words end in their own space. + if (pardes.Trail.outOfRest(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane)); + return restPrefix(p, arena, pane); +} + +/// The prefix as the tag has it at rest, whatever its state: what its own +/// text follows, so what its cursor and selections are offsets after +/// (Core.sync's `tag_lead`), and the rows it takes at rest +/// (layout.wantedTagRows). +pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { + const prefix = try restPath(p, arena, pane); // The space between the prefix and the tag's own text is the text's // (every default starts with one), but the prefix is computed, so it // cannot trust the text to keep it: with it deleted, Look and Exec @@ -411,13 +438,13 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso /// words; null off it. pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize { const tab = p.settings.tab; - if (row + pane.tag_top != 0) return null; + if (row + pane.tag_top != 0 or pardes.Trail.outOfRest(p, pane)) 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; var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; var w: std.Io.Writer = .fixed(&room); - pane.trail.write(.back, pardes.Trail.folded(p, pane), &w) catch return null; + pane.trail.write(.back, pardes.Trail.shown_steps, &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; @@ -432,8 +459,8 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false; // The name starts after its walk's words. const col: usize = @intCast(@max(0, pane.tag.cur_col)); - if (col < nameAt(p, pane)) return false; - const at = col - nameAt(p, pane); + 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 From 304ea98913c178de9645cad5c3fe45a5f13e25d5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:07:21 -0300 Subject: draw: no pane dims while a tag is out of rest (walk UI polish P1, UX DESIGN.md D9): the other panes' every cell took `style.dim` while any tag was out of rest (SPEC §3.6's "slightly", built as the faint attribute: fg 12.5:1 to 4.5:1, comments 4.06:1 to 1.96:1 on neonotte84, UX A7), stacked on the user's own InactiveDim, flashed the whole screen at every SPC and repainted every pane per state change; now a tag out of rest changes its own pane and the notice row only, the others keep their look at rest (InactiveDim already applied to unfocused panes); THE CHANGE: render's pass over the other panes' cells and layers is deleted; TagState.previewing keeps its `.full` (the whole window wearing a theme, taken off at rest) and its doc says so: no pane's own bit is read any more, so Pick.unroll no longer sets the landing pane's (the field keeps its type: the wire and the dumps unchanged); TEST FIRST: Band.zig "a pane whose body would drop below four rows ... borrows them": the other pane's tag and body cells are not dim out of rest (on the base: dim, fails); core-test 1062/1232 (170 skipped); process-test: fsearch's golden regenerated and read: its `typing` style snap's left pane (the terminal) loses the `,f` (faint) on every cell, nothing else; a user saw it at every SPC, picker and prompt 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/Band.zig | 5 ++-- core/Pick.zig | 3 +-- core/TagState.zig | 6 ++--- core/draw.zig | 13 ---------- test/snapshots/fsearch.golden | 56 +++++++++++++++++++++---------------------- 5 files changed, 35 insertions(+), 48 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 2fcf4a3b..31205d87 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -595,12 +595,13 @@ test "a pane whose body would drop below four rows under its band borrows them f const r = p.view().rects[low]; try std.testing.expect(r.h > before); try std.testing.expect(r.h -| pane.tag_rows >= 4); - // The other panes dim; the one out of rest does not. + // No pane dims out of rest (UX D9): the others look as at rest. var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const s = try p.render(frame.allocator()); const other = p.view().rects[top]; - try std.testing.expect(s.at(other.x + 3, other.y).style.dim); + try std.testing.expect(!s.at(other.x + 3, other.y).style.dim); + try std.testing.expect(!s.at(other.x + 3, other.y + 1).style.dim); try std.testing.expect(!s.at(r.x + 3, r.y).style.dim); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqual(before, p.view().rects[low].h); diff --git a/core/Pick.zig b/core/Pick.zig index f4e26527..321b16b7 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -260,10 +260,9 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; pk.shown = no_row; - // The whole window previews a theme: no pane dimmed (SPEC §3.6). + // The whole window previews a theme. if (pk.source == .themes) s.previewing = .full; if (p.paneBySerial(pk.landing)) |id| { - s.previewing.set(id); const pane = p.panes[id].?; pk.aside_row = pane.body.cur_row; pk.aside_col = pane.body.cur_col; diff --git a/core/TagState.zig b/core/TagState.zig index 938a45d1..8bead506 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -79,9 +79,9 @@ miss: u8 = 0, /// The leaf each group ran last, by its key (bindings.groups): the cursor /// starts there and the rolled level underlines it (SPEC §4.3). used: [bindings.ngroups]u8 = @splat(0), -/// The panes showing a preview of what the state would do (a picker's -/// landing pane, a pane an action draws ghosts in), by slot: not dimmed -/// while the others are (SPEC §3.6). Set by the state that previews. +/// `.full` while the whole window previews a theme (a themes picker's +/// row, `:theme `'s): its own again at rest. No pane dims out of rest +/// (UX D9), so no pane's own bit is read. previewing: std.StaticBitSet(pardes.MAX_PANES) = .empty, /// describe-key (SPEC §4.5), in the tag of pane `id`: the next keys are diff --git a/core/draw.zig b/core/draw.zig index 179b7cfc..17ac7514 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -361,19 +361,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { for (s.regionList()) |region| { if (region.kind == .notice) try joinNotice(p, s, arena, region); } - // A tag out of rest: the other panes dim a little so the eye goes to - // it, but a pane showing a preview (walk UI SPEC §3.6). - if (TagState.hostOf(p)) |host| for (p.panes, 0..) |slot, id| { - if (slot == null or id == host or v.tag_state.previewing.isSet(id)) continue; - const r = v.rects[id]; - for (r.y..r.y + r.h) |y| for (r.x..r.x + r.w) |x| { - s.at(@intCast(x), @intCast(y)).style.dim = true; - }; - for ([_]*pardes.Layer{ &s.body_layers[id], &s.tag_layers[id] }) |layer| for (layer.cells[0 .. @as(usize, layer.cols) * layer.rows]) |*cell| { - cell.style.dim = true; - }; - }; - try paintHeaders(p, s); try paintNoticeRow(p, s); diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 450ea298..bf8957df 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -50,34 +50,34 @@ == style typing grid=180x31 |0: 0-1 d,#1d2824, 2-179 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#887455, 92-179 #becfc4,#314738, -|2: 0-1 d,#496656,f 2-30 #b2c3b8,#1d2824,f 31-40 #d3b0d9,#1d2824,f 41-89 #b2c3b8,#1d2824,f 90-91 #b2c3b8,#496656,f 92-120 #b2c3b8,#1d2824,f 121-130 #d3b0d9,#1d2824,f 131-179 #b2c3b8,#1d2824,f -|3: 0-0 d,#608269,f 1-1 d,#0d1410,f 2-89 #e5eee5,#0d1410,f 90-90 #e5eee5,#608269,f 91-179 #e5eee5,#0d1410,f -|4: 0-0 d,#608269,f 1-1 d,#0d1410,f 2-89 #e5eee5,#0d1410,f 90-90 #e5eee5,#608269,f 91-179 #e5eee5,#0d1410,f -|5: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|6: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|7: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|8: 0-0 d,#608269,f 1-3 d,#0d1410,f 4-89 #e5eee5,#0d1410,f 90-90 #e5eee5,#608269,f 91-179 #e5eee5,#0d1410,f -|9: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|10: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|11: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|12: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|13: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|14: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|15: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269,f 91-179 d,#0d1410,f -|16: 0-1 d,#496656,f 2-30 #b2c3b8,#1d2824,f 31-40 #d3b0d9,#1d2824,f 41-89 #b2c3b8,#1d2824,f 90-91 #000000,#add38a, 92-98 #becfc4,#2c2819, 99-99 #add38a,#2c2819,b 100-100 #add38a,#2c2819, 101-104 #becfc4,#2c2819, 105-112 #becfc4,#2c2819,f 113-138 #becfc4,#2c2819, 139-179 #becfc4,#2c2819,f -|17: 0-0 d,#608269,f 1-1 d,#0d1410,f 2-89 #e5eee5,#0d1410,f 90-91 #e5eee5,#2c2819, 92-92 #becfc4,#2c2819,f 93-179 #becfc4,#2c2819, -|18: 0-0 d,#608269,f 1-1 d,#0d1410,f 2-89 #e5eee5,#0d1410,f 90-90 #e5eee5,#e5eee5, 91-94 #e5eee5,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|19: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-91 d,#0d1410, 92-94 d,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #add38a,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, -|20: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|21: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|22: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#5e4923, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|23: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, -|24: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|25: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|26: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|27: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#5e4923, 91-93 d,#0d1410, 94-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, -|28: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|29: 0-0 d,#608269,f 1-89 d,#0d1410,f 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|2: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#496656, 92-120 #b2c3b8,#1d2824, 121-130 #d3b0d9,#1d2824, 131-179 #b2c3b8,#1d2824, +|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|4: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|5: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|6: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|7: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|8: 0-0 d,#608269, 1-3 d,#0d1410, 4-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-179 #e5eee5,#0d1410, +|9: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|10: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|11: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|12: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|13: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|14: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|15: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, +|16: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #000000,#add38a, 92-98 #becfc4,#2c2819, 99-99 #add38a,#2c2819,b 100-100 #add38a,#2c2819, 101-104 #becfc4,#2c2819, 105-112 #becfc4,#2c2819,f 113-138 #becfc4,#2c2819, 139-179 #becfc4,#2c2819,f +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-91 #e5eee5,#2c2819, 92-92 #becfc4,#2c2819,f 93-179 #becfc4,#2c2819, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#e5eee5, 91-94 #e5eee5,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-91 d,#0d1410, 92-94 d,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #add38a,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, +|20: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|22: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|23: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|25: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|26: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|27: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-93 d,#0d1410, 94-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|28: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|29: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |30: 0-1 d,#1d2824, 2-179 #67756e,#1d2824, == snap list grid=180x31 cursor=110,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 -- cgit v1.3 From c3b01a651dcee194f20a5be8da80a3f55a7235e7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:17:46 -0300 Subject: bindings, TagState, Messages: nothing changes in the tag before a root's level shows, its keys echo on the notice row's right end at once (walk UI polish P1, UX DESIGN.md D12, C2): SPC, `"` and C-w wrote their key cell into the tag at once (`at_once`), which with D1 (the path hidden out of rest) flipped the whole tag and back at every fast chord (`SPC j o`, `SPC f s`: a flash per chord, UX A16); now the tag stays exactly at rest until the root's delay passes (SPC and C-w 250 ms, `"` 300 ms, g m z [ ] Z 500 ms, on the taped clock), a sequence finished inside the delay never touches it (the spec's `gg` rule, extended to SPC), and after the delay it goes straight to D1's layout in one frame; the keys typed so far show at once at the notice row's right end (`SPC f`, vim's showcmd): TagState.pending gives the chord (bindings.chord) while a root is current and its level not shown, Messages.noticeRow appends it to the row's right part; THE CHANGE: bindings.Info's `at_once` is deleted (every root waits), TagState.hostOf is null until `shown`, and head's `…` branch for a key cell alone is gone (unreachable); TEST FIRST: TagState.zig "SPC changes nothing in the tag until its level shows 250 ms on, its keys on the notice row's right end at once ..." (on the base the tag is `␣ …` after SPC: fails), bindings.zig's registers test (`"`: the tag as at rest until 300 ms), the C-w test, "a tag out of rest keeps its rows at rest at least" (now Help's head under the rows the tag keeps: there is no key-cell-alone state left), the click and the asking tests date the level before they read it; test/behaviour keys.zig's PDF case: SPC leaves the panes as they were and the notice row ends `SPC`; core-test 1062/1232 (170 skipped); behaviour-test 277/277; process-test 0/146 failed (no golden caught the key cell alone); a user saw the flash at every leader chord 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/Messages.zig | 10 ++++++++-- core/TagState.zig | 47 +++++++++++++++++++++++++++++++---------------- core/bindings.zig | 30 +++++++++++++++--------------- test/behaviour/keys.zig | 11 ++++++++--- 4 files changed, 62 insertions(+), 36 deletions(-) (limited to 'core') diff --git a/core/Messages.zig b/core/Messages.zig index 2b63e647..dd5c232a 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -726,6 +726,10 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { r.writeAll("SPC e walk") catch {} else if (m.len > 0) r.print("{d} message{s} \u{b7} SPC h m", .{ m.len, if (m.len == 1) "" else "s" }) catch {}; + // The keys of a root whose level waits for its delay, at once (UX D12: + // vim's showcmd; the tag stays at rest until the level shows). + var keys: [64]u8 = undefined; + if (pardes.TagState.pending(p, p.view(), &keys)) |typed| r.print("{s}{s}", .{ if (r.end > 0) " " else "", typed }) catch {}; const tail = r.buffered(); // The left cut to make room for the right, a blank between them. const tail_w = panes.File.displayWidth(tab, tail); @@ -1362,9 +1366,11 @@ test "a file changed on disk under unsaved text asks in its tag and never takes try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk") == null); // The tag's own text is no one's to edit meanwhile. try std.testing.expect((try pardes.TagState.head(p, frame.allocator(), pane)) != null); - // Out of rest (SPC: its key cell at once) the level's head, not the - // question; at rest again, the question. + // Out of rest (SPC's level shown) the level's head, not the question; + // at rest again, the question. p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") == null); p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") != null); diff --git a/core/TagState.zig b/core/TagState.zig index 8bead506..96c5b9b1 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -26,6 +26,7 @@ const Band = @import("Band.zig"); const Names = @import("Names.zig"); const Prompt = @import("Prompt.zig"); const Ask = @import("lsp/Ask.zig"); +const Messages = @import("Messages.zig"); /// The tag's states besides a root's level (which `kind` rest with a root /// current is): `help`, a field over every leaf (SPEC §4.5); `describe`, @@ -192,8 +193,7 @@ pub fn hostOf(p: *const Pardes) ?usize { if (v.tag_state.kind != .rest) return for (p.panes, 0..) |slot, i| { if (slot) |pane| if (pane.serial == v.tag_state.host) break i; } else null; - const cur = current(p, v) orelse return null; - if (!bindings.info.get(cur.root).at_once and !shown(p, v)) return null; + if (current(p, v) == null or !shown(p, v)) return null; return if (p.panes[v.active] != null) v.active else null; } @@ -311,6 +311,15 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { return b.done(); } +/// The keys of the root current in view `v` while its level waits for its +/// delay (UX D12: the tag is at rest until then), as the notice row's right +/// end echoes them at once: `SPC f`. +pub fn pending(p: *const Pardes, v: *const View, buf: []u8) ?[]const u8 { + if (v.tag_state.kind != .rest or shown(p, v)) return null; + const cur = current(p, v) orelse return null; + return bindings.chord(cur.root, cur.path, buf); +} + /// The last leaf run in the current level, as the line under it says it /// (Messages' leader band): `k Hover: its summary (last used here)`, while /// the level is shown rolled. @@ -557,10 +566,6 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { } const cur = current(p, v) orelse return null; try b.keyCells(cur.root, cur.path); - if (!shown(p, v)) { - try b.put("…"); - return b.done(); - } const node = bindings.nodeAt(cur.root, cur.path) orelse return b.done(); if (s.unrolled) { try b.put(if (cur.path.len == 0) bindings.info.get(cur.root).label else node.label); @@ -614,7 +619,7 @@ fn testTag(p: *Pardes, arena: std.mem.Allocator) ![]const u8 { return tagline.tagText(p, arena, p.panes[p.view().active].?); } -test "SPC writes its key cell at once and its level 250 ms on; g changes nothing until 500 ms, and gg never" { +test "SPC changes nothing in the tag until its level shows 250 ms on, its keys on the notice row's right end at once; g nothing until 500 ms, and gg never" { const Key = pardes.Key; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); defer p.deinit(); @@ -626,9 +631,12 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing p.clock.stepped_ns = p.clock.now_ns; p.sync(); const rest = try a.dupe(u8, try testTag(p, a)); - // SPC: its cell at once, the own words gone under the head. + // SPC: the tag at rest until the level shows (UX D12), the keys typed + // at the notice row's right end at once. p.update(.{ .key = .{ .cp = ' ' } }); - try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); + try std.testing.expectEqualStrings(rest, try testTag(p, a)); + var row: [Messages.notice_row_cap]u8 = undefined; + try std.testing.expect(std.mem.endsWith(u8, Messages.noticeRow(p, 100, &row).text, "SPC")); // Its time is the next advance's; the level waits 250 ms from it, and // the loop wakes for it then. try std.testing.expectEqual(asked, p.view().tag_state.due_ns); @@ -638,7 +646,7 @@ test "SPC writes its key cell at once and its level 250 ms on; g changes nothing const woken = p.nextWake().?; try std.testing.expect(woken >= due and woken < due + pardes.frame_ns); p.clock.now_ns = due - 1; - try std.testing.expect(std.mem.eql(u8, try testTag(p, a), "␣ …")); + try std.testing.expectEqualStrings(rest, try testTag(p, a)); p.clock.now_ns = due; const level = try testTag(p, a); try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null); @@ -846,9 +854,10 @@ test "C-w's level is window mode's, shown at once and kept while its keys move t var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); + const rest = try a.dupe(u8, try testTag(p, a)); p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); try std.testing.expect(p.view().window_pick != null); - try std.testing.expect(std.mem.endsWith(u8, try testTag(p, a), "C-w …")); + try std.testing.expectEqualStrings(rest, try testTag(p, a)); p.advance(p.clock.now_ns); p.clock.now_ns = p.view().tag_state.due_ns; try std.testing.expect(std.mem.indexOf(u8, try testTag(p, a), "C-w ▸ c Collapse d Del h Left j Down k Up l Right") != null); @@ -953,7 +962,7 @@ test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC' }; } -test "a tag out of rest keeps its rows at rest at least: a root's key cell alone moves no body up" { +test "a tag out of rest keeps its rows at rest at least: a level shorter than its own text moves no body up" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 30 }); defer p.deinit(); _ = try p.setTestFile("one\n"); @@ -961,19 +970,23 @@ test "a tag out of rest keeps its rows at rest at least: a root's key cell alone p.sync(); const rows, const tag_rows = .{ pane.rows, pane.tag_rows }; try std.testing.expect(tag_rows > 1); + // Help's head, a row, its band under the rows the tag keeps. p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = '?' } }); p.sync(); try std.testing.expect(hostOf(p) != null); - try std.testing.expectEqual(tag_rows, pane.tag_rows); - try std.testing.expectEqual(rows, pane.rows); + try std.testing.expectEqual(tag_rows, pane.tag_rows - pane.band_rows); + try std.testing.expectEqual(rows, pane.rows + pane.band_rows); // With the keyboard in the tag (whose top row follows its caret) too: - // C-w's key cell, a line, in a tag of more rows. + // C-w's level, a line, in a tag of more rows. toRest(p); pane.focus = .tag; p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; p.sync(); try std.testing.expect(hostOf(p) != null); - try std.testing.expectEqual(tag_rows, pane.tag_rows); + try std.testing.expect(pane.tag_rows >= tag_rows); try std.testing.expectEqual(@as(u16, 0), pane.tag_top); } @@ -1024,6 +1037,8 @@ test "a click that gives the keyboard to another pane ends a level as Esc does; const rl = p.view().rects[low]; // SPC's level in the lower pane's tag; a click in its own tag keeps it. p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; try std.testing.expect(hostOf(p) == low); click(p, rl.x + config.GUTTER + 2, rl.y); try std.testing.expect(hostOf(p) == low and p.view().prefix == .leader); diff --git a/core/bindings.zig b/core/bindings.zig index 43145b15..af5e8a6d 100644 --- a/core/bindings.zig +++ b/core/bindings.zig @@ -45,26 +45,25 @@ pub const Info = struct { /// Its key cell in the head (`␣` for SPC). cell: []const u8, label: []const u8, - /// How long after it the level shows (SPEC §3.3). + /// How long after it the level shows (SPEC §3.3): the tag changes + /// nothing before (UX D12), so `gg` and a fast `SPC f s` never touch it; + /// its keys show on the notice row's right end at once (Messages). delay_ns: u64, - /// Its key cell is written at once (SPC, `"`, `C-w`); the others change - /// nothing until the delay is up, so `gg` never touches the tag. - at_once: bool, node: *const Node, }; const ms = std.time.ns_per_ms; pub const info = std.EnumArray(Root, Info).init(.{ - .leader = .{ .key = .{ .cp = config.leader[0].cp }, .cell = "␣", .label = "SPC", .delay_ns = 250 * ms, .at_once = true, .node = &leader_tree }, - .window = .{ .key = .{ .cp = config.window_prefix[0].cp, .ctrl = true }, .cell = "C-w", .label = "window", .delay_ns = 250 * ms, .at_once = true, .node = &window_tree }, - .goto = .{ .key = .{ .cp = config.goto_prefix }, .cell = "g", .label = "goto", .delay_ns = 500 * ms, .at_once = false, .node = &goto_tree }, - .match = .{ .key = .{ .cp = config.match_prefix }, .cell = "m", .label = "match", .delay_ns = 500 * ms, .at_once = false, .node = &match_tree }, - .view = .{ .key = .{ .cp = config.view_prefix }, .cell = "z", .label = "view", .delay_ns = 500 * ms, .at_once = false, .node = &view_tree }, - .view_sticky = .{ .key = .{ .cp = config.view_prefix_sticky }, .cell = "Z", .label = "view", .delay_ns = 500 * ms, .at_once = false, .node = &view_sticky_tree }, - .prev = .{ .key = .{ .cp = config.prev_prefix }, .cell = "[", .label = "previous", .delay_ns = 500 * ms, .at_once = false, .node = &prev_tree }, - .next = .{ .key = .{ .cp = config.next_prefix }, .cell = "]", .label = "next", .delay_ns = 500 * ms, .at_once = false, .node = &next_tree }, - .register = .{ .key = .{ .cp = config.register_prefix }, .cell = "\"", .label = "registers", .delay_ns = 300 * ms, .at_once = true, .node = ®ister_tree }, + .leader = .{ .key = .{ .cp = config.leader[0].cp }, .cell = "␣", .label = "SPC", .delay_ns = 250 * ms, .node = &leader_tree }, + .window = .{ .key = .{ .cp = config.window_prefix[0].cp, .ctrl = true }, .cell = "C-w", .label = "window", .delay_ns = 250 * ms, .node = &window_tree }, + .goto = .{ .key = .{ .cp = config.goto_prefix }, .cell = "g", .label = "goto", .delay_ns = 500 * ms, .node = &goto_tree }, + .match = .{ .key = .{ .cp = config.match_prefix }, .cell = "m", .label = "match", .delay_ns = 500 * ms, .node = &match_tree }, + .view = .{ .key = .{ .cp = config.view_prefix }, .cell = "z", .label = "view", .delay_ns = 500 * ms, .node = &view_tree }, + .view_sticky = .{ .key = .{ .cp = config.view_prefix_sticky }, .cell = "Z", .label = "view", .delay_ns = 500 * ms, .node = &view_sticky_tree }, + .prev = .{ .key = .{ .cp = config.prev_prefix }, .cell = "[", .label = "previous", .delay_ns = 500 * ms, .node = &prev_tree }, + .next = .{ .key = .{ .cp = config.next_prefix }, .cell = "]", .label = "next", .delay_ns = 500 * ms, .node = &next_tree }, + .register = .{ .key = .{ .cp = config.register_prefix }, .cell = "\"", .label = "registers", .delay_ns = 300 * ms, .node = ®ister_tree }, }); /// SPC's groups by their key, as the spec names them (Appendix A). @@ -566,9 +565,10 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi p.clock.now_ns = 5 * std.time.ns_per_s; p.clock.stepped_ns = p.clock.now_ns; p.sync(); - // Its key cell at once, the level 300 ms on. + // Nothing in the tag until the level shows 300 ms on (UX D12). + const rest = try a.dupe(u8, try tagline.tagText(p, a, pane)); p.update(.{ .key = .{ .cp = '"' } }); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, a, pane), "\" …")); + try std.testing.expectEqualStrings(rest, try tagline.tagText(p, a, pane)); p.advance(p.clock.now_ns); try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns); p.clock.now_ns = p.view().tag_state.due_ns; diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 65c52ee7..6256a0b7 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -388,12 +388,17 @@ test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, canc try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal ")); try s.keys(":"); try std.testing.expect(try s.cursor() == null); - // The leader shows its key cell in the tag at once (walk UI) until a + // The leader changes nothing in the tag before its level shows (walk + // UI, UX D12): its key on the notice row's right end at once, until a // key the PDF takes, which takes the leader away. + const before = try std.testing.allocator.dupe(u8, try panesShown(&s)); + defer std.testing.allocator.free(before); try s.keys(" "); - try std.testing.expect(std.mem.indexOf(u8, try panesShown(&s), " ␣ ") != null); + try std.testing.expectEqualStrings(before, try panesShown(&s)); + const shown = try s.screen(); + try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, shown[std.mem.lastIndexOfScalar(u8, shown, '\n').? + 1 ..], " "), "SPC")); try s.keys("!"); - try std.testing.expect(std.mem.indexOf(u8, try panesShown(&s), " ␣ ") == null); + try std.testing.expectEqualStrings(before, try panesShown(&s)); try s.keys("/"); try std.testing.expect(try s.cursor() != null); try std.testing.expectEqual(n, try s.focused()); -- cgit v1.3 From 99c70953a0c3b8e32cc5b61121c2b18e5ee68edd Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:39:53 -0300 Subject: TagState, Pick, Prompt: the head's right block, the count `cursor/matches` and the hints at its row's right end, fixed while the field grows, the hints dim and first to go (walk UI polish P1, UX DESIGN.md D3): the count sat three spaces after the field (`Help tut▌ 3/133`, `Find re▌ 2/3`), so it slid right with every key typed, the only moving thing in the tag, and meant two things (Help's matches/total, the picker's cursor/matches); the hints followed it and wrapped mid-word onto a row of their own (msg's `s EXT ... C-r histo` / `ry · esc`); now `TagState.Builder.right(count, hints)` moves what was put from those bytes on to the row's right end (its last cell the row's last, two blanks between, at least two before), drops the hints whole when the row has no room for them, never the count (a head with no room for it runs past its row: the field's scroll D3 asks for there is not built); THE CHANGE: Builder is pub, made by `Builder.of(p, arena, pane)` with the row's width and the prefix's cells before the head (`col`), and Pick.head and Prompt.head build in it (their text and spans the builder's); counts: Help's is the cursor's row of its hits (`2/17`, `0` with none: no total), the picker's `0` with none (was `0/0`), the search prompt's wrap ` ↻` (was ` · wrapped`); hints are dim spans (describe-key's `⏎ run · esc`, Rename's, unrolled's `↑ roll up · ? field · esc`, the prompts' and the themes picker's); the rolled level keeps its hint as before (D2's rows put it on its last row); TEST FIRST: TagState.zig "the right block: the count `cursor/matches` at the row's right end, fixed while the field grows; the hints after it, dim, dropped whole where the row has no room" (Help at 60 columns: the first row exactly the tag's width ending ` 1/N`, the same after typing and `2/N` after Down; unrolled SPC's hints at the end, a dim span; at 24 columns `␣ SPC` alone); the tests reading heads read a run of blanks as two (Prompt.zig, Command.zig `has`; Pick, Band: the first row's start and end); core-test 1063/1233 (170 skipped); process-test: 7 goldens regenerated and read (find, fsearch, lsp, msg, pipe, selregex, ttyhelp): every changed row a count or hints moved to the row's right end (`␣ f Find zqm` ... `1/3`), `0/0` now `0`, ttyhelp's `1/136` now `1/1` (one match, the cursor on it), msg's `s EXT` hints dropped at 70 columns so its tag is one row again (the body a row up, where it is at rest); a user saw the count move at every key 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/Band.zig | 3 +- core/Command.zig | 16 +++- core/Pick.zig | 24 ++++-- core/Prompt.zig | 46 ++++++++--- core/TagState.zig | 174 ++++++++++++++++++++++++++++++++++++++--- test/snapshots/find.golden | 10 +-- test/snapshots/fsearch.golden | 46 +++++------ test/snapshots/lsp.golden | 6 +- test/snapshots/msg.golden | 10 +-- test/snapshots/pipe.golden | 2 +- test/snapshots/selregex.golden | 10 +-- test/snapshots/ttyhelp.golden | 2 +- 12 files changed, 263 insertions(+), 86 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 31205d87..024b6be4 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -555,7 +555,8 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push for (s.cells[@as(usize, layer.viewport.y) * s.cols ..][layer.viewport.x..][0..layer.viewport.w]) |cell| try grid.appendSlice(frame.allocator(), cell.grapheme()); try std.testing.expect(std.mem.indexOf(u8, grid.items, "▶ b buffer…") != null); // The head names the level and says how to roll it up. - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagText(p, frame.allocator(), pane), "␣ SPC ↑ roll up · ? field · esc")); + const head = try tagline.tagText(p, frame.allocator(), pane); + try std.testing.expect(std.mem.startsWith(u8, head, "␣ SPC ") and std.mem.endsWith(u8, head, " ↑ roll up · ? field · esc")); // Down moves the cursor; Up back to the first row, then rolls up. p.update(.{ .key = .{ .cp = Key.down } }); try std.testing.expectEqual(@as(u8, 'c'), p.view().tag_state.hi); diff --git a/core/Command.zig b/core/Command.zig index 334d49a2..908358de 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -659,8 +659,22 @@ fn tagOf(p: *Pardes) ![]const u8 { return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?); } +/// Whether `needle` is in `hay`, a run of two spaces or more in either read +/// as two: a right block's padding is its row's (UX D3). fn has(hay: []const u8, needle: []const u8) bool { - return std.mem.indexOf(u8, hay, needle) != null; + var in: [8192]u8 = undefined; + var of: [1024]u8 = undefined; + return std.mem.indexOf(u8, squeezed(hay, &in), squeezed(needle, &of)) != null; +} + +fn squeezed(s: []const u8, buf: []u8) []const u8 { + var n: usize = 0; + for (s, 0..) |c, i| { + if (c == ' ' and i >= 2 and s[i - 1] == ' ' and s[i - 2] == ' ') continue; + buf[n] = c; + n += 1; + } + return buf[0..n]; } /// Band row `y`'s text under the live view's active pane. diff --git a/core/Pick.zig b/core/Pick.zig index 321b16b7..8fcc5945 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -563,8 +563,9 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const pk = live(p) orelse return null; const s = &p.view().tag_state; - var text: std.ArrayList(u8) = .empty; - var spans: std.ArrayList(TagState.Span) = .empty; + var b = try TagState.Builder.of(p, arena, pane); + const text = &b.text; + const spans = &b.spans; var cells: [4][2]u32 = undefined; var ncells: usize = 0; // SPC's cell, then its keys': `␣ f`. @@ -581,16 +582,22 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()}); const caret: u32 = @intCast(text.items.len + s.field.caret); try text.appendSlice(arena, s.field.text()); + // The count at the row's right end (UX D3): `cursor/matches`, `0` with + // none, ` •M` marked. + const counted = text.items.len; const n = count(p, pk); - try text.print(arena, " {d}/{d}", .{ if (n == 0) 0 else s.rows.at + 1, n }); + 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 have no acts and no other sources: no second row. if (pk.source == .themes) { - try text.appendSlice(arena, " ⏎ wear it · esc"); + const hints = text.items.len; + try b.styled("⏎ wear it · esc", .dim); + try b.right(counted, hints); for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret }; } + try b.right(counted, text.items.len); // The second row: the spines go on through it from the key cells, // then the other sources' words, each switching to it. try text.append(arena, '\n'); @@ -1528,7 +1535,8 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the const tag = try tagOf(p, a, reader); // Out of rest no path (UX D1): not the previewed file's, not Keep; // the head starts the tag's text. - try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick 1/1\n")); + const first = tag[0..std.mem.indexOfScalar(u8, tag, '\n').?]; + try std.testing.expect(std.mem.startsWith(u8, first, "␣ f Find pick ") and std.mem.endsWith(u8, first, " 1/1")); try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null); // The body previews the row's file, after a frame of its own. p.update(.tick); @@ -1570,7 +1578,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and try std.testing.expectEqual(@as(u16, 2), s.rows.at); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); - try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs 3/4 •1\n") != null); + const refs = try tagOf(p, frame.allocator(), id); + try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); @@ -1588,7 +1597,8 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and settle(p); try std.testing.expectEqual(@as(usize, 1), count(p, pk)); _ = frame.reset(.retain_capacity); - try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, frame.allocator(), id), " Refs alpha | w 1/1\n") != null); + const refined = try tagOf(p, frame.allocator(), id); + try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null); // Backspace twice: the `w` goes, then the refinement, its query back. p.update(.{ .key = .{ .cp = Key.backspace } }); p.update(.{ .key = .{ .cp = Key.backspace } }); diff --git a/core/Prompt.zig b/core/Prompt.zig index 10886606..27b59649 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -1062,9 +1062,10 @@ fn strike(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, line: i32, lo_: pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { const s = &p.view().tag_state; const pr = &s.prompt; - var text: std.ArrayList(u8) = .empty; - var spans: std.ArrayList(TagState.Span) = .empty; - try styled(arena, &text, &spans, info.get(pr.op).cell, .key); + var b = try TagState.Builder.of(p, arena, pane); + const text = &b.text; + const spans = &b.spans; + try styled(arena, text, spans, info.get(pr.op).cell, .key); try text.append(arena, ' '); const caret: u32 = @intCast(text.items.len + s.field.caret); const line = s.field.text(); @@ -1074,20 +1075,25 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { var w: std.Io.Writer = .fixed(&buf); const said = if (pr.op == .command) Command.plainWord(p, &w, line) else plainWord(&w, pr.op, line) catch null; if (said) |verb| { - try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim); + try styled(arena, text, spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim); try text.print(arena, " {s}", .{w.buffered()}); } + } + // The count and the hints at the row's right end (UX D3). + const at = text.items.len; + if (line.len > 0) { if (pr.bad) { try text.appendSlice(arena, " "); - try styled(arena, &text, &spans, regexMessage(line), .err); + try styled(arena, text, spans, regexMessage(line), .err); try text.print(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}); } else if (behavior(pr.op) != null) { - try pipeCount(p, arena, &text, &spans, pane, pr, line); - } else try count(arena, &text, pane, pr); + try pipeCount(p, arena, text, spans, pane, pr, line); + } else try count(arena, text, pane, pr); } - if (pr.op == .command) try Command.count(p, arena, &text); - try text.appendSlice(arena, " "); - try styled(arena, &text, &spans, info.get(pr.op).hint, .dim); + if (pr.op == .command) try Command.count(p, arena, text); + const hints = text.items.len; + try styled(arena, text, spans, info.get(pr.op).hint, .dim); + try b.right(at, hints); return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret }; } @@ -1115,7 +1121,7 @@ fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *Pane, pr: *c // Round the end from where it began. const c = at orelse return; const origin = set.origin(pane); - if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " · wrapped"); + if (if (pr.op == .search) hits[c].start < origin else hits[c].start > origin) try text.appendSlice(arena, " ↻"); }, .select, .split => if (pr.found == 0) try text.appendSlice(arena, " 0") @@ -1255,8 +1261,22 @@ fn tagOf(p: *Pardes) ![]const u8 { return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?); } +/// Whether `needle` is in `hay`, a run of two spaces or more in either read +/// as two: a right block's padding is its row's (UX D3). fn has(hay: []const u8, needle: []const u8) bool { - return std.mem.indexOf(u8, hay, needle) != null; + var in: [8192]u8 = undefined; + var of: [1024]u8 = undefined; + return std.mem.indexOf(u8, squeezed(hay, &in), squeezed(needle, &of)) != null; +} + +fn squeezed(s: []const u8, buf: []u8) []const u8 { + var n: usize = 0; + for (s, 0..) |c, i| { + if (c == ' ' and i >= 2 and s[i - 1] == ' ' and s[i - 2] == ' ') continue; + buf[n] = c; + n += 1; + } + return buf[0..n]; } test "s asks in the tag's head: its key cell, the field, the plain word and the count, the selections live in the body; no match is 0, a pattern that is no regex keeps the last result dimmed and says why, Esc puts them back" { @@ -1269,7 +1289,7 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind); // No chip on the notice band: the prompt is the tag's. try std.testing.expectEqual(Pane.Prompt.none, pane.prompt); - try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc")); + try std.testing.expect(has(try tagOf(p), "s ⏎ select · M-⏎ as a list · C-r history · esc")); typeKeys(p, "self"); try std.testing.expect(has(try tagOf(p), "s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select")); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); diff --git a/core/TagState.zig b/core/TagState.zig index 96c5b9b1..d70edf47 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -466,22 +466,106 @@ pub const Head = struct { caret: ?u32 = null, }; -const Builder = struct { +/// A head as it is built: its text and spans, laid out against the tag's +/// rows (UX D2, D3). +pub const Builder = struct { arena: std.mem.Allocator, text: std.ArrayList(u8) = .empty, spans: std.ArrayList(Span) = .empty, cells: u8 = 0, + /// The cells of a row of the tag, and those before the head on its + /// first row (the owner's and the newest step's words). + width: usize = 0, + lead: usize = 0, + tab: u16 = 8, - fn put(b: *Builder, s: []const u8) !void { + /// A head for pane `pane`'s tag, out of rest in the live view. + pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Builder { + const prefix = try tagline.prefixIn(p, arena, pane); + const id = panes.paneIdOf(p, pane) orelse 0; + return .{ .arena = arena, .width = tagline.tagWidth(p, id), .lead = panes.File.displayWidth(p.settings.tab, prefix), .tab = p.settings.tab }; + } + + pub fn put(b: *Builder, s: []const u8) !void { try b.text.appendSlice(b.arena, s); } - fn styled(b: *Builder, s: []const u8, style: Style) !void { + pub fn styled(b: *Builder, s: []const u8, style: Style) !void { const lo: u32 = @intCast(b.text.items.len); try b.text.appendSlice(b.arena, s); try b.spans.append(b.arena, .{ .lo = lo, .hi = @intCast(b.text.items.len), .style = style }); } + + /// The cells the row being built takes so far, the prefix's before the + /// first row's. + pub fn col(b: *const Builder) usize { + const items = b.text.items; + const nl = std.mem.lastIndexOfScalar(u8, items, '\n') orelse return b.lead + panes.File.displayWidth(b.tab, items); + return panes.File.displayWidth(b.tab, items[nl + 1 ..]); + } + + /// The right block (UX D3): what was put from byte `count` on (the + /// count) and from byte `hints` on (the hints) moved to the right end of + /// their row, its last cell the row's last, two spaces between them and + /// at least two before; so it never moves while the field grows toward + /// it. Hints that do not fit go whole, first; the count never does (a + /// head with no room for it runs past its row). + pub fn right(b: *Builder, count: usize, hints: usize) !void { + var h = hints; + b.cut(h, h + spaces(b.text.items[h..])); + const lead_c = spaces(b.text.items[count..h]); + b.cut(count, count + lead_c); + h -= lead_c; + while (h > count and b.text.items[h - 1] == ' ') : (h -= 1) b.cut(h - 1, h); + const items = b.text.items; + const row = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0; + const left = panes.File.displayWidth(b.tab, items[row..count]) + if (row == 0) b.lead else 0; + var trail: usize = 0; + while (trail < count - row and items[count - 1 - trail] == ' ') trail += 1; + const cw = panes.File.displayWidth(b.tab, items[count..h]); + var hw = panes.File.displayWidth(b.tab, items[h..]); + const between: usize = if (cw > 0) 2 else 0; + if (hw > 0 and left + (2 -| trail) + cw + between + hw > b.width) { + b.text.shrinkRetainingCapacity(h); + var kept: usize = 0; + for (b.spans.items) |span| if (span.lo < h) { + b.spans.items[kept] = span; + kept += 1; + }; + b.spans.shrinkRetainingCapacity(kept); + hw = 0; + } + if (cw + hw == 0) return; + if (cw > 0 and hw > 0) try b.insert(h, 2); + const used = left + cw + (if (cw > 0 and hw > 0) between else 0) + hw; + try b.insert(count, if (used + (2 -| trail) <= b.width) b.width - used else 2 -| trail); + } + + /// `n` spaces put in at byte `at`, the spans after it moved with them. + fn insert(b: *Builder, at: usize, n: usize) !void { + const blank = try b.arena.alloc(u8, n); + @memset(blank, ' '); + try b.text.insertSlice(b.arena, at, blank); + for (b.spans.items) |*span| if (span.lo >= at) { + span.lo += @intCast(n); + span.hi += @intCast(n); + }; + } + + /// Bytes `lo` to `hi` taken out (blanks: no span starts in them). + fn cut(b: *Builder, lo: usize, hi: usize) void { + if (hi <= lo) return; + b.text.replaceRangeAssumeCapacity(lo, hi - lo, &.{}); + for (b.spans.items) |*span| if (span.lo >= hi) { + span.lo -= @intCast(hi - lo); + span.hi -= @intCast(hi - lo); + }; + } + + fn spaces(s: []const u8) usize { + return s.len - std.mem.trimStart(u8, s, " ").len; + } /// The keys typed as 2-cell key cells: the root's, then each key. - fn keyCells(b: *Builder, root: Root, path: []const u8) !void { + pub fn keyCells(b: *Builder, root: Root, path: []const u8) !void { try b.styled(bindings.info.get(root).cell, .key); try b.put(" "); for (path) |k| { @@ -490,7 +574,7 @@ const Builder = struct { } b.cells = @intCast(b.spans.items.len); } - fn done(b: *const Builder) Head { + pub fn done(b: *const Builder) Head { return .{ .text = b.text.items, .spans = b.spans.items, .cells = b.cells }; } }; @@ -502,11 +586,11 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { if (p.panes[id] != pane) return asking(p, arena, pane); const v = p.view(); const s = &v.tag_state; - var b: Builder = .{ .arena = arena }; + var b = try Builder.of(p, arena, pane); switch (s.kind) { .rest => {}, - // `Help`, its scope's keys, the field, its count: - // `Help ␣ l hov 2/17` (out of rest the head starts the tag's + // `Help`, its scope's keys, the field, its count at the row's end: + // `Help ␣ l hov 2/17` (out of rest the head starts the tag's // text, after the owner's and the newest step's words: UX D1). .help => { try b.put("Help "); @@ -514,7 +598,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { var h = b.done(); h.caret = @intCast(b.text.items.len + s.field.caret); try b.put(s.field.text()); - try b.text.print(arena, " {d}/{d}", .{ s.nhits, s.ntotal }); + const count = b.text.items.len; + if (s.nhits == 0) try b.put("0") else try b.text.print(arena, "{d}/{d}", .{ s.rows.at + 1, s.nhits }); + try b.right(count, b.text.items.len); h.text = b.text.items; h.spans = b.spans.items; return h; @@ -542,9 +628,16 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { try b.put(" "); try b.put(c.label); }; - try b.put(" ⏎ run · esc"); + const hints = b.text.items.len; + try b.styled("⏎ run · esc", .dim); + try b.right(hints, hints); } else try b.put("…"); - } else try b.put("… press a key or a sequence · esc"); + } else { + try b.put("…"); + const hints = b.text.items.len; + try b.styled("press a key or a sequence · esc", .dim); + try b.right(hints, hints); + } return b.done(); }, .pick => return @import("Pick.zig").head(p, arena, pane), @@ -558,7 +651,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { var h = b.done(); h.caret = @intCast(b.text.items.len + s.field.caret); try b.put(s.field.text()); - try b.put(" ⏎ rename · esc"); + const hints = b.text.items.len; + try b.styled("⏎ rename · esc", .dim); + try b.right(hints, hints); h.text = b.text.items; h.spans = b.spans.items; return h; @@ -569,7 +664,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { const node = bindings.nodeAt(cur.root, cur.path) orelse return b.done(); if (s.unrolled) { try b.put(if (cur.path.len == 0) bindings.info.get(cur.root).label else node.label); - try b.put(" ↑ roll up · ? field · esc"); + const hints = b.text.items.len; + try b.styled("↑ roll up · ? field · esc", .dim); + try b.right(hints, hints); return b.done(); } try b.styled("▸", .key); @@ -688,6 +785,57 @@ test "SPC changes nothing in the tag until its level shows 250 ms on, its keys o try std.testing.expect(p.view().tag_state.root == null); } +fn firstRow(tag: []const u8) []const u8 { + return tag[0 .. std.mem.indexOfScalar(u8, tag, '\n') orelse tag.len]; +} + +test "the right block: the count `cursor/matches` at the row's right end, fixed while the field grows; the hints after it, dim, dropped whole where the row has no room" { + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const tab = p.settings.tab; + const width = tagline.tagWidth(p, p.view().active); + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = '?' } }); + const s = &p.view().tag_state; + var row = firstRow(try testTag(p, a)); + try std.testing.expect(std.mem.startsWith(u8, row, "Help ")); + try std.testing.expectEqual(width, panes.File.displayWidth(tab, row)); + try std.testing.expect(std.mem.endsWith(u8, row, try std.fmt.allocPrint(a, " 1/{d}", .{s.nhits}))); + // Typed into: the field grows toward the count, which stays put. + for ("wr") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + row = firstRow(try testTag(p, a)); + try std.testing.expect(std.mem.startsWith(u8, row, "Help wr ") and s.nhits > 1); + try std.testing.expectEqual(width, panes.File.displayWidth(tab, row)); + try std.testing.expect(std.mem.endsWith(u8, row, try std.fmt.allocPrint(a, " 1/{d}", .{s.nhits}))); + // The cursor's row is the count's first number. + p.update(.{ .key = .{ .cp = Key.down } }); + try std.testing.expect(std.mem.endsWith(u8, firstRow(try testTag(p, a)), try std.fmt.allocPrint(a, " 2/{d}", .{s.nhits}))); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Unrolled: the hints at the row's end, dim. + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = Key.down } }); + row = firstRow(try testTag(p, a)); + try std.testing.expect(std.mem.startsWith(u8, row, "␣ SPC ")); + try std.testing.expect(std.mem.endsWith(u8, row, " ↑ roll up · ? field · esc")); + try std.testing.expectEqual(width, panes.File.displayWidth(tab, row)); + const h = (try head(p, a, p.panes[p.view().active].?)).?; + const last = h.spans[h.spans.len - 1]; + try std.testing.expect(last.style == .dim and last.hi == h.text.len); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Where the row has no room for them, the hints go whole. + const narrow = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 24, .rows = 30 }); + defer narrow.deinit(); + _ = try narrow.setTestFile("one\n"); + narrow.update(.{ .key = .{ .cp = ' ' } }); + narrow.update(.{ .key = .{ .cp = Key.down } }); + try std.testing.expectEqualStrings("␣ SPC", firstRow(try testTag(narrow, a))); +} + test "a leaf run from a level is remembered: underlined there, and said on the line under it" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); defer p.deinit(); diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 8cef240d..83fd76dc 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -41,7 +41,7 @@ | | /tmp/pardes-snap/find/cwd/here.txt:1 == snap armed grid=120x41 cursor=11,2 -|2: ^ ␣ f Find 1/5 +|2: ^ ␣ f Find 1/5 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist |4: │ │ ▶ here.txt |5: │ │ other.txt @@ -51,7 +51,7 @@ |9: 1 Find zqm |40: ✓ /tmp/pardes-snap/find/cwd/here.txt Find 1 message · SPC h m == snap typing grid=120x41 cursor=14,2 -|2: ^ ␣ f Find zqm 1/3 +|2: ^ ␣ f Find zqm 1/3 |4: │ │ ▶ zqmark-alpha.txt |5: │ │ sub/ZQMARK-beta.txt |6: │ │ sub/nest/zqmark-gamma.txt @@ -59,7 +59,7 @@ |8: │ │ |9: 1 alpha body == snap next grid=120x41 cursor=14,2 -|2: ^ ␣ f Find zqm 2/3 +|2: ^ ␣ f Find zqm 2/3 |4: │ │ zqmark-alpha.txt |5: │ │ ▶ sub/ZQMARK-beta.txt |9: 1 beta body @@ -73,7 +73,7 @@ |8: |9: == snap nomatch grid=120x41 cursor=30,2 -|2: ^ Find zqm 2/3 › ␣ f Find zzqq 0/0 +|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 |4: │ │ nothing matches |5: │ │ @@ -86,7 +86,7 @@ |5: |6: == snap topbar grid=120x41 cursor=29,2 -|2: ^ Find zqm 2/3 › ␣ f Find bod 0/0 +|2: ^ Find zqm 2/3 › ␣ f Find bod 0 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist |4: │ │ nothing matches |5: │ │ diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index bf8957df..dd1d34e5 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -31,22 +31,12 @@ | | · @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 == snap slash grid=180x31 cursor=101,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › / ⏎ land · M-⏎ as a list · C-r history · esc +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › / ⏎ land · M-⏎ as a list · C-r history · esc == snap typing grid=180x31 cursor=105,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › / MARK = Look /MARK/ 1/3 · 3 lines ⏎ land · M-⏎ as a list · C-r history · es -|17: ls c -|18: g.txt 1 l1 -|19: 2▸MARK a -|20: 3 l3 -|21: 4 l4 -|22: 5 l5 -|23: 6▪MARK b -|24: 7 l7 -|25: 8 l8 -|26: 9 l9 -|27: 10▪MARK c -|28: 11 l11 -|29: 12 l12 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › / MARK = Look /MARK/ 1/3 · 3 lines ⏎ land · M-⏎ as a list · C-r history · esc +|18: g.txt 2▸MARK a +|22: 6▪MARK b +|26: 10▪MARK c == style typing grid=180x31 |0: 0-1 d,#1d2824, 2-179 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-89 #b2c3b8,#1d2824, 90-91 #b2c3b8,#887455, 92-179 #becfc4,#314738, @@ -64,23 +54,23 @@ |13: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |14: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |15: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, -|16: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #000000,#add38a, 92-98 #becfc4,#2c2819, 99-99 #add38a,#2c2819,b 100-100 #add38a,#2c2819, 101-104 #becfc4,#2c2819, 105-112 #becfc4,#2c2819,f 113-138 #becfc4,#2c2819, 139-179 #becfc4,#2c2819,f -|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-91 #e5eee5,#2c2819, 92-92 #becfc4,#2c2819,f 93-179 #becfc4,#2c2819, -|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#e5eee5, 91-94 #e5eee5,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|19: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-91 d,#0d1410, 92-94 d,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #add38a,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, +|16: 0-1 d,#496656, 2-30 #b2c3b8,#1d2824, 31-40 #d3b0d9,#1d2824, 41-89 #b2c3b8,#1d2824, 90-91 #000000,#add38a, 92-98 #becfc4,#2c2819, 99-99 #add38a,#2c2819,b 100-100 #add38a,#2c2819, 101-104 #becfc4,#2c2819, 105-112 #becfc4,#2c2819,f 113-137 #becfc4,#2c2819, 138-179 #becfc4,#2c2819,f +|17: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#608269, 91-94 #e5eee5,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|18: 0-0 d,#608269, 1-1 d,#0d1410, 2-89 #e5eee5,#0d1410, 90-90 #e5eee5,#e5eee5, 91-91 #e5eee5,#0d1410, 92-94 #e5eee5,#0d1410,b 95-95 #616f64,#0d1410,b 96-96 #add38a,#0d1410,b 97-100 #f5f7ee,#3c614a, 101-101 #f5f7ee,#0d1410, 102-179 #e5eee5,#0d1410, +|19: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |20: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |21: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|22: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|23: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|22: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-94 d,#0d1410, 95-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|23: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |24: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |25: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|26: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-94 d,#0d1410, 95-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|27: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-93 d,#0d1410, 94-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|26: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#5e4923, 91-93 d,#0d1410, 94-95 #59675c,#0d1410, 96-96 #add38a,#0d1410, 97-100 #e5eee5,#352e19, 101-179 #e5eee5,#0d1410, +|27: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |28: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, -|29: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, +|29: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |30: 0-1 d,#1d2824, 2-179 #67756e,#1d2824, == snap list grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 |17: ls │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symb |18: g.txt ols All Jumplist |19: ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a @@ -95,7 +85,7 @@ |28: 7 l7 |29: 8 l8 == snap ctrln grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 |19: /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a |20: ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b |22: 2 MARK a @@ -139,5 +129,5 @@ |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse == snap cancel grid=180x31 cursor=97,23 == snap nomatch grid=180x31 cursor=118,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · e -|17: ls sc +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · esc +|17: ls diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 445c5d4b..94958ba4 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -57,7 +57,7 @@ |14: ~ |40: ✓ /tmp/pardes-snap/lsp/cwd/a.zig Hover 1 message · SPC h m == snap symbols grid=120x41 cursor=24,2 -|2: ^ a.zig:8 › ␣ l Symbols 1/3 +|2: ^ a.zig:8 › ␣ l Symbols 1/3 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symbols All Jumplist |4: │ │ ▶ a.zig:1:7-9 std |5: │ │ a.zig:3:4-9 helper @@ -76,9 +76,9 @@ |18: ~ |40: ✓ /tmp/pardes-snap/lsp/cwd/a.zig Symbols 2 messages · SPC h m == snap step grid=120x41 cursor=27,2 -|2: ^ a.zig:8 › ␣ l Symbols jn 0/0 +|2: ^ a.zig:8 › ␣ l Symbols jn 0 |4: │ │ nothing matches |5: │ │ |6: │ │ == snap nothing grid=120x41 cursor=29,2 -|2: ^ a.zig:8 › ␣ l Symbols jngd 0/0 +|2: ^ a.zig:8 › ␣ l Symbols jngd 0 diff --git a/test/snapshots/msg.golden b/test/snapshots/msg.golden index 7e622261..4c6f2308 100644 --- a/test/snapshots/msg.golden +++ b/test/snapshots/msg.golden @@ -48,18 +48,12 @@ |9: |16: · reloaded /tmp/pardes-snap/msg/cwd/a.txt 5 messages · SPC h m == snap prompt grid=70x17 cursor=7,2 -|2: ^ s EXT = Exec Edit x/EXT/ 0 ⏎ select · M-⏎ as a list · C-r histo -|3: ry · esc -|4: 1 EXTERNAL -|5: ~ +|2: ^ s EXT = Exec Edit x/EXT/ 0 == snap prompt-wins grid=70x17 cursor=7,2 -|4: 1 AGAIN +|3: 1 AGAIN |16: · reloaded /tmp/pardes-snap/msg/cwd/a.txt ×2 5 messages · SPC h m == snap esc grid=70x17 cursor=7,4 |2: /tmp/pardes-snap/msg/cwd/a.txt Keep Save Term Collapse Follow Del -|3: 1 AGAIN -|4: ~ -|5: == snap msgbuiltin grid=70x17 cursor=29,5 |2: */tmp/pardes-snap/msg/cwd/a.txt Save Term Collapse Follow Del |4: 2 diff --git a/test/snapshots/pipe.golden b/test/snapshots/pipe.golden index a8d2aa31..9ac8ced4 100644 --- a/test/snapshots/pipe.golden +++ b/test/snapshots/pipe.golden @@ -1,7 +1,7 @@ == snap prompt grid=180x13 cursor=14,2 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol -|^ | tr a-z A-Z = Exec Edit |tr a-z A-Z 1 line → 1 · exit 0 ⏎ replace · C-r history · esc +|^ | tr a-z A-Z = Exec Edit |tr a-z A-Z 1 line → 1 · exit 0 ⏎ replace · C-r history · esc | 1 alpha beta | ALPHA BETA | 2 gamma delta diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index df68f85a..b6e45518 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -1,7 +1,7 @@ == snap prompt-armed grid=160x25 cursor=4,2 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol -|^ s ⏎ select · M-⏎ as a list · C-r history · esc +|^ s ⏎ select · M-⏎ as a list · C-r history · esc | 1┃const one = 1; | 2┃const two = 2; | 3┃const three = 3; @@ -25,12 +25,12 @@ | | /tmp/pardes-snap/selregex/cwd/m.zig:3 == snap preview grid=160x25 cursor=9,2 -|2: ^ s const = Exec Edit x/const/ 3 selections in 3 lines ⏎ select · M-⏎ as a list · C-r history · esc +|2: ^ s const = Exec Edit x/const/ 3 selections in 3 lines ⏎ select · M-⏎ as a list · C-r history · esc |24: /tmp/pardes-snap/selregex/cwd/m.zig:1 == style preview grid=160x25 |0: 0-1 d,#1d2824, 2-159 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-159 #becfc4,#314738, -|2: 0-1 #000000,#add38a, 2-2 #add38a,#2c2819,b 3-3 #add38a,#2c2819, 4-8 #becfc4,#2c2819, 9-16 #becfc4,#2c2819,f 17-59 #becfc4,#2c2819, 60-103 #becfc4,#2c2819,f 104-159 #becfc4,#2c2819, +|2: 0-1 #000000,#add38a, 2-2 #add38a,#2c2819,b 3-3 #add38a,#2c2819, 4-8 #becfc4,#2c2819, 9-16 #becfc4,#2c2819,f 17-115 #becfc4,#2c2819, 116-159 #becfc4,#2c2819,f |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-5 #616f64,#0d1410,b 6-6 #add38a,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, @@ -64,12 +64,12 @@ |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap narrowed grid=160x25 cursor=21,2 -|2: ^ Edit x/const/ › s t = Exec Edit x/t/ 3 selections in 3 lines ⏎ select · M-⏎ as a list · C-r history · esc +|2: ^ Edit x/const/ › s t = Exec Edit x/t/ 3 selections in 3 lines ⏎ select · M-⏎ as a list · C-r history · esc |3: 1┃const one = 1; |4: 2┃const two = 2; |5: 3┃const three = 3; == style narrowed grid=160x25 -|2: 0-1 #000000,#add38a, 2-17 #becfc4,#2c2819, 18-18 #add38a,#2c2819,b 19-19 #add38a,#2c2819, 20-20 #becfc4,#2c2819, 21-28 #becfc4,#2c2819,f 29-67 #becfc4,#2c2819, 68-111 #becfc4,#2c2819,f 112-159 #becfc4,#2c2819, +|2: 0-1 #000000,#add38a, 2-17 #becfc4,#2c2819, 18-18 #add38a,#2c2819,b 19-19 #add38a,#2c2819, 20-20 #becfc4,#2c2819, 21-28 #becfc4,#2c2819,f 29-115 #becfc4,#2c2819, 116-159 #becfc4,#2c2819,f |3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-5 #616f64,#0d1410,b 6-6 #add38a,#0d1410,b 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-5 #59675c,#0d1410, 6-6 #add38a,#0d1410, 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, diff --git a/test/snapshots/ttyhelp.golden b/test/snapshots/ttyhelp.golden index 3eb84714..93442263 100644 --- a/test/snapshots/ttyhelp.golden +++ b/test/snapshots/ttyhelp.golden @@ -49,7 +49,7 @@ |20: r SPC and those keys (`Help l`, as `SPC l ?` shows them). Each fills the one +Help: a second |30: ✓ @p1 Help 1 message · SPC h m == snap leaderworks grid=100x31 cursor=12,5 -|5: ^ Help tutor 1/136 +|5: ^ Help tutor 1/1 |6: ▶ SPC h t · Tutor · help│ t Tutor |7: │ Open the tutor, a document to work through. |8: │ keys SPC h t -- cgit v1.3 From 1d440373e90516ace8e45e8e64f2e4ae5d4a4773 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:58:33 -0300 Subject: TagState, Pick, Band: computed text breaks between its items only, a hanging indent under the spines, a rolled level three rows at most ending `+N ↓`, the picker's act row one row, a row too long cut with `…` (a path from the left) (walk UI polish P1, UX DESIGN.md D2): the rolled level was one long line wrapped by the tag's grapheme wrap, so a key fell apart from its label (`P`/`ClipPasteBefore`, `l ls`/`p…`, `D d`/`iagnostic end`) and its continuation rows started at the tag's first column under the box; the act row wrapped onto two (`Grep Rec`/`ent`); a band row was clipped at its step's edge; now (TagState.Builder) `keyCell` keeps each key cell's column and `row(indent)` starts a row of the head with a `│` under each key cell left of the indent (UX D5's spines through the tag's continuation rows; `// P2: the rule role`) and blanks up to it; the rolled level puts each child (`key label`) whole, a row's last child followed by the next row from the first child's column, three rows at most (a terminal's: the rows its own text takes, as before), the last one's last fitting child followed by a dim `+N ↓` (N the children not shown; the cells of it and of a struck key kept on the last row), its hints by the right block's rule on its last row (dropped where they do not fit); Pick.head's key cells are the builder's (its head's first spans, as every head's), its act row one row from two cells right of the last spine: the acts, `|`, the other sources, what does not fit dropped from the right (the sources first) and a dim `…` ending it (M-l, M-h reach them); Band.findSpines takes the key cells on whatever row they are (it wanted them on the tag's last row, so a picker's band had no spines and its steps started at the pane's edge: fsearch's list rows); Band.cutRow holds a row to its room with `…`: a path (its directory faint: Find's rows) cut from the left (`…r/Store.zig`), anything else from the right, its marks and faint bytes moved with it; TEST FIRST: TagState.zig "a rolled level breaks between its children only: ..." (SPC's level at 60 columns: three rows, the second and third `│ ` then a child, no row wider than the tag, every child shown whole, the rest counted in the last row's `+N ↓`; SPC h's on one row), Pick.zig "a picker's act row is one row under the spines ..." (60 columns: `│ │ Walk Look ` ... ` …`, a dim `…`), Band.zig "a row longer than its room is cut with `…` ..."; the SPC test reads a level of three rows at most; core-test 1066/1236 (170 skipped); process-test: 3 goldens regenerated and read: leader (the rolled level's second and third rows `│ ` from its first child's column, no child split, the hints at the last row's right end), find (`␣ f`'s hints at the row's end), fsearch (the list picker's act row one row ending `Panes …`, its band rows under spines from two cells right of the last, the body a row up); a user met the split words at every width under ~160 columns 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/Band.zig | 63 +++++++++++++++---- core/Pick.zig | 103 +++++++++++++++++++------------ core/TagState.zig | 139 +++++++++++++++++++++++++++++++++--------- test/snapshots/find.golden | 2 +- test/snapshots/fsearch.golden | 35 +++++------ test/snapshots/leader.golden | 10 +-- 6 files changed, 251 insertions(+), 101 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 024b6be4..0d4891aa 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -394,20 +394,16 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi band.nsteps = kept; } -/// The display columns of the head's key cells, when they are all on the -/// tag's last row (the spines hang from there). +/// The display columns of the head's key cells: a spine hangs under each, +/// through the tag's rows under them and the band's (UX D5). fn findSpines(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void { const h = (try TagState.head(p, arena, pane)) orelse return; const whole = try tagline.tagText(p, arena, pane); const shown = try tagline.wrapTag(p.settings.tab, arena, whole, tagline.tagWidth(p, id)); const lead = whole.len - h.text.len; - const last = shown.rows() -| 1; for (h.spans[0..h.cells]) |span| { const at = modal.positionAt(shown.text, shown.fromReal(lead + span.lo)); - if (at.row != last or band.nspines == max_spines) { - band.nspines = 0; - return; - } + if (band.nspines == max_spines) return; band.spines[band.nspines] = @intCast(File.rawDisplayCol(p.settings.tab, modal.lineSlice(shown.text, at.row), at.col)); band.nspines += 1; } @@ -484,16 +480,46 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line const lead: []const u8 = if (step.doc) "" else if (row.on) "▶ " else if (row.mark) "• " else " "; try text.appendSlice(arena, lead); col += @intCast(File.displayWidth(tab, lead)); - try parts.append(arena, .{ .col = col, .width = per -| @as(u16, @intCast(File.displayWidth(tab, lead))), .row = row }); const room = per -| @as(u16, @intCast(File.displayWidth(tab, lead))); - const cut = File.byteAtDisplay(tab, row.text, room); - try text.appendSlice(arena, row.text[0..cut]); - col += @intCast(File.displayWidth(tab, row.text[0..cut])); + const fit = try cutRow(arena, tab, row, room); + try parts.append(arena, .{ .col = col, .width = room, .row = fit }); + try text.appendSlice(arena, fit.text); + col += @intCast(File.displayWidth(tab, fit.text)); } } return .{ .text = text.items, .parts = parts.items }; } +/// Row `row` held to `room` cells (UX D2): a longer one cut with `…`, a +/// path (its directory faint: Find's rows) from the left +/// (`…core/Store.zig`), anything else from the right; its marks and faint +/// bytes moved with its text. +fn cutRow(arena: std.mem.Allocator, tab: u16, row: Row, room: u16) !Row { + if (File.displayWidth(tab, row.text) <= room) return row; + var fit = row; + var marks: std.ArrayList(u16) = .empty; + if (row.faint > 0 and row.pre == 0 and room > 1) { + var from = row.text.len; + while (from > 0) { + const before = modal.prevGrapheme(row.text, from); + if (File.displayWidth(tab, row.text[before..]) > room - 1) break; + from = before; + } + fit.text = try std.mem.concat(arena, u8, &.{ "…", row.text[from..] }); + for (row.marks) |m| if (m >= from) try marks.append(arena, @intCast(m - from + "…".len)); + fit.faint = @intCast(if (row.faint > from) row.faint - from + "…".len else "…".len); + } else { + const cut = File.byteAtDisplay(tab, row.text, room -| 1); + fit.text = try std.mem.concat(arena, u8, &.{ row.text[0..cut], if (room > 0) "…" else "" }); + for (row.marks) |m| if (m < cut) try marks.append(arena, m); + fit.key = @intCast(@min(row.key, cut)); + fit.pre = @intCast(@min(row.pre, cut)); + fit.faint = @intCast(@min(row.faint, cut -| fit.pre)); + } + fit.marks = marks.items; + return fit; +} + /// The word under column `col` of band row `y` of pane `id`, at the /// tagline's pitch: what B2 executes and B3 looks at. pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, y: u16, col: u16) !?[]const u8 { @@ -518,6 +544,21 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![ return out.items; } +test "a row longer than its room is cut with `…`: a path from the left, anything else from the right, its marks and faint bytes moved with it" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const a = arena.allocator(); + const path = try cutRow(a, 8, .{ .text = "core/deep/dir/Store.zig", .faint = 14, .marks = &.{ 0, 14, 15 } }, 12); + try std.testing.expectEqualStrings("…r/Store.zig", path.text); + try std.testing.expectEqual(@as(u16, 5), path.faint); + try std.testing.expectEqualSlices(u16, &.{ 5, 6 }, path.marks); + const other = try cutRow(a, 8, .{ .text = "a.zig:3:1: hello world", .pre = 9, .marks = &.{ 10, 20 } }, 12); + try std.testing.expectEqualStrings("a.zig:3:1: …", other.text); + try std.testing.expectEqualSlices(u16, &.{10}, other.marks); + const fits = try cutRow(a, 8, .{ .text = "short" }, 12); + try std.testing.expectEqualStrings("short", fits.text); +} + test "SPC Down unrolls the level into a band under the tag's text, the body pushed down and never drawn over; Up on its first row rolls it up" { const Key = pardes.Key; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); diff --git a/core/Pick.zig b/core/Pick.zig index 8fcc5945..52976f15 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -565,17 +565,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const s = &p.view().tag_state; var b = try TagState.Builder.of(p, arena, pane); const text = &b.text; - const spans = &b.spans; - var cells: [4][2]u32 = undefined; - var ncells: usize = 0; // SPC's cell, then its keys': `␣ f`. - if (pk.keys.len > 0) for (0..pk.keys.len + 1) |k| { - const name = if (k == 0) "␣" else bindings.keyName(pk.keys.slice()[k - 1]); - cells[ncells] = .{ @intCast(text.items.len), @intCast(text.items.len + name.len) }; - ncells += 1; - try text.appendSlice(arena, name); - try text.append(arena, ' '); - }; + if (pk.keys.len > 0) try b.keyCells(.leader, pk.keys.slice()); 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()}); @@ -594,38 +585,43 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const hints = text.items.len; try b.styled("⏎ wear it · esc", .dim); try b.right(counted, hints); - for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); - return .{ .text = text.items, .spans = spans.items, .cells = @intCast(ncells), .caret = caret }; + var h = b.done(); + h.caret = caret; + return h; } try b.right(counted, text.items.len); - // The second row: the spines go on through it from the key cells, - // then the other sources' words, each switching to it. - try text.append(arena, '\n'); - const prefix = try pardes.tagline.prefixIn(p, arena, pane); - const width = pardes.tagline.tagWidth(p, panes.paneIdOf(p, pane) orelse 0); - const lead = File.displayWidth(p.settings.tab, prefix) % @max(1, width); - var col: usize = 0; - for (cells[0..ncells]) |c| { - const at = lead + File.displayWidth(p.settings.tab, text.items[0..c[0]]); - while (col < at) : (col += 1) try text.append(arena, ' '); - try spans.append(arena, .{ .lo = @intCast(text.items.len), .hi = @intCast(text.items.len + "│".len), .style = .key }); - try text.appendSlice(arena, "│"); - col += 1; - } - const nspines: u8 = @intCast(spans.items.len); - try text.appendSlice(arena, if (ncells == 0) "" else " "); - for (acts) |act| if (offered(pk, act)) try text.print(arena, "{s} ", .{act.word}); - try text.appendSlice(arena, "|"); - var first = false; - inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes) { - if (src != pk.source) { - if (!first) try text.append(arena, ' '); - first = false; - try text.appendSlice(arena, words.get(src).word); - } + // The second row, one row (UX D2): under the spines from the key + // cells, from two cells right of the last, the acts, `|`, the other + // sources' words, each switching to it; what does not fit is dropped + // from the right (the sources first) and the row ends in a dim `…` + // (M-l and M-h reach them all). + try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0); + var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined; + var nw: usize = 0; + for (acts) |act| if (offered(pk, act)) { + offer[nw] = act.word; + nw += 1; + }; + offer[nw] = "|"; + nw += 1; + inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != pk.source) { + offer[nw] = words.get(src).word; + nw += 1; }; - for (cells[0..ncells]) |c| try spans.append(arena, .{ .lo = c[0], .hi = c[1], .style = .key }); - return .{ .text = text.items, .spans = spans.items, .cells = nspines, .caret = caret }; + for (offer[0..nw], 0..) |word, i| { + const gap: usize = @intFromBool(i > 0); + const rest: usize = if (i + 1 < nw) 2 else 0; + if (b.col() + gap + File.displayWidth(p.settings.tab, word) + rest > b.width) { + try b.put(if (gap > 0) " " else ""); + try b.styled("…", .dim); + break; + } + try b.put(if (gap > 0) " " else ""); + try b.put(word); + } + var h = b.done(); + h.caret = caret; + return h; } /// The band's rows: as many as the list will show, eleven at most, from @@ -1553,6 +1549,35 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the try std.testing.expectEqualStrings("pick", pk.query.slice()); } +test "a picker's act row is one row under the spines, two cells right of the last: what does not fit dropped from the right, the sources first, a dim `…` ending it" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + p.stream.engine = .walk; + open(p, asker, .find, "", "", ""); + const reader = p.paneBySerial(live(p).?.landing).?; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const tag = try tagOf(p, a, reader); + var rows = std.mem.splitScalar(u8, tag, '\n'); + try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find ")); + const acts_row = rows.next().?; + try std.testing.expect(rows.next() == null); + try std.testing.expect(std.mem.startsWith(u8, acts_row, "│ │ Walk Look ")); + try std.testing.expect(std.mem.endsWith(u8, acts_row, " …")); + try std.testing.expect(File.displayWidth(p.settings.tab, acts_row) <= pardes.tagline.tagWidth(p, reader)); + const h = (try head(p, a, p.panes[reader].?)).?; + try std.testing.expect(h.spans[h.spans.len - 1].style == .dim); +} + test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); diff --git a/core/TagState.zig b/core/TagState.zig index d70edf47..18fd5fac 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -478,6 +478,9 @@ pub const Builder = struct { width: usize = 0, lead: usize = 0, tab: u16 = 8, + /// Each key cell's column, which a spine hangs under (UX D5). + cols: [Band.max_spines]u16 = undefined, + ncols: u8 = 0, /// A head for pane `pane`'s tag, out of rest in the live view. pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Builder { @@ -517,10 +520,10 @@ pub const Builder = struct { h -= lead_c; while (h > count and b.text.items[h - 1] == ' ') : (h -= 1) b.cut(h - 1, h); const items = b.text.items; - const row = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0; - const left = panes.File.displayWidth(b.tab, items[row..count]) + if (row == 0) b.lead else 0; + const start = if (std.mem.lastIndexOfScalar(u8, items[0..count], '\n')) |nl| nl + 1 else 0; + const left = panes.File.displayWidth(b.tab, items[start..count]) + if (start == 0) b.lead else 0; var trail: usize = 0; - while (trail < count - row and items[count - 1 - trail] == ' ') trail += 1; + while (trail < count - start and items[count - 1 - trail] == ' ') trail += 1; const cw = panes.File.displayWidth(b.tab, items[count..h]); var hw = panes.File.displayWidth(b.tab, items[h..]); const between: usize = if (cw > 0) 2 else 0; @@ -566,13 +569,34 @@ pub const Builder = struct { } /// The keys typed as 2-cell key cells: the root's, then each key. pub fn keyCells(b: *Builder, root: Root, path: []const u8) !void { - try b.styled(bindings.info.get(root).cell, .key); + try b.keyCell(bindings.info.get(root).cell); + for (path) |k| try b.keyCell(if (k == ' ') "␣" else bindings.keyName(k)); + b.cells = @intCast(b.spans.items.len); + } + + /// One key cell, its column kept for its spine, and the blank after it. + pub fn keyCell(b: *Builder, name: []const u8) !void { + if (b.ncols < b.cols.len) { + b.cols[b.ncols] = @intCast(b.col()); + b.ncols += 1; + } + try b.styled(name, .key); try b.put(" "); - for (path) |k| { - try b.styled(if (k == ' ') "␣" else bindings.keyName(k), .key); - try b.put(" "); + } + + /// A row more of the head (UX D2): the spines on through it under each + /// key cell left of `indent` (UX D5), then blanks up to `indent`, a + /// hanging indent where the row's words start. + pub fn row(b: *Builder, indent: usize) !void { + try b.text.append(b.arena, '\n'); + var at: usize = 0; + for (b.cols[0..b.ncols]) |c| { + if (c >= indent) break; + try b.text.appendNTimes(b.arena, ' ', c - at); + try b.styled("│", .key); // P2: the rule role (UX D4) + at = c + 1; } - b.cells = @intCast(b.spans.items.len); + try b.text.appendNTimes(b.arena, ' ', indent -| at); } pub fn done(b: *const Builder) Head { return .{ .text = b.text.items, .spans = b.spans.items, .cells = b.cells }; @@ -670,31 +694,35 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { return b.done(); } try b.styled("▸", .key); - // The rolled level wraps to three rows at most (SPEC §3.6): what does - // not fit is `…`, and `↓` unrolls it whole. A terminal's to the rows its - // own text takes: its pty is its body, and a which-key that took a row - // would resize the program under it at every SPC. Every cell is - // counted: the prefix, each child with its separator and a group's - // `…`, the ` …` after a child that is not the last, a struck key, the - // hint (left out, a terminal's tag took a row more at some widths). - const hint = " ↓ unroll · ? help"; - const more = " …"; - const prefix = try tagline.prefixIn(p, arena, pane); + // The rolled level breaks between its children only (UX D2), each row + // after the first from the first child's column, its spines on through + // it; three rows at most, the last ending `+N ↓` (N the children not + // shown, `↓` unrolls them) when they do not fit. A terminal's to the + // rows its own text takes: its pty is its body, and a which-key that + // took a row would resize the program under it at every SPC. const tab = p.settings.tab; const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3; - const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0; - const room = most * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, prefix) -| panes.File.displayWidth(tab, hint) -| struck; var children: [bindings.max_children]bindings.Child = undefined; const level = bindings.level(p, cur.root, cur.path, &children); const used = s.used[node.group]; - var width = panes.File.displayWidth(tab, b.text.items); + const indent = b.col() + 1; + // A struck key goes after the children: the last row keeps its cells. + const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0; + var rows: usize = 1; for (level, 0..) |c, i| { - width += @as(usize, if (i == 0) 1 else 2) + panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group); - if (width + @as(usize, if (i + 1 < level.len) panes.File.displayWidth(tab, more) else 0) > room) { - try b.put(more); + const w = panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group or c.more); + var gap: usize = if (i == 0) 1 else 2; + if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width and rows < most and b.col() > indent) { + try b.row(indent); + rows += 1; + gap = 0; + } + if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width) { + try b.put(if (gap == 0) "" else " "); + try b.styled(try std.fmt.allocPrint(arena, "+{d} ↓", .{level.len - i}), .dim); break; } - try b.put(if (i == 0) " " else " "); + try b.put(if (gap == 0) "" else if (gap == 1) " " else " "); const lo: u32 = @intCast(b.text.items.len); try b.styled(bindings.keyName(c.key), .key); try b.put(" "); @@ -705,13 +733,24 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under }); } if (s.miss != 0) { - try b.put(" "); + if (b.col() + struck > b.width and rows < most) try b.row(indent) else try b.put(" "); try b.styled(bindings.keyName(s.miss), .strike); } - try b.put(hint); + // Its hints on its last row, by the right block's rule (UX D3). + const hints = b.text.items.len; + try b.styled("↓ unroll · ? help", .dim); + try b.right(hints, hints); return b.done(); } +/// The cells `+N ↓` takes after a child on a rolled level's last row, with +/// `n` children after it. +fn more(n: usize, last: bool) usize { + if (n == 0 or !last) return 0; + // Two blanks, `+`, N, a blank, `↓`. + return 5 + std.fmt.count("{d}", .{n}); +} + fn testTag(p: *Pardes, arena: std.mem.Allocator) ![]const u8 { return tagline.tagText(p, arena, p.panes[p.view().active].?); } @@ -748,7 +787,7 @@ test "SPC changes nothing in the tag until its level shows 250 ms on, its keys o const level = try testTag(p, a); try std.testing.expect(std.mem.indexOf(u8, level, "␣ ▸ b buffer…") != null); try std.testing.expect(std.mem.indexOf(u8, level, "l lsp…") != null); - try std.testing.expect(std.mem.endsWith(u8, level, "↓ unroll · ? help")); + try std.testing.expect(std.mem.count(u8, level, "\n") < 3); // Down a level: its keys, its children. p.update(.{ .key = .{ .cp = 'l' } }); try std.testing.expect(std.mem.startsWith(u8, try testTag(p, a), "␣ l ▸ a CodeAction b Callstack")); @@ -836,6 +875,50 @@ test "the right block: the count `cursor/matches` at the row's right end, fixed try std.testing.expectEqualStrings("␣ SPC", firstRow(try testTag(narrow, a))); } +test "a rolled level breaks between its children only: the rows after the first from its first child's column under the spines, three at most, the last ending `+N ↓`" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 30 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const tab = p.settings.tab; + const width = tagline.tagWidth(p, p.view().active); + p.update(.{ .key = .{ .cp = ' ' } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + const tag = try testTag(p, a); + var rows: [8][]const u8 = undefined; + var n: usize = 0; + var split = std.mem.splitScalar(u8, tag, '\n'); + while (split.next()) |row| : (n += 1) rows[n] = row; + try std.testing.expectEqual(@as(usize, 3), n); + try std.testing.expect(std.mem.startsWith(u8, rows[0], "␣ ▸ b buffer… ")); + // Each row after the first: the spine under `␣`, then from the first + // child's column; no row wider than the tag. + for (rows[1..n]) |row| try std.testing.expect(std.mem.startsWith(u8, row, "│ ") and row["│ ".len] != ' '); + for (rows[0..n]) |row| try std.testing.expect(panes.File.displayWidth(tab, row) <= width); + // Every child shown is whole on one row; the ones not shown are counted. + var children: [bindings.max_children]bindings.Child = undefined; + const level = bindings.level(p, .leader, "", &children); + var whole: usize = 0; + for (level) |c| { + const item = try std.fmt.allocPrint(a, "{s} {s}", .{ bindings.keyName(c.key), c.label }); + for (rows[0..n]) |row| { + if (std.mem.indexOf(u8, row, item) != null) break; + } else continue; + whole += 1; + } + try std.testing.expect(whole > 0 and whole < level.len); + try std.testing.expect(std.mem.endsWith(u8, rows[n - 1], try std.fmt.allocPrint(a, "+{d} ↓", .{level.len - whole}))); + // A level that fits takes one row; its hints at its end where the row + // has room for them, else none. + p.update(.{ .key = .{ .cp = 'h' } }); + const help = try testTag(p, a); + try std.testing.expect(std.mem.indexOfScalar(u8, help, '\n') == null); + try std.testing.expect(std.mem.startsWith(u8, help, "␣ h ▸ b Build ") and std.mem.endsWith(u8, help, " t Tutor")); +} + test "a leaf run from a level is remembered: underlined there, and said on the line under it" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); defer p.deinit(); diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 83fd76dc..6af0405d 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -1,7 +1,7 @@ == snap group grid=120x41 cursor=7,3 | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol -| ␣ f ▸ c Config f Find g Grep h History n New r Recent s Save ↓ unroll · ? help +| ␣ f ▸ c Config f Find g Grep h History n New r Recent s Save ↓ unroll · ? help | 1 Find zqm | | diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index dd1d34e5..fe5a29ef 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -71,23 +71,11 @@ |30: 0-1 d,#1d2824, 2-179 #67756e,#1d2824, == snap list grid=180x31 cursor=110,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 -|17: ls │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes Symb -|18: g.txt ols All Jumplist -|19: ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|20: /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b -|21: /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c -|22: 1 l1 -|23: 2 MARK a -|24: 3 l3 -|25: 4 l4 -|26: 5 l5 -|27: 6 MARK b -|28: 7 l7 -|29: 8 l8 -== snap ctrln grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 -|19: /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|20: ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|17: ls │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes … +|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|20: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c +|21: 1 l1 |22: 2 MARK a |23: 3 l3 |24: 4 l4 @@ -96,6 +84,19 @@ |27: 7 l7 |28: 8 l8 |29: 9 l9 +== snap ctrln grid=180x31 cursor=110,16 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 +|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|21: 2 MARK a +|22: 3 l3 +|23: 4 l4 +|24: 5 l5 +|25: 6 MARK b +|26: 7 l7 +|27: 8 l8 +|28: 9 l9 +|29: 10 MARK c == snap landed grid=180x31 cursor=97,22 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse |17: ls Follow Del diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index b93030e8..1f2d4fc5 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -2,8 +2,8 @@ | Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit | New Term Find Grep Joincol Delcol | ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume -| / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace w Window -| y ClipYank Y ClipYankMain ↓ unroll · ? help +| │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace +| │ w Window y ClipYank Y ClipYankMain ↓ unroll · ? help | 1 Help Help h Help t Help c Help l | | @@ -41,7 +41,7 @@ | | /tmp/pardes-snap/leader/cwd/cmds.txt:1 == snap spc-h grid=100x41 cursor=7,3 -|2: ␣ h ▸ b Build c Changelog k Keys m Messages t Tutor ↓ unroll · ? help +|2: ␣ h ▸ b Build c Changelog k Keys m Messages t Tutor ↓ unroll · ? help |3: 1 Help Help h Help t Help c Help l |4: |5: @@ -49,8 +49,8 @@ |2: /tmp/pardes-snap/leader/cwd/cmds.txt Keep Save Term Collapse Follow Del == snap unmapped grid=100x41 cursor=7,5 |2: ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume -|3: / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace w Window -|4: y ClipYank Y ClipYankMain x ↓ unroll · ? help +|3: │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace +|4: │ w Window y ClipYank Y ClipYankMain x ↓ unroll · ? help |5: 1 Help Help h Help t Help c Help l == snap help-group grid=100x41 cursor=7,6 |2: /tmp/pardes-snap/leader/cwd/cmds.txt Keep Save Term Collapse Follow Del -- cgit v1.3 From 5c897d00fe064cf8463ef76ea804b0aff6b62f0a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 06:06:54 -0300 Subject: Band, Core, draw, mouse, layout: a band over a terminal or a kind's pane is drawn over its body's top rows, so a transient state never resizes a pty or a kind's view (walk UI polish P1, G3's finding; UX DESIGN.md D6's borrowing and R3, drawn never written, my reading of D5/D6 for these bodies): a band's rows came out of the pane's body in every pane (Core.sync `tag_rows += band_rows`), so `:` or SPC Down in a terminal resized its pty smaller and back, the shell redrew under it and left its prompt row blank (tagnav's row 6 `$ `, ttytaken's prompt line moved two columns), and a PDF's view was re-sized each time; now Band.over (a terminal, a kind's pane) keeps its `band_rows` at 0, the pane's size the user's alone, and the band is painted after every pane's body (draw.render, Band.shownRows: what the band wants held to the body's rows) at the body's first row, its layer's viewport there; mouse.bandPoint reads the same rows; layout.floorRows borrows nothing for it; joinBand takes its rows; TEST FIRST: TagState.zig "a band over a terminal is drawn over its body's top rows: its pty keeps its size across the band's open and close" (a shell: SPC Down, then `:`: band_rows 0, the tag's rows, the pty's rows and columns as at rest, the band layer at the body's top, no resize_pty effect after Esc; on the parent it fails at band_rows: the band's rows were the body's); the terminal test of rolled levels loses its key-cell-alone step (D12 took that state away); core-test 1066/1237 (171 skipped), shell-test's terminal tests 12/12; process-test: tagnav and ttytaken regenerated and read: tagnav's tty-on and column-tag snaps have the shell's `$ ` on row 6 again (G2's golden), ttytaken's at-prompt row 5 is ` echo TAKEN''ONE` again (main's; E2's two-column shift was the resize's redraw); a user met it at every `:` or band in a terminal Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 16 ++++++++++++++++ core/Core.zig | 3 ++- core/TagState.zig | 42 ++++++++++++++++++++++++++++++++++++------ core/draw.zig | 15 +++++++++++---- core/layout.zig | 2 +- core/mouse.zig | 5 +++-- test/snapshots/tagnav.golden | 2 ++ test/snapshots/ttytaken.golden | 2 +- 8 files changed, 72 insertions(+), 15 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 0d4891aa..07c2f83d 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -113,6 +113,22 @@ pub fn takes(p: *Pardes, id: usize) u16 { return @max(doc_rows, levelRows(n)); } +/// A terminal's and a kind's band is drawn over the top rows of its body +/// (UX D6's borrowing, R3: drawn, never written): a transient state never +/// resizes a pty under a program or a kind's view (a PDF's), whose size +/// only the user's resize changes. Their `band_rows` stay 0. +pub fn over(pane: *const Pane) bool { + return pane.isTerminal() or pane.addon != null; +} + +/// The rows pane `id`'s band is drawn on: those it takes from the layout, +/// or over a terminal's or a kind's body, as many of its body rows as the +/// band wants. +pub fn shownRows(p: *Pardes, pane: *const Pane, id: usize) u16 { + if (pane.band_rows > 0 or !over(pane) or pane.collapsed) return pane.band_rows; + return @min(takes(p, id), p.view().rects[id].h -| pane.tag_rows); +} + fn levelRows(n: u16) u16 { return if (n > one_column) (n + 1) / 2 else n; } diff --git a/core/Core.zig b/core/Core.zig index e43f9e83..26860365 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2062,7 +2062,8 @@ pub fn sync(p: *Pardes) void { } else pane.tag_top = 0; // The band unrolled under the tag's text pushes the body down: // the tag's rows, as everything under them counts them. - pane.band_rows = if (pane.collapsed) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows); + // A terminal's or a kind's is drawn over its body instead (Band.over). + pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows); pane.tag_rows += pane.band_rows; const cols = @max(1, r.w -| config.GUTTER); // The tag steals the top rows. The pty is what the pane shows diff --git a/core/TagState.zig b/core/TagState.zig index 18fd5fac..c364451a 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -1178,12 +1178,6 @@ test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC' p.sync(); const rows, const tag_rows = .{ pane.rows, pane.tag_rows }; p.update(.{ .key = root }); - // Its key cell alone, before the level shows: shorter than the - // tag's own text, the rows it had. - p.sync(); - try std.testing.expect(hostOf(p) == shell); - try std.testing.expectEqual(tag_rows, pane.tag_rows); - try std.testing.expectEqual(rows, pane.rows); p.advance(p.clock.now_ns); p.clock.now_ns = p.view().tag_state.due_ns; p.sync(); @@ -1193,6 +1187,42 @@ test "a terminal's rolled level keeps its tag rows at every width, C-w's as SPC' }; } +test "a band over a terminal is drawn over its body's top rows: its pty keeps its size across the band's open and close" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .file = "mise.toml", .cols = 100, .rows = 30 }); + defer p.deinit(); + _ = pardes.exec.spawnTty(p, 0); + const shell = p.view().active; + const pane = p.panes[shell].?; + pane.body.mode = .normal; + p.sync(); + while (p.nextEffect()) |_| {} + const rows, const cols, const tag_rows = .{ pane.rows, pane.cols, pane.tag_rows }; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + // SPC unrolled, then `:`'s rows (the tagnav case): a band each, over + // the body; no resize of the pty while it is open, nor when it goes. + for ([_][]const Key{ &.{ .{ .cp = ' ' }, .{ .cp = Key.down } }, &.{.{ .cp = ':' }} }) |keys| { + for (keys) |k| p.update(.{ .key = k }); + p.sync(); + try std.testing.expect(hostOf(p) == shell); + try std.testing.expectEqual(@as(u16, 0), pane.band_rows); + try std.testing.expectEqual(tag_rows, pane.tag_rows); + try std.testing.expectEqual(rows, pane.rows); + try std.testing.expectEqual(cols, pane.cols); + _ = frame.reset(.retain_capacity); + _ = try p.render(frame.allocator()); + const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; + try std.testing.expect(layer.kind == .band and layer.rows > 0); + try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[shell]), layer.viewport.y); + p.update(.{ .key = .{ .cp = Key.escape } }); + p.sync(); + try std.testing.expectEqual(rows, pane.rows); + while (p.nextEffect()) |e| try std.testing.expect(e != .resize_pty); + } +} + test "a tag out of rest keeps its rows at rest at least: a level shorter than its own text moves no body up" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 30 }); defer p.deinit(); diff --git a/core/draw.zig b/core/draw.zig index 17ac7514..f69f83c6 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -357,6 +357,12 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { s.body_layers[id].rows = 0; try renderPane(p, s, arena, pane, v.rects[id], id, id == v.active); } + // A band over a terminal's or a kind's body (Band.over), drawn after + // the body it covers. + if (TagState.hostOf(p)) |id| if (p.panes[id]) |pane| if (pane.band_rows == 0) { + const rows = pardes.Band.shownRows(p, pane, id); + if (rows > 0) try joinBand(p, s, arena, pane, v.rects[id], id, id == v.active, rows); + }; // Each notice once, as a tag layer, and the grid's chip a copy of it. for (s.regionList()) |region| { if (region.kind == .notice) try joinNotice(p, s, arena, region); @@ -495,7 +501,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: try joinPaneTag(p, s, arena, pane, r, id, active); // The keyboard is in the head's field: its caret, not the body's. const head_caret = if (typing) s.cursor else null; - if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active); + if (pane.band_rows > 0) try joinBand(p, s, arena, pane, r, id, active, pane.band_rows); // Folded panes retain their body state, but neither body pixels nor // its cursor belong outside the one-row tag rectangle. @@ -868,14 +874,13 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r /// layer at the tagline's pitch, a row to a line, and copied into the /// grid: the spines and steps in the tag's tint, the keys in the key ink, /// the cursor's row tinted as a selection. -fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { +fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool, rows: u16) !void { const layer = &s.tag_layers[pardes.BAND_LAYER]; if (r.w <= TAG_TEXT_INSET) return; const band = (try pardes.Band.of(p, arena, pane, id)) orelse return; const th = p.theme(); const chrome = p.chromeTheme(); const tab = p.settings.tab; - const rows = pane.band_rows; const columns = @max(band.columns, 1); const bg = tagGround(p, pane, active); const fg = if (active) chrome.tag_active_fg else chrome.tag_fg; @@ -921,7 +926,9 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R const count = @as(usize, columns) * rows; if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); @memcpy(layer.cells, storage); - const y0 = p.tagTop(pane, r) + (pane.tag_rows - rows); + // Under the tag's text rows; a terminal's or a kind's over its body's + // top rows (Band.over). + const y0 = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows); layer.kind = .band; layer.id = @intCast(id); layer.serial = pane.serial; diff --git a/core/layout.zig b/core/layout.zig index 0a773cab..de12294b 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -1476,7 +1476,7 @@ pub fn compute(p: *Pardes) void { /// (walk UI SPEC §3.6). fn floorRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return 0; - const band = pardes.Band.takes(p, id); + const band = if (pardes.Band.over(pane)) 0 else pardes.Band.takes(p, id); if (band > 0) return @max(1, pane.tag_rows -| pane.band_rows) + band + 4; return if (pane.isTerminal()) @max(1, pane.tag_rows) + min_body_rows else 1; } diff --git a/core/mouse.zig b/core/mouse.zig index 89a8c5c6..6516ea71 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -914,10 +914,11 @@ fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint { if (v.pointer_tag_hit) |hit| return if (hit.kind == .band) .{ .id = hit.id, .line = hit.line, .col = hit.col } else null; const id = paneAt(p, mcol, mrow) orelse return null; const pane = p.panes[id].?; - if (pane.band_rows == 0) return null; + const rows = pardes.Band.shownRows(p, pane, id); + if (rows == 0) return null; const r = v.rects[id]; const top = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows); - if (mrow < top or mrow >= top + pane.band_rows or mcol < r.x + TAG_TEXT_INSET) return null; + if (mrow < top or mrow >= top + rows or mcol < r.x + TAG_TEXT_INSET) return null; return .{ .id = id, .line = mrow - top, .col = mcol - (r.x + TAG_TEXT_INSET) }; } diff --git a/test/snapshots/tagnav.golden b/test/snapshots/tagnav.golden index 9bf061bc..1039c40a 100644 --- a/test/snapshots/tagnav.golden +++ b/test/snapshots/tagnav.golden @@ -42,12 +42,14 @@ == snap tty-on grid=100x31 cursor=54,6 |2: /tmp/pardes-snap/tagnav/cwd/w.txt Save Term Coll$ /tmp/pardes-snap/tagnav/cwd Term+bash Save Mode |4: 1 alpha $ ls +|6: 3 gamma $ |30: ✓ /tmp/pardes-snap/tagnav/cwd/w.txt Window 5 messages · SPC h m == snap tty-tag grid=100x31 cursor=95,2 == snap tty-restored grid=100x31 cursor=54,6 == snap column-tag grid=100x31 cursor=2,1 |2: /tmp/pardes-snap/tagnav/cwd/w.txt Save Term Coll /tmp/pardes-snap/tagnav/cwd Term+bash Save Mode |4: 1 alpha ls +|6: 3 gamma |30: ✓ /tmp/pardes-snap/tagnav/cwd/w.txt Up 8 messages · SPC h m == snap column-word grid=100x31 cursor=5,1 == snap workspace-tag grid=100x31 cursor=2,0 diff --git a/test/snapshots/ttytaken.golden b/test/snapshots/ttytaken.golden index a2011891..337072f1 100644 --- a/test/snapshots/ttytaken.golden +++ b/test/snapshots/ttytaken.golden @@ -32,7 +32,7 @@ | /tmp/pardes-snap/ttytaken/cwd == snap at-prompt grid=210x31 cursor=4,5 |2: /tmp/pardes-snap/ttytaken/cwd Term+bash Save Mode Filter Collapse Del @`echo TAKEN''ONE` -|5: echo TAKEN''ONE +|5: echo TAKEN''ONE |6: TAKENONE |30: ✓ @p1 Exec 1 message · SPC h m == snap paging grid=210x31 cursor=9,29 -- cgit v1.3 From ea9a19700cc1c0bc22c08b1d31d7a62e5853b802 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 06:20:03 -0300 Subject: Pick, layout, Core, Band: the band's height: a picker's from its list at open, four rows at least, 40 % of its column at most, never moved by typing; the body keeps 60 % of its pane and six rows, borrowed from its column, and the band gives way before the body drops under six (walk UI polish P1, UX DESIGN.md D6, C8): a picker's band was as tall as its list (three hits, three rows; no cap), so a short list's band was a sliver and a long one took a short pane's body down to four rows (shot 04-L: four body rows of 18); now Pick.bandRows is min(11, max(4, what the source has), 40 % of the rows of the host's column: its panes' rows, which a borrow only moves between them, so the height never changes while typing), the rows fewer than it leaving the band's ground (and its spines) under them; layout.floorRows keeps a band's pane its band and a body of one and a half times what is above it (60 % of the pane) and six rows at least (Band.body_rows), borrowed from the column's other panes as before; Core.sync's band takes what leaves the body six rows, so a column too short for 60 % shrinks the band, never the body under six; TEST FIRST: Pick.zig "a picker's band is sized from its list at open, 4 rows at least, and typing never moves it" (two files: four rows, the same after `zzq` with nothing matching; on the parent two rows), Band.zig "a band keeps its pane's body 60 % of the pane, borrowed from its column; where the column has not the rows, the band gives way before the body drops under 6" (three panes in 40 rows: the body 60 % of the pane; in 12 rows the band shorter than it wants, the body six), the borrow test's body six rows (was four); core-test 1068/1239 (171 skipped); process-test: find, fsearch, lsp regenerated and read: each picker band four rows where its list has two or three (find's two files, fsearch's three places, lsp's three symbols), the rows under the list the band's ground with the spines on through it, the body that much lower; a user saw a picker's band change size with its source, and a short pane's body crushed Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Band.zig | 35 +++++++++++++++++++++++++++++++++-- core/Core.zig | 2 +- core/Pick.zig | 42 ++++++++++++++++++++++++++++++++++++++---- core/layout.zig | 12 ++++++++---- test/snapshots/find.golden | 10 ++++++++-- test/snapshots/fsearch.golden | 27 +++++++++++++-------------- test/snapshots/lsp.golden | 25 +++++++++++++------------ 7 files changed, 114 insertions(+), 39 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index 07c2f83d..e34b6a49 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -73,6 +73,8 @@ pub const max_spines = 12; pub const min_width = 24; /// A doc's rows, the fewest a band with one has. const doc_rows = 4; +/// The body rows a band leaves its pane at least: it gives way first (UX D6). +pub const body_rows = 6; /// A level's rows past which it flows into two columns. const one_column = 9; @@ -635,7 +637,35 @@ test "SPC Down unrolls the level into a band under the tag's text, the body push try std.testing.expect(!p.view().tag_state.unrolled); } -test "a pane whose body would drop below four rows under its band borrows them from its column" { +test "a band keeps its pane's body 60 % of the pane, borrowed from its column; where the column has not the rows, the band gives way before the body drops under 6" { + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + const top = p.view().active; + p.newScratchBelow(top); + const low = p.view().active; + p.newScratchBelow(low); + p.view().active = low; + p.sync(); + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = Key.down } }); + const pane = p.panes[low].?; + const r = p.view().rects[low]; + try std.testing.expect(pane.band_rows >= doc_rows); + try std.testing.expect(@as(u32, r.h -| pane.tag_rows) * 5 >= @as(u32, r.h) * 3); + p.update(.{ .key = .{ .cp = Key.escape } }); + // A window of 12 rows: the band shrinks, the body keeps 6. + p.update(.{ .resize = .{ .cols = 120, .rows = 12 } }); + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = Key.down } }); + p.sync(); + const short = p.view().rects[low]; + try std.testing.expect(short.h -| pane.tag_rows >= 6 or pane.band_rows == 0); + try std.testing.expect(pane.band_rows < Band.takes(p, low)); +} + +test "a pane whose body would drop below six rows under its band borrows them from its column" { const Key = pardes.Key; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 24 }); defer p.deinit(); @@ -652,7 +682,8 @@ test "a pane whose body would drop below four rows under its band borrows them f const pane = p.panes[low].?; const r = p.view().rects[low]; try std.testing.expect(r.h > before); - try std.testing.expect(r.h -| pane.tag_rows >= 4); + // Its body six rows at least (UX D6): a column too short for 60 %. + try std.testing.expect(r.h -| pane.tag_rows >= 6); // No pane dims out of rest (UX D9): the others look as at rest. var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); diff --git a/core/Core.zig b/core/Core.zig index 26860365..5b6eba75 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -2063,7 +2063,7 @@ pub fn sync(p: *Pardes) void { // The band unrolled under the tag's text pushes the body down: // the tag's rows, as everything under them counts them. // A terminal's or a kind's is drawn over its body instead (Band.over). - pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows); + pane.band_rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), r.h -| pane.tag_rows -| pardes.Band.body_rows); pane.tag_rows += pane.band_rows; const cols = @max(1, r.w -| config.GUTTER); // The tag steals the top rows. The pty is what the pane shows diff --git a/core/Pick.zig b/core/Pick.zig index 52976f15..52e9601d 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -624,13 +624,18 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { return h; } -/// The band's rows: as many as the list will show, eleven at most, from -/// what the source has (not what the query keeps: typing never moves the -/// body). +/// The band's rows (UX D6): as many as the list will show, from what the +/// source has (not what the query keeps: typing never moves the body), +/// four at least, eleven at most, and 40 % of the host's column at most +/// (its panes' rows, which a borrow moves between them, never changes). pub fn bandRows(p: *const Pardes) u16 { const pk = live(p) orelse return 0; const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len; - const rows: usize = @max(1, @min(Band.Cursor.shown, have)); + const v = p.view(); + const at = @import("layout.zig").findPane(p, TagState.hostOf(p) orelse return 0) orelse return 0; + var column: usize = 0; + for (v.cols[at.col].panes[0..v.cols[at.col].n]) |id| column += v.rects[id].h; + const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), column * 2 / 5)); // Its second step's rows too: the sources, the acts and what they act on. return @intCast(switch (pk.spine) { .sources => @max(rows, spine_rows.len), @@ -1578,6 +1583,35 @@ test "a picker's act row is one row under the spines, two cells right of the las try std.testing.expect(h.spans[h.spans.len - 1].style == .dim); } +test "a picker's band is sized from its list at open, 4 rows at least, and typing never moves it" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + // In the test's directory: its two files listed. + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + p.stream.engine = .walk; + open(p, asker, .find, "", "", ""); + settle(p); + const reader = p.paneBySerial(live(p).?.landing).?; + p.sync(); + const rows = p.panes[reader].?.band_rows; + // One or two files listed: four rows, ground under them. + try std.testing.expectEqual(@as(u16, 4), rows); + for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + p.sync(); + try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); + try std.testing.expectEqual(rows, p.panes[reader].?.band_rows); +} + test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); diff --git a/core/layout.zig b/core/layout.zig index de12294b..5550ef4a 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -1471,13 +1471,17 @@ pub fn compute(p: *Pardes) void { /// The fewest rows a pane is laid out with: a terminal keeps its tag and /// `min_body_rows` (a shorter one loses its prompt and reads busy for /// ever), a text pane may shrink to its tag, as acme's windows do. A tag -/// out of rest keeps its band and four body rows, borrowed from the -/// column's other panes, which shrink to their tags until it rolls up -/// (walk UI SPEC §3.6). +/// out of rest keeps its band and a body of 60 % of the pane and 6 rows at +/// least (UX D6), borrowed from the column's other panes, which shrink to +/// their tags until it rolls up (walk UI SPEC §3.6). fn floorRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return 0; const band = if (pardes.Band.over(pane)) 0 else pardes.Band.takes(p, id); - if (band > 0) return @max(1, pane.tag_rows -| pane.band_rows) + band + 4; + if (band > 0) { + const above = @max(1, pane.tag_rows -| pane.band_rows) + band; + // A body of 60 % is one and a half times what is above it. + return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2); + } return if (pane.isTerminal()) @max(1, pane.tag_rows) + min_body_rows else 1; } diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index 6af0405d..da1b0e4e 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -77,7 +77,9 @@ |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist |4: │ │ nothing matches |5: │ │ -|6: 1 beta body +|6: │ │ +|7: │ │ +|8: 1 beta body |40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find 2 messages · SPC h m == snap cancel grid=120x41 cursor=7,3 |2: here.txt:1 › Find zqm 2/3 › /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Keep Save Term Collapse Follow Del @@ -85,10 +87,14 @@ |4: |5: |6: +|7: +|8: == snap topbar grid=120x41 cursor=29,2 |2: ^ Find zqm 2/3 › ␣ f Find bod 0 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist |4: │ │ nothing matches |5: │ │ -|6: 1 beta body +|6: │ │ +|7: │ │ +|8: 1 beta body |40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find ×2 2 messages · SPC h m diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index fe5a29ef..905d2ef0 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -75,7 +75,19 @@ |18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a |19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b |20: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c -|21: 1 l1 +|21: │ │ +|22: 1 l1 +|23: 2 MARK a +|24: 3 l3 +|25: 4 l4 +|26: 5 l5 +|27: 6 MARK b +|28: 7 l7 +|29: 8 l8 +== snap ctrln grid=180x31 cursor=110,16 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 +|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b |22: 2 MARK a |23: 3 l3 |24: 4 l4 @@ -84,19 +96,6 @@ |27: 7 l7 |28: 8 l8 |29: 9 l9 -== snap ctrln grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 -|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b -|21: 2 MARK a -|22: 3 l3 -|23: 4 l4 -|24: 5 l5 -|25: 6 MARK b -|26: 7 l7 -|27: 8 l8 -|28: 9 l9 -|29: 10 MARK c == snap landed grid=180x31 cursor=97,22 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse |17: ls Follow Del diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 94958ba4..06127538 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -62,18 +62,19 @@ |4: │ │ ▶ a.zig:1:7-9 std |5: │ │ a.zig:3:4-9 helper |6: │ │ a.zig:7:8-11 main -|7: 1 const std = @import("std"); -|8: 2 -|9: 3 fn helper(x: u32) u32 { -|10: fn helper(x: u32) u32 -|11: (fn (u32) u32) -|12: 4 return x + 1; -|13: 5 } -|14: 6 -|15: 7 pub fn main() void { -|16: 8 _ = helper(41); -|17: 9 } -|18: ~ +|7: │ │ +|8: 1 const std = @import("std"); +|9: 2 +|10: 3 fn helper(x: u32) u32 { +|11: fn helper(x: u32) u32 +|12: (fn (u32) u32) +|13: 4 return x + 1; +|14: 5 } +|15: 6 +|16: 7 pub fn main() void { +|17: 8 _ = helper(41); +|18: 9 } +|19: ~ |40: ✓ /tmp/pardes-snap/lsp/cwd/a.zig Symbols 2 messages · SPC h m == snap step grid=120x41 cursor=27,2 |2: ^ a.zig:8 › ␣ l Symbols jn 0 -- cgit v1.3 From 56ca48879da0dd335097d695fb7f4b4b6fe5157b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 06:26:22 -0300 Subject: Band, draw: drawing the band: its steps from two cells right of the last spine and the spines kept at every width, a list's rows 52 cells at most, a give-way that never clips, the cursor's row tinted across its step, the spines on through the tag's rows under the head (walk UI polish P1, UX DESIGN.md D5, geometry; the colours stay today's fields, `// P2: the rule role` where a spine is drawn): a band narrower than its steps dropped its spines and started its steps at the pane's left edge (shots 04-L, 08-L), a level or a list was as wide as its widest row whatever its length, and the tag's rows kept from rest under a one-row head were bare where the spines should run; now Band.place starts at the last spine + 2 always, makes a level's column its widest row and a list's 52 cells at most (`row_cells`), and gives way in UX D5's order: the head's hints first (D3), the doc leaves the band where it has no 24 cells, the last list unrolled (a picker's acts, M-l) takes the place of the others where they do not all fit, and one step left is held to the room there is (24 cells at least), its rows cut with `…` (D2's Band.cutRow): nothing runs off the right edge; draw.joinBand tints the cursor's row across its step's width, its `▶ ` lead too; draw.paintPaneTag draws a `│` under each key cell in the tag's rows under the head's own (the rows a tag keeps from rest, A2's rule), so the spines run unbroken from the head into the band; the box glyph stays on row 1 alone, the grip column under it the tag's ground (as it was in a terminal; the window's grip seams and the tag rule's place under the band are the window's: see the screenshots), the row meta of D5 is not built (no step has right-hand meta yet); TEST FIRST: Band.zig "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the spines run on through the tag's rows under the head" (44 columns, Help for SPC l: two spines, one step at the last spine + 2, every row within the band, `│` in the tag's second row under each key cell; on the parent the spines are dropped: 0, and the second row is blank); core-test 1069/1240 (171 skipped); process-test: fsearch regenerated and read: its nomatch snap's tag keeps two rows under a one-row prompt head, the second now with a `│` under the `/` key cell; a user saw the band lose its spines at 26 px 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/Band.zig | 61 ++++++++++++++++++++++++++++++++++++------- core/draw.zig | 21 +++++++++++++-- test/snapshots/fsearch.golden | 2 +- 3 files changed, 72 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/Band.zig b/core/Band.zig index e34b6a49..2b688a61 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -71,6 +71,8 @@ pub const max_steps = 4; pub const max_spines = 12; /// The narrowest a step is drawn (SPEC §3.6: box, spines, one 24-cell column). pub const min_width = 24; +/// The widest a list's rows are laid out (UX D5). +const row_cells = 52; /// A doc's rows, the fewest a band with one has. const doc_rows = 4; /// The body rows a band leaves its pane at least: it gives way first (UX D6). @@ -375,26 +377,33 @@ pub fn docStep(p: *Pardes, arena: std.mem.Allocator, root: bindings.Root, path: return .{ .rows = rows.items, .doc = true }; } -/// Where each step goes: right of the spines, a rule's cell between steps; -/// a doc takes what is left, wrapped to it. Narrow, the doc goes first, -/// then the spines (the steps start at the band's left edge). +/// Where each step goes (UX D5): from two cells right of the last spine, +/// a rule's cell between steps; a level as wide as its widest row (two +/// columns past nine), a list of rows `row_cells` at most, a doc the width +/// the others leave, wrapped to it, `min_width` at least. Narrower than +/// the steps (the hints already gone from the head), the band gives way: +/// the doc leaves it, then the last step unrolled (a picker's acts) takes +/// the place of the others; one step left is held to the room there is, +/// its rows cut with `…` (Band.cutRow): the spines stay, nothing is clipped +/// off the right edge. fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !void { const tab = p.settings.tab; try band.findSpines(p, arena, pane, id); - var x: u16 = if (band.nspines > 0) band.spines[band.nspines - 1] + 2 else 0; + const x0: u16 = if (band.nspines > 0) band.spines[band.nspines - 1] + 2 else 0; var need: u16 = 0; + var lists: u8 = 0; for (band.steps[0..band.nsteps]) |*step| { if (step.doc) continue; var widest: usize = 0; for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text)); - const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4, @max(min_width, band.columns -| x))); + const column: u16 = @intCast(@min(widest, row_cells) + 2); step.width = if (step.two) 2 * column + 1 else column; need += step.width + 2; + lists += 1; } - if (x + need > band.columns) { - band.nspines = 0; - x = 0; - } + // The last list alone where they do not all fit. + var skip: u8 = if (x0 + need > band.columns and lists > 1) lists - 1 else 0; + var x = x0; var kept: u8 = 0; for (band.steps[0..band.nsteps]) |step| { var placed = step; @@ -403,6 +412,12 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi if (room < min_width) continue; placed.width = room; placed.rows = try wrap(arena, tab, step.rows, room -| 1, band.height); + } else { + if (skip > 0) { + skip -= 1; + continue; + } + placed.width = @min(placed.width, @max(band.columns -| x, @min(min_width, band.columns))); } placed.x = x; x +|= placed.width + 2; @@ -562,6 +577,34 @@ fn layerRow(arena: std.mem.Allocator, layer: *const pardes.Layer, row: usize) ![ return out.items; } +test "a narrow band gives way and keeps its spines: the doc goes, the steps start two cells right of the last spine, no row past the band's edge; the spines run on through the tag's rows under the head" { + const Key = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 44, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + p.sync(); + try std.testing.expect(pane.tag_rows > 1); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // Help for SPC l: its key cells `␣ l`, its rows, no room for a doc. + for ([_]u21{ ' ', 'l', '?' }) |c| p.update(.{ .key = .{ .cp = c } }); + p.sync(); + const band = (try of(p, a, pane, id)).?; + try std.testing.expectEqual(@as(u8, 2), band.nspines); + try std.testing.expectEqual(@as(u8, 1), band.nsteps); + try std.testing.expectEqual(band.spines[1] + 2, band.steps[0].x); + for (0..band.height) |y| try std.testing.expect(File.displayWidth(p.settings.tab, (try band.line(a, p.settings.tab, @intCast(y))).text) <= band.columns); + // The tag's second row, kept from rest under the head's one: a spine + // under each key cell. + const s = try p.render(a); + const r = p.view().rects[id]; + const tag_y = p.tagTop(pane, r); + for (band.spines[0..band.nspines]) |col| try std.testing.expectEqualStrings("│", s.at(r.x + pardes.TAG_TEXT_INSET + col, tag_y + 1).grapheme()); + p.update(.{ .key = .{ .cp = Key.escape } }); +} + test "a row longer than its room is cut with `…`: a path from the left, anything else from the right, its marks and faint bytes moved with it" { var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); defer arena.deinit(); diff --git a/core/draw.zig b/core/draw.zig index f69f83c6..be4230c4 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -903,7 +903,8 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R } for (ln.parts) |part| { const end = @min(columns, part.col + part.width); - if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, th.tag_sel_bg orelse th.sel_bg, th.sel_fg); + // The cursor's row across its step's width, its lead too (UX D5). + if (part.row.on and part.col < end) t.tint(part.col -| 2, row, end - (part.col -| 2), th.tag_sel_bg orelse th.sel_bg, th.sel_fg); var c = part.col; var b: usize = 0; while (b < part.row.text.len and c < end) : (c += 1) { @@ -999,7 +1000,11 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, var lines: [MAX_TAG_ROWS][]const u8 = @splat(""); var split = std.mem.splitScalar(u8, shown.text, '\n'); for (0..top) |_| _ = split.next(); - for (lines[0..rows]) |*line| line.* = split.next() orelse ""; + var nlines: usize = 0; + for (lines[0..rows]) |*line| { + line.* = split.next() orelse continue; + nlines += 1; + } // The keyboard's caret, as a row and a byte offset in that row's // line: in the tag's own text when the tag has the keyboard, in the // path while a name is drafted. @@ -1026,6 +1031,18 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll)); _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } + // Out of rest the rows the tag keeps from rest under the head's own: + // the spines on through them, under the key cells (UX D5). + if (head) |h| if (top == 0 and nlines < rows and h.cells > 0) { + const first = lines[0]; + for (h.spans[0..h.cells]) |cell| { + const at = prefix_len + cell.lo; + if (at > first.len) break; + const col = panes.File.rawDisplayCol(p.settings.tab, first, at); + if (col >= tw) break; + for (nlines..rows) |row| s.set(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row)), "│", .{ .fg = .{ .rgb = chrome.box }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); // P2: the rule role (UX D4) + } + }; // The pane's progress at its first row's right end, where the row has // room for it (SPEC §10.2); out of rest the head's right block is // there (UX D1). diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 905d2ef0..59037755 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -130,4 +130,4 @@ == snap cancel grid=180x31 cursor=97,23 == snap nomatch grid=180x31 cursor=118,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · esc -|17: ls +|17: ls │ -- cgit v1.3 From c51ecfb07e4c5d091d0155c609205c7e5f6bc0b1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 06:31:43 -0300 Subject: Trail, tagline, draw, Prompt: the trail at rest: the steps past the newest three fold into one dim `+N ›` after the owner, fewer whole while the walk would add a row to the tag, the forward steps past two into one `› +N`, two files of the same name told apart by the shortest end of their paths, the word n walks underlined (walk UI polish P1, UX DESIGN.md D8, C3): each folded step was a `·` of its own (four cells each, nameless), the walk took the rows it wanted (05a-L, 05b-L: a reader's tag two rows at rest, so a jump moved the body), and two `x.zig` steps read alike; now Trail.foldOf names the folded steps (back: those older than the newest `whole`, never the owner; forward: those past `shown_ahead` = 2), Trail.wordIn writes the first of them as `+N` and nothing for the others (out of rest `.newest` as D1 made it), Trail.stepAt maps a click on `+N` to the step nearest the path among those it holds (a Look on `+2` goes back to the newest hidden step: the band step D8 asks for, the whole trail unrolled newest first, is not built), wordOf names a place by the shortest end of its path no other step's file shares (`core/rank.zig:2` beside `/rank.zig:12`; the same file at two lines keeps its basename), Trail.walked is the newest list or search back step (what Pick.walkList and the prompts' n walk) and draw.paintPaneTag underlines it in the box's ink (`// P2: the key role`), the fold's `+N` drawn in the forward steps' dim ink; tagline.folded is how many back steps stay whole: three, fewer down to the newest one while the walk's cells would make the tag at rest take more rows than it takes with no walk (the tag's cells, not its wrap: one line), which nameAt, forwardSpan, trailAt, onName, restPath and Prompt.unlit read (Trail.folded's constant `shown_steps` until now); seed 109 of ninep's random placements is NOT fixed by it (tried with the test under the walk: column 2 under its minimums at step 36, the newest step alone still adds a row in a column with no rows to give), so that test keeps `Jumps new-pane`; TEST FIRST: Trail.zig "a trail keeps its newest three back steps whole, older ones fold into one dim `+N` after the owner ..." (six steps at 400 columns: `‹@pN › +2 › rank.zig:30 › rank.zig:40 › rank.zig:50 ›`, the `+2` in the dim ink, a click on it back at rank.zig:20; back at the first, `› rank.zig:20 › rank.zig:30 › +3 Keep`; on the parent `· ›` per step: fails), "the walk never adds a row to a tag at rest ..." (a width 35 cells past the bare tag: one row with a `+N` fold; on the parent two rows), "two steps whose files have the same name are told apart ...; the word n walks is underlined"; core-test 1071/1242 (171 skipped); process-test: fsearch and lookrange regenerated and read: fsearch's landed/n/N reader tag `‹@p1 › +1 › /MARK/ 2/3 › …/g.txt Keep ...` (its two rows at rest: the newest alone still wraps there, g.txt:1 folded), lookrange's hit1/hit2/back style rows underline `/NEEDLE/ 2/2` (cols 2-13), the word n walks; a user saw the body move a row at a jump 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/Prompt.zig | 4 +- core/Trail.zig | 192 +++++++++++++++++++++++++++++++++------- core/draw.zig | 35 ++++++-- core/tagline.zig | 53 ++++++++--- test/snapshots/fsearch.golden | 8 +- test/snapshots/lookrange.golden | 4 +- 6 files changed, 236 insertions(+), 60 deletions(-) (limited to 'core') diff --git a/core/Prompt.zig b/core/Prompt.zig index 27b59649..c3d9959a 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -811,9 +811,9 @@ pub fn execWord(p: *Pardes, id: usize) void { pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; - const whole = Trail.shown_steps; + const whole = pardes.tagline.folded(p, pane); for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { - if (lights(pane, &step.search) or t.cur - i > whole) return null; + if (lights(pane, &step.search) or t.isFolded(i, whole)) return null; return t.spanOf(i, whole); }; return null; diff --git a/core/Trail.zig b/core/Trail.zig index 58a72256..e22a58b6 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -318,18 +318,36 @@ pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool { pub const Part = enum { back, forward, newest }; /// 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, whole: usize, buf: *[max_text + 16]u8) []const u8 { - const s = &t.steps[i]; - if (s.* != .owner and i < t.cur and t.cur - i > whole) return "·"; +/// own text. A place's file is named by its basename, or where another +/// step's file has the same one, by the shortest end of its path the other +/// does not share (UX D8: `core/x.zig:3` beside `dev/x.zig:9`). +fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 { // The step itself, not a copy: a word's text is the step's own bytes. - return switch (s.*) { + return switch (t.steps[i]) { .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 + .place => |*at| place: { + const path = at.path.slice(); + var from = if (std.mem.lastIndexOfScalar(u8, path, '/')) |slash| slash + 1 else 0; + 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(), }; } +/// Whether another step's file, not step `i`'s, has a path ending in `end` +/// at a `/`. +fn shared(t: *const Trail, i: usize, end: []const u8) bool { + const own = t.steps[i].place.path.slice(); + for (t.steps[0..t.n], 0..) |*s, j| { + if (j == i or s.* != .place) continue; + const path = s.place.path.slice(); + if (std.mem.eql(u8, path, own) or !std.mem.endsWith(u8, path, end)) continue; + if (path.len == end.len or path[path.len - end.len - 1] == '/') return true; + } + return false; +} + const sep = " › "; /// The steps a part writes. @@ -340,20 +358,36 @@ fn range(t: *const Trail, part: Part) [2]usize { }; } -/// Whether step `i` is in what `part` writes: out of rest the owner and -/// the newest back step only. -fn writes(t: *const Trail, part: Part, i: usize) bool { - return part != .newest or t.steps[i] == .owner or i + 1 == t.cur; +/// 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 { + 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) }; + }, + .forward => .{ @min(t.n, t.cur + 1 + shown_ahead), t.n }, + .newest => .{ 0, 0 }, + }; } /// 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; -/// Step `i`'s word as `part` writes it: out of rest a word longer than -/// `newest_cells` keeps its first and last cells around a `…`. -fn shownWord(t: *const Trail, part: Part, i: usize, whole: usize, buf: *[max_text + 16]u8, cut: *[max_text + 16]u8) []const u8 { - const word = wordOf(t, i, whole, buf); +/// Step `i`'s word as `part` writes it, null where it writes none: a +/// folded step's is the fold's `+N` on its first, none on the others; out +/// 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; + 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 if (panes.File.displayWidth(tab, word) <= newest_cells) return word; @@ -364,15 +398,16 @@ fn shownWord(t: *const Trail, part: Part, i: usize, whole: usize, buf: *[max_tex } /// 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 newest `whole` back steps whole, older ones `·` (`folded`). +/// 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 +/// 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; var cut: [max_text + 16]u8 = undefined; const r = range(t, part); - for (r[0]..r[1]) |i| if (writes(t, part, i)) switch (part) { - .back, .newest => try w.print("{s}" ++ sep, .{shownWord(t, part, i, whole, &buf, &cut)}), - .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, whole, &buf)}), + for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| switch (part) { + .back, .newest => try w.print("{s}" ++ sep, .{word}), + .forward => try w.print(sep ++ "{s}", .{word}), }; } @@ -382,12 +417,23 @@ pub fn bytes(t: *const Trail, part: Part, whole: usize) usize { var cut: [max_text + 16]u8 = undefined; var n: usize = 0; const r = range(t, part); - for (r[0]..r[1]) |i| if (writes(t, part, i)) { - n += shownWord(t, part, i, whole, &buf, &cut).len + sep.len; + for (r[0]..r[1]) |i| if (wordIn(t, part, whole, i, &buf, &cut)) |word| { + n += word.len + sep.len; }; return n; } +/// 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; + while (i > 0) { + i -= 1; + if (t.steps[i] == .list or t.steps[i] == .search) return @intCast(i); + } + return null; +} + /// Whether pane `pane`'s tag is out of rest in the live view (UX D1: its /// path, its forward steps and its own words hidden, the owner and the /// newest step before the head). Asking is rest. @@ -396,13 +442,26 @@ pub fn outOfRest(p: *const Pardes, pane: *const Pane) bool { return p.panes[host] == pane; } -/// Where back step `i`'s word is in what `write` writes for the back -/// steps, the newest `whole` whole. +/// Where back step `i`'s word (the fold's `+N` for a folded one) is in +/// what `write` writes for the back steps, the newest `whole` whole. 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; var x: usize = 0; - for (0..i) |j| x += wordOf(t, j, whole, &buf).len + sep.len; - return .{ x, x + wordOf(t, i, whole, &buf).len }; + for (0..i) |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 ""; + return .{ x, x + word.len }; +} + +/// Whether back step `i` is in the 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]; } /// The step whose word in `part` is at byte `off` of what `write` wrote @@ -412,12 +471,13 @@ 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| { - if (!writes(t, part, i)) continue; + const word = wordIn(t, part, whole, i, &buf, &cut) orelse continue; if (part == .forward) x += sep.len; - const n = shownWord(t, part, i, whole, &buf, &cut).len; - if (off >= x and off < x + n) return @intCast(i); - x += n; + // 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); + x += word.len; if (part != .forward) x += sep.len; } return null; @@ -761,19 +821,85 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, p.panes[rd].?), "› Refs 2/2 ›") != null); } -test "a trail keeps its newest three back steps whole, older ones fold to ·, and a click on a · goes back to its step" { +test "a trail keeps its newest three back steps whole, older ones fold into one dim `+N` after the owner, and a click on it goes back to the newest of them; forward steps past two fold the same way" { 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); + for ([_]usize{ 10, 20, 30, 40, 50, 60 }) |line| f.look(f.held, "rank.zig", line); const r = p.view().active; + const pane = p.panes[r].?; + // Wide enough for the three newest whole on its one row. + p.update(.{ .resize = .{ .cols = 400, .rows = 60 } }); 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.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&buf, "‹@p{d} › +2 › rank.zig:30 › rank.zig:40 › rank.zig:50 › {s}/rank.zig Keep ", .{ owner, f.dir }))); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const fold = try tagCell(p, r, "+2"); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().lineno }, s.at(fold[0], fold[1]).style.fg); + try clickTag(p, r, "+2", .right); + try std.testing.expectEqualStrings("rank.zig:20", f.at(&at)); + // Back at the first: five forward steps, the two nearest whole. + try clickTag(p, r, "rank.zig:10", .right); try std.testing.expectEqualStrings("rank.zig:10", f.at(&at)); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), try std.fmt.bufPrint(&buf, "{s}/rank.zig › rank.zig:20 › rank.zig:30 › +3 Keep ", .{f.dir})) != null); +} + +test "the walk never adds a row to a tag at rest: its steps fold further, down to the newest alone, where they would" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + f.look(f.held, "rank.zig", 10); + for ([_]usize{ 20, 30, 40, 50, 60, 70 }) |line| { + f.look(p.view().active, "place.zig", line); + f.look(p.view().active, "rank.zig", line); + } + const r = p.view().active; + const pane = p.panes[r].?; + try std.testing.expect(pane.trail.cur > 4); + // A width 35 cells past what the tag takes with no walk: room on its + // row for the owner, a fold and the newest, not for three. + const walk = pane.trail; + pane.trail.n = 0; + pane.trail.cur = 0; + const bare = panes.File.displayWidth(p.settings.tab, try tagOf(p, pane)); + pane.trail = walk; + const extra = p.view().screen_w - pardes.tagline.tagWidth(p, r); + p.update(.{ .resize = .{ .cols = @intCast(bare + 35 + extra), .rows = 60 } }); + p.sync(); + try std.testing.expectEqual(@as(u16, 1), pardes.layout.wantedTagRows(p, r)); + try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), " › +") != null); +} + +test "two steps whose files have the same name are told apart by the shortest path they do not share; the word n walks is underlined" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + try f.tmp.dir.createDirPath(std.testing.io, "core"); + try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = "core/rank.zig", .data = "a\nb\nc\n" }); + f.look(f.held, "rank.zig", 12); + f.look(p.view().active, "core/rank.zig", 2); + f.look(p.view().active, "place.zig", 3); + const r = p.view().active; + var buf: [4096 + 128]u8 = undefined; + const tag = try tagOf(p, p.panes[r].?); + try std.testing.expect(std.mem.indexOf(u8, tag, try std.fmt.bufPrint(&buf, " › {s}/rank.zig:12 › core/rank.zig:2 › ", .{std.Io.Dir.path.basename(f.dir)})) != null); + // A list word: the one n walks, underlined. + p.panes[r].?.trail.steps[1] = .{ .list = .{} }; + p.panes[r].?.trail.steps[1].list.text.set("Find x 1/2"); + p.sync(); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const word = try tagCell(p, r, "Find x 1/2"); + try std.testing.expect(s.at(word[0], word[1]).style.ul == .single); + const other = try tagCell(p, r, "place.zig"); + try std.testing.expect(s.at(other[0], other[1]).style.ul != .single); } test "Ctrl-o goes back one place in a reader's walk and Ctrl-i forward again; past its first place, or from a held pane, the jump list's" { diff --git a/core/draw.zig b/core/draw.zig index be4230c4..28b9f22d 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -695,7 +695,7 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len } return null; } - var start: usize = tagline.nameAt(pane); + var start: usize = tagline.nameAt(p, 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: { @@ -945,7 +945,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: 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 { +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, under: bool) 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); @@ -956,8 +956,11 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const 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 }; + while (col < end and col < w) : (col += 1) { + const style = &s.at(x + @as(u16, @intCast(col)), row_y).style; + style.fg = .{ .rgb = ink }; + if (under) style.ul = .single; + } } } @@ -1014,7 +1017,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(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); + const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, 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 and head == null) caret: { @@ -1059,12 +1062,26 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, // wrapped onto. const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len]; if (tagTintRange(p, 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). + 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, false); + // A walk's forward steps, after the name, dimmed (Trail.zig); its fold + // `+N` too; the word n walks underlined in the key ink (UX D8). const ahead = tagline.forwardSpan(p, 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); + 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, false); + if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) { + const kept = tagline.folded(p, pane); + const t = &pane.trail; + const first: usize = @intFromBool(t.steps[0] == .owner); + if (t.isFolded(first, kept)) { + const fold = t.spanOf(first, kept); + inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), chrome.lineno, 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.box, true); // P2: the key role + }; + } // A search word its places no longer light, dimmed (Prompt.zig). - if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno); + if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno, false); // The head's keys in the key ink, its dimmed, underlined and struck // words (TagState.Span), over whichever rows they wrapped onto. if (head) |h| for (h.spans) |span| { diff --git a/core/tagline.zig b/core/tagline.zig index 3256f824..5f7222e6 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -179,7 +179,7 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 // 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 whole = pardes.Trail.shown_steps; + const whole = folded(p, pane); const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len); var w: std.Io.Writer = .fixed(room); pane.trail.write(.back, whole, &w) catch return error.OutOfMemory; @@ -200,15 +200,48 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 } /// 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 and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.shown_steps) else 0; +pub fn nameAt(p: *const Pardes, pane: *const Pane) usize { + return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, folded(p, pane)) else 0; +} + +/// The back steps a file's tag writes whole at rest (UX D8): the newest +/// three (Trail.shown_steps), fewer, down to the newest alone, while its +/// walk would make the tag take more rows than it takes with none: the +/// walk never adds a row to a tag at rest (as far as the newest alone +/// lets it). +pub fn folded(p: *const Pardes, pane: *const Pane) usize { + const t = &pane.trail; + const f = pane.file orelse return pardes.Trail.shown_steps; + if (t.n == 0) return pardes.Trail.shown_steps; + const id = panes.paneIdOf(p, pane) orelse return pardes.Trail.shown_steps; + const tab = p.settings.tab; + const width = tagWidth(p, id); + const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; + const bare = panes.File.displayWidth(tab, name) + @as(usize, if (pardes.Trail.reading(p, pane)) " Keep".len else 0) + panes.File.displayWidth(tab, curTail(pane)); + var whole: usize = pardes.Trail.shown_steps; + while (whole > 1 and rowsOf(bare + walkCells(t, whole, tab), width) > rowsOf(bare, width)) whole -= 1; + return whole; +} + +/// The cells a walk's words take at rest with its newest `whole` back +/// steps whole. +fn walkCells(t: *const pardes.Trail, whole: usize, tab: u16) usize { + var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; + var w: std.Io.Writer = .fixed(&room); + t.write(.back, whole, &w) catch {}; + t.write(.forward, whole, &w) catch {}; + return panes.File.displayWidth(tab, w.buffered()); +} + +fn rowsOf(cells: usize, width: usize) usize { + return @max(1, (cells + width - 1) / width); } /// The bytes of a file's tag its walk's forward steps take, after its name. pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { const f = pane.file orelse return .{ 0, 0 }; if (pane.trail.n == 0 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 }; - const whole = pardes.Trail.shown_steps; + const whole = folded(p, pane); const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; const lo = pane.trail.bytes(.back, whole) + name.len; return .{ lo, lo + pane.trail.bytes(.forward, whole) }; @@ -219,9 +252,9 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 { if (pane.trail.n == 0 or pane.file == null) return null; if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at); - const whole = pardes.Trail.shown_steps; + const whole = folded(p, pane); const ahead = forwardSpan(p, pane); - if (at < nameAt(pane)) return pane.trail.stepAt(.back, whole, at); + if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at); if (at >= ahead[0] and at < ahead[1]) return pane.trail.stepAt(.forward, whole, at - ahead[0]); return null; } @@ -268,7 +301,7 @@ pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 /// The tag's own text: what the user made of it, or until then the /// default a pane of its kind starts with. -pub fn curTail(pane: *Pane) []const u8 { +pub fn curTail(pane: *const Pane) []const u8 { return pane.tag.own orelse defaultTail(pane); } @@ -444,7 +477,7 @@ pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize { const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; var w: std.Io.Writer = .fixed(&room); - pane.trail.write(.back, pardes.Trail.shown_steps, &w) catch return null; + pane.trail.write(.back, folded(p, pane), &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; @@ -459,8 +492,8 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false; // 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); + if (col < nameAt(p, pane)) return false; + const at = col - nameAt(p, 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; diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 59037755..627fb21c 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -97,8 +97,8 @@ |28: 8 l8 |29: 9 l9 == snap landed grid=180x31 cursor=97,22 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse -|17: ls Follow Del +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll +|17: ls ow Del |18: g.txt 2 MARK a |19: 3 l3 |20: 4 l4 @@ -112,7 +112,7 @@ |28: 12 l12 |29: == snap n grid=180x31 cursor=97,27 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 3/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse +|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 |19: 2 MARK a |20: 3 l3 @@ -126,7 +126,7 @@ |28: 11 l11 |29: 12 l12 == snap N grid=180x31 cursor=97,23 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › g.txt:1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll == snap cancel grid=180x31 cursor=97,23 == snap nomatch grid=180x31 cursor=118,16 |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › /MARK/ 2/3 › / zzqq = Look /zzqq/ 0 ⏎ land · M-⏎ as a list · C-r history · esc diff --git a/test/snapshots/lookrange.golden b/test/snapshots/lookrange.golden index a0cbd3be..1ea85a6e 100644 --- a/test/snapshots/lookrange.golden +++ b/test/snapshots/lookrange.golden @@ -100,7 +100,7 @@ |7: /NEEDLE/ 2/2 › /tmp/pardes-snap/lookrange/cwd/r.txt Save Term Collapse Follow Del |30: /tmp/pardes-snap/lookrange/cwd/r.txt:8 == style hit1 grid=150x31 -|7: 0-1 d,#add38a, 2-47 #becfc4,#314738, 48-53 #dfbce5,#314738, 54-149 #becfc4,#314738, +|7: 0-1 d,#add38a, 2-13 #add38a,#314738,u 14-14 #add38a,#314738, 15-47 #becfc4,#314738, 48-53 #dfbce5,#314738, 54-149 #becfc4,#314738, |14: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-9 #e5eee5,#0d1410, 10-15 #e5eee5,#352e19, 16-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #e5eee5,#0d1410, 12-17 #f5f7ee,#3c614a, 18-149 #f5f7ee,#0d1410, |16: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-149 #e5eee5,#0d1410, @@ -110,7 +110,7 @@ |7: /NEEDLE/ 1/2 ↻ › /tmp/pardes-snap/lookrange/cwd/r.txt Save Term Collapse Follow Del |30: · /tmp/pardes-snap/lookrange/cwd/r.txt /NEEDLE/ 1/2 ↻ · line 7 1 message · SPC h m == style hit2 grid=150x31 -|7: 0-1 d,#add38a, 2-49 #becfc4,#314738, 50-55 #dfbce5,#314738, 56-149 #becfc4,#314738, +|7: 0-1 d,#add38a, 2-15 #add38a,#314738,u 16-16 #add38a,#314738, 17-49 #becfc4,#314738, 50-55 #dfbce5,#314738, 56-149 #becfc4,#314738, |14: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-9 #e5eee5,#0d1410, 10-15 #f5f7ee,#3c614a, 16-16 #f5f7ee,#0d1410, 17-149 #e5eee5,#0d1410, |15: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-11 #e5eee5,#0d1410, 12-17 #e5eee5,#352e19, 18-149 #e5eee5,#0d1410, |22: 0-0 d,#e5eee5, 1-149 d,#0d1410, -- cgit v1.3 From 6068e48aa4cec242dc0c29865b06347573fdd1ae Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 06:41:14 -0300 Subject: TagState: a question asks in the rows its tag takes at rest: the hint goes first, then the question is cut, its answers always shown (walk UI polish P1, UX DESIGN.md D13, asking; UX A16 "a question reflows its pane"): asking wrote its question, `▸`, its answers and `· SPC e to answer` after the path whatever their length, so a tag whose own words are short took a row more while the question waited, moving the body of a pane the user was not in; now TagState.asking measures the room the rest rows leave after the path (layout.wantedTagRows times the tag's width, less tagline.restPrefix's cells), drops the dim hint where it does not fit, then cuts the question to what is left (12 cells at least, ending `…`; the whole of it is the notice row's), never the answers; the order stays path · question ▸ answers, the mark in the box's cell; NOT DONE of D13: a message's detail on request only (`K` or Enter on its ghost, SPC e; rolled up at the next motion: today it unrolls under the caret's line, Messages.detailUnder), and progress in the right block (today drawn at the first row's right end where there is room, never wrapping: the dim ink is P2's); TEST FIRST: Messages.zig "a question never adds a row to its tag: at every width the asking tag takes the rows the tag takes at rest, its answers always shown, the question cut before them" (a file `/t/c.zig` with the tag's own text ` Put`, changed on disk under unsaved text, 56 to 160 columns: the tag's rows never past its rows at rest, `r Reload`, `k Keep mine`, `d Diff` always there; on the parent the whole question and its hint take two rows below 76 columns); core-test 1072/1243 (171 skipped); process-test with the tip's gates 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/Messages.zig | 28 ++++++++++++++++++++++++++++ core/TagState.zig | 19 +++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/Messages.zig b/core/Messages.zig index dd5c232a..6d8d570d 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -1330,6 +1330,34 @@ test "a burst of the same message is one message, counted, and moves nothing on try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10")); } +test "a question never adds a row to its tag: at every width the asking tag takes the rows the tag takes at rest, its answers always shown, the question cut before them" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + // A short name: the tag's rows have room for it and the answers. + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, "/t/c.zig"); + const f = &pane.file.?; + f.saved_hash = panes.File.fileHash(f); + for ([_]u21{ 'G', 'o', 'f', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } }); + // The tag's own words cut to one, so the question is the longer. + pane.tag.own = try p.gpa.dupe(u8, " Put"); + p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = "zero\n" } }); + _ = p.messages.waiting(pane) orelse return error.NotAsked; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + for (56..161) |cols| { + p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 30 } }); + p.sync(); + const rest = pardes.layout.wantedTagRows(p, id); + try std.testing.expect(pane.tag_rows <= @max(rest, 1)); + const shown = try pardes.tagline.tagText(p, frame.allocator(), pane); + for ([_][]const u8{ "r Reload", "k Keep mine", "d Diff" }) |word| try std.testing.expect(std.mem.indexOf(u8, shown, word) != null); + _ = frame.reset(.retain_capacity); + } +} + test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); defer p.deinit(); diff --git a/core/TagState.zig b/core/TagState.zig index c364451a..3fceb7f0 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -296,8 +296,23 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { const i = p.messages.waiting(pane) orelse return null; const said = &p.messages.live[i]; var b: Builder = .{ .arena = arena }; + // In the rows the tag takes at rest (UX D13: a question never adds a + // row): the hint goes first, then the question is cut, 12 cells at + // least, with `…` (the whole of it is on the notice row); its answers + // always show. + const tab = p.settings.tab; + const id = panes.paneIdOf(p, pane) orelse return null; + const room = @as(usize, @import("layout.zig").wantedTagRows(p, id)) * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, try tagline.restPrefix(p, arena, pane)); + const hint = if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer"; + var answers: usize = 2; // ` ▸`, then each ` k word ` + for (said.asks.answers()) |a| answers += 3 + panes.File.displayWidth(tab, a.word) + 1; + const question = said.words(); + const wanted = 1 + panes.File.displayWidth(tab, question) + answers; try b.put(" "); - try b.put(said.words()); + if (wanted <= room) try b.put(question) else { + try b.put(question[0..panes.File.byteAtDisplay(tab, question, @max(12, room -| (1 + answers)) - 1)]); + try b.put("…"); + } try b.put(" "); try b.styled("▸", .key); for (said.asks.answers()) |a| { @@ -307,7 +322,7 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { try b.put(a.word); try b.put(" "); } - try b.styled(if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer", .dim); + if (wanted + panes.File.displayWidth(tab, hint) <= room) try b.styled(hint, .dim); return b.done(); } -- cgit v1.3 From eb8ecb8a451ae32d590c42755614b801f9cc0c09 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 07:03:02 -0300 Subject: views, dump, draw: a load makes each view's band rows again from its own tag state, and the tag's own rows are held to MAX_TAG_ROWS where the frame reads them (the coordinator's item from P3's soak: `index out of bounds: index 15, len 8` at draw.zig paintPaneTag, `for (lines[0..rows])`, from views.drawOne in a replica client's draw after a divergence); RUN FIRST: views.zig's new test on the parent, its band-rows check left out: `panic: index out of bounds: index 12, len 8` at draw.zig:1007 paintPaneTag, from joinPaneTag, renderPane, render, drawOne: the same fault; THE CAUSE: a tag's `tag_rows` counts its band's rows (Core.sync: the band unrolled under its text pushes the body down) and is dumped and in the digest, while `band_rows` is derived (views.PaneView and Pane: never dumped, made again at every sync); a load (a join's dump, a replica's rollback) zeroed `band_rows` and kept `tag_rows`, so a view drawn before its next step (drawOne: a replica client's own view, a pump's other views; no sync there) read the tag's own rows as `tag_rows - band_rows` = the band's too, 12 to 19, and indexed paintPaneTag's `[MAX_TAG_ROWS]` array past its 8; THE FIX: views.bandsLoaded (from dump.afterLoad, after TagState.loaded) makes each open view's `band_rows` again within that view from its own state as its sync does (`Band.takes`, 0 for a folded pane and Band.over's), into the pane's live field and the view's share (derived: the digest is unchanged, as the test checks); draw.joinPaneTag and paintPaneTag hold the tag's own rows to MAX_TAG_ROWS (`-|` and `@min`): production code never panics on a stale pair; TEST: views.zig "a view not live with its band open, dumped and loaded, draws before its next step: its band's rows made again from its state, its tag's rows never past MAX_TAG_ROWS" (SPC Down in view 0, another view live, byteDump, load: the digest equal, view 0's share's band rows 11 again (0 on the parent), drawOne draws it; with its band rows zeroed by hand drawOne draws it too); a user's client could abort on a join or a rollback while another view had a band open; core-test 1073/1244 (171 skipped) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/draw.zig | 7 ++++--- core/dump.zig | 1 + core/views.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/draw.zig b/core/draw.zig index 28b9f22d..2ef72f0e 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -822,8 +822,9 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r const chrome = p.chromeTheme(); const region = s.region(.tag, id).?; const tag = (try tagline.shownTag(p, arena, pane)).text; - // The tag's text rows; the band's under them are its own layer. - const rows = pane.tag_rows - pane.band_rows; + // The tag's text rows; the band's under them are its own layer. A + // tag's own are MAX_TAG_ROWS at most (Pardes.sync). + const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS); // As wide as the widest row it shows, and never narrower than its // viewport. var widest: usize = 0; @@ -978,7 +979,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const tx = r.x + @min(TAG_TEXT_INSET, r.w); const tw = r.w -| TAG_TEXT_INSET; const tag_y = p.tagTop(pane, r); - const rows = pane.tag_rows - pane.band_rows; + const rows = @min(pane.tag_rows -| pane.band_rows, MAX_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 = tagGround(p, pane, active); diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..c0403c06 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -149,6 +149,7 @@ fn afterLoad(p: *Pardes) void { }; @import("jj.zig").loaded(p); pardes.TagState.loaded(p); + pardes.views.bandsLoaded(p); } /// A file kept slim in a dump (`dumpExit`, a closed pane's past its bound, diff --git a/core/views.zig b/core/views.zig index b05a116b..7bf30aa0 100644 --- a/core/views.zig +++ b/core/views.zig @@ -171,6 +171,24 @@ pub fn undumped(p: *Pardes, others: []const Shares) void { } } +/// After a load: each view's band rows (derived: never dumped nor in the +/// digest) made again from its own tag state as its last sync made them. +/// Its tag rows, which are dumped, count them, and a view drawn before its +/// next step (drawOne: a replica client's, a pump's other views) reads the +/// tag's own rows as their difference (draw.zig): with the band's rows +/// zeroed by the load, a band's became the tag's, past MAX_TAG_ROWS. +pub fn bandsLoaded(p: *Pardes) void { + for (0..max) |k| if (isOpen(p, @intCast(k))) within(p, @intCast(k), {}, bandsOf) catch {}; +} + +fn bandsOf(_: void, p: *Pardes) anyerror!void { + for (p.panes, 0..) |slot, id| if (slot) |pane| { + const rows = if (pane.collapsed or pardes.Band.over(pane)) 0 else @min(pardes.Band.takes(p, id), pane.tag_rows -| 1); + pane.band_rows = rows; + pane.pv[p.live].band_rows = rows; + }; +} + /// The views a dump before `Pardes.views` kept (`OldDumped`): each its /// share of the session into `views[k]`, the rest as `undumped`. What /// each view holds is the session's then; one refused is freed. @@ -581,6 +599,36 @@ pub fn within(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pa const testing = std.testing; const Key = pardes.Key; +test "a view not live with its band open, dumped and loaded, draws before its next step: its band's rows made again from its state, its tag's rows never past MAX_TAG_ROWS" { + const gpa = std.testing.allocator; + const dump = @import("dump.zig"); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + // SPC's level unrolled in view 0: its band's rows in the tag's. + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = Key.down } }); + p.sync(); + const band = pane.band_rows; + try testing.expect(band > 0 and pane.tag_rows - band <= pardes.MAX_TAG_ROWS and pane.tag_rows > pardes.MAX_TAG_ROWS); + // Another view live, view 0 parked, as a client's is when a join's + // (a replica's rollback's) dump is made. + const k = p.openView().?; + p.toView(k); + const bytes = try dump.byteDump(p); + defer gpa.free(bytes); + const q = try dump.load(gpa, .{ .tty_only = true, .cols = 80, .rows = 30 }, bytes, null); + defer q.deinit(); + try testing.expectEqual(pardes.walk.digest(Pardes, p), pardes.walk.digest(Pardes, q)); + // View 0 drawn with no step first (a client's draw, a pump's other + // views): its band as it was, the tag's own rows under the bound. + try testing.expectEqual(band, q.panes[0].?.pv[0].band_rows); + _ = try drawOne(q, 0, .{ .ctx = null, .f = null }); + // The bound itself: a share whose band's rows are not counted. + q.panes[0].?.pv[0].band_rows = 0; + _ = try drawOne(q, 0, .{ .ctx = null, .f = null }); +} + fn typeKeys(p: *Pardes, text: []const u8) void { for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); } -- cgit v1.3