From e563ef0d896fc66c3e88c274b25f09bb75f80fea Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 25 Nov 2026 05:49:06 -0300 Subject: Pick, body_layer, look, Messages, draw, colors: a picker's preview legible as one (UX DESIGN.md D7; the user missed it: S's 04 showed a preview from body line 1 with no mark where a hit lands and a tag naming the file as the pane's own): its landing line, the body line the cursor row lands on in the landing pane while that pane shows the row's file (Pick.landingLine), on the hit ground across the body's width with `▸` in the key ink in the gutter's cell after its number (where a prompt's current place has it), the place its row points at (a Grep's match at the row's column) on the current hit's ground over the places lit; placed a third of the way down the body (look.focusPaneLine's `.third`: ⌈rows/3⌉ rows of context above, clamped at the top, a text that fits shown whole), where it was centred; a Find row lands on line 1 and that is marked (its Enter lands there); the notice row's left, while a picker previews, says `⏎ lands in @pN's reader · its text is the preview · S-⏎ a new pane` (`⏎ lands here · …` in the pane itself) in the dim ink with the owner's address in the text's (Pick.sentence, Messages.Row.quiet_left and word), before any message; the notice row's dim words in the dim ink of the tagline's ground (colors.Roles.notice, 3:1 at least; it was the tagline's ink half mixed to its ground); a preview whose next file is not read yet keeps the previous one (the read is synchronous: the body is never blank) and a row with no file leaves the body; TEST FIRST: Pick.zig "a picker's preview is legible as one" (on the parent the landing line has no ground, line 40 sits mid-body and the notice row says the path): line 40 of an 80-line file at ⌈rows/3⌉, its row on the hit ground and the one above not, `▸` in the key ink, the sentence and its address, the row its own again at rest; colors.zig's floors test holds the notice row's inks too (fromTheme's comptime quota raised for them); core-test 1069/1239 (170 skipped) 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/Pick.zig | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) (limited to 'core/Pick.zig') diff --git a/core/Pick.zig b/core/Pick.zig index cb5f605d..efadc881 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -680,6 +680,45 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { // ---- the preview ---- +/// The line (from 0) pane `pane`'s body lands the live picker's cursor row +/// on, while it is that picker's landing pane previewing that row's file +/// (UX D7: drawn on the hit ground, body_layer.zig); null else. +pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usize { + const pk = live(p) orelse return null; + if (!pk.previews or pk.landing != pane.serial or pk.source == .themes) return null; + const s = &p.view().tag_state; + if (pk.shown != s.rows.at or count(p, pk) == 0) return null; + const row = rowAt(p, pk, arena, s.rows.at) catch return null; + const place = switch (row.target) { + .place => |t| t, + else => return null, + }; + const f = pane.file orelse return null; + if (!std.mem.eql(u8, f.path, place.path)) return null; + return @intCast(@max(0, pane.body.cur_row)); +} + +/// The notice row's sentence while a picker previews (UX D7), written to +/// `w`: where Enter lands (`here`, or the owner's reader by its address, +/// a word to Look at), that the body is the preview, and Shift-Enter's new +/// pane; the address's bytes in what was written, or null with no picker +/// previewing. +pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { + const pk = live(p) orelse return null; + if (!pk.previews or pk.source == .themes) return null; + if (pk.landing == pk.owner) { + w.writeAll("⏎ lands here") catch return null; + } else { + w.writeAll("⏎ lands in ") catch return null; + } + const lo = w.end; + if (pk.landing != pk.owner) w.print("@p{d}", .{pk.owner}) catch return null; + const hi = w.end; + if (pk.landing != pk.owner) w.writeAll("'s reader") catch return null; + w.writeAll(" · its text is the preview · S-⏎ a new pane") catch return null; + return .{ lo, hi }; +} + /// The landing pane's body showing the current row's place (SPEC §5.3): /// a file at its line, the query's matches lit for a Grep. Its own text is /// set aside the first time, put back when the picker rolls up. A file an @@ -745,7 +784,7 @@ fn preview(p: *Pardes, pk: *Pick) void { pane.body.cur_col = 0; return; } - look.focusPaneLine(p, id, at, .center); + look.focusPaneLine(p, id, at, .third); // A Grep's matches in the file lit, as its own pane would have them. if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false); } @@ -1984,3 +2023,60 @@ test "the themes picker marks the theme in use: `in use` at its row's right end band = (try Band.of(p, a, pane, id)).?; try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta); } + +test "a picker's preview is legible as one (UX D7): its landing line on the hit ground with `▸` in the gutter, a third of the body above it, and the notice row saying where Enter lands" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (1..81) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i}); + const path = try testFile(p, &tmp, "long.zig", text.items); + defer p.gpa.free(path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:40:6 line 40 of the file\n", .{path}); + defer std.testing.allocator.free(rows); + open(p, asker, .list, "Refs", "", rows); + const pk = live(p).?; + const reader = p.paneBySerial(pk.landing).?; + p.update(.tick); + const pane = p.panes[reader].?; + try std.testing.expectEqualStrings(path, pane.file.?.path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[reader]; + const body_y = p.bodyTop(pane, r); + // Line 40 a third of the way down: ⌈rows/3⌉ rows of context above it. + var at: ?u16 = null; + for (0..pane.rows) |row| if (pane.wrapAt(p.settings.tab, @intCast(row)).line == 39) { + at = @intCast(row); + break; + }; + try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), at); + const y = body_y + at.?; + const roles = &p.chromeTheme().roles; + const tx = r.x + pardes.config.GUTTER; + const gutter = File.gutterWidth(pane); + // Its text on the hit ground across the row; the row above as it was. + for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg); + try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = roles.hit })); + // `▸` in the key ink in the gutter's cell after the number. + const mark = s.at(tx + gutter - 1, y); + try std.testing.expectEqualStrings("▸", mark.grapheme()); + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, mark.style.fg); + // The notice row: where Enter lands, the owner's address a word in it. + var buf: [pardes.Messages.notice_row_cap]u8 = undefined; + const said = pardes.Messages.noticeRow(p, 120, &buf); + const want = try std.fmt.allocPrint(frame.allocator(), "⏎ lands in @p{d}'s reader · its text is the preview · S-⏎ a new pane", .{p.panes[asker].?.serial}); + try std.testing.expect(std.mem.startsWith(u8, said.text, want)); + try std.testing.expect(said.quiet_left); + try std.testing.expectEqualStrings(try std.fmt.allocPrint(frame.allocator(), "@p{d}", .{p.panes[asker].?.serial}), said.text[said.word[0]..said.word[1]]); + // At rest: no ground, no mark, the row back to its own. + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(!pardes.Messages.noticeRow(p, 120, &buf).quiet_left); +} -- cgit v1.3