diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 07:26:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 07:36:10 -0300 |
| commit | c225fe093d7b4cb23bd5f66c7369f93beb5cfb18 (patch) | |
| tree | d0f484b696d284d00f075713c79f0100ebf07832 /core/body_layer.zig | |
| parent | 1ee22df4c6c8fb2fd63325fcec616ea8aedad147 (diff) | |
| parent | 415b4e2683d03624f5600c23bfabde749a1a207c (diff) | |
| download | pardes-c225fe093d7b4cb23bd5f66c7369f93beb5cfb18.tar.gz pardes-c225fe093d7b4cb23bd5f66c7369f93beb5cfb18.zip | |
walk UI M5: the polish round's P3 (uppppkkk 1ee22df4c6c8: code actions as a picker, /kbdin as typed, Esc at once, `]` targets in one pass and cached, a pane keeps its number when it walks, B3 on an answer word) and P2 (zvkrxzwq 415b4e2683d0: the colour roles of UX DESIGN.md D4, the tui reading box, the themes picker's `in use`, registers D11, painted targets D10, the preview legible D7, prompts D14, 29 goldens, the roles derived faster) merged, both on G3's kytxrnnk, resolved by meaning: Pick.zig's five conflicts: Row carries P3's `key` (an action's digit) and P2's `meta` (`in use`), rowAt keeps P2's themes arm and P3's actions arm, steps passes both to Band.Row, head's no-second-row branch is P3's (themes and actions) with P2's hints as a dim span (`⏎ or 1-9 apply it · esc` dim as `⏎ wear it · esc` is), and both lines' tests at the file's end; body_layer.zig merged without a conflict and agrees: P3's treeTargets cache answers targetLine's `]f` `]c` `]T` arms, and P2's paintTargets paints whatever targetLine answers in place of the line's number, so the cached lines are the painted ones; the `g` target and the `]g` motion both ask jj.nextChange (body_layer targetLine, normal.zig goto_change), whose P2 change finds the last unsaved edit with the Changes layer off, so they agree; Band.zig is P2's alone: its Row.meta (right-aligned, dim, the first to give way) is the "right-aligned row meta" P3 left as not done, nothing more to build for it; an action's rows are drawn by P2's painter (Band.Row.key: the digit bold in the roles' key ink) and its ghost lines stand on colors.Grounds add/del, which D4's add/del role is (as the Changes layer), so neither needed wiring; A MERGE FAULT FOUND BY A TEST FIRST: P2's D7 preview (Pick.landingLine, Pick.sentence) held for every picker that previews but themes, and P3's actions picker previews: its body got the hit ground and `▸` on the caret's line (the line the edit starts, or for an edit that only puts lines in, the untouched line under them) and the notice row said `⏎ lands here · its text is the preview · S-⏎ a new pane` where Enter applies an edit and lands nowhere; both now leave out actions as they leave out themes (an action's preview is its edit on the Changes grounds, the head says what Enter does); TEST: Pick.zig's code actions test asks no landing line, no `▸` before the line the edit changes, no sentence on the notice row, and no hit ground on the line under an edit that puts a line in (fails on the merge at Pick.zig:2188, landingLine answered the caret's line); find.golden (the conflict) resolved by meaning and checked by process-test: snap nomatch's and topbar's notice rows are P2's D7 sentence with P3's count `1 message` (the walked pane's two Find echoes one entry), cancel's is P3's row; leader.golden (P3's, CodeAction's new doc) passes as P3 wrote it; docs/typ/builtins-tui.json is P3's, current (core-test's builtins_json test passes); core-test 1072/1242 (170 skipped), process-test 0 of 147 failed (3 skipped, gui-only)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/body_layer.zig')
| -rw-r--r-- | core/body_layer.zig | 131 |
1 files changed, 111 insertions, 20 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig index 8bc38e23..0107b3e0 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -349,7 +349,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h); panes.Tables.paint(p, s, pane, r, tx, tw, body_h); drawWrapMarkers(p, s, pane, r, tx, tw, body_h, pane_bg); + // A picker's landing line under the places it lights (UX D7). + const landing = pardes.Pick.landingLine(p, arena, pane); + if (landing) |line| paintLanding(p, s, pane, r, tx, tw, body_h, line); pane.places.paint(p, s, pane, r, body_h); + if (landing) |line| paintLandingSpan(p, s, pane, r, f, line); pardes.Prompt.paintGutter(p, s, pane, r, body_h); panes.Query.paint(p, s, pane, r, body_h); } else if (pane.isTerminal()) { @@ -652,6 +656,47 @@ pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col: return text.items[b.lo..b.hi]; } +/// A picker's landing line (UX D7): its text on the hit ground across +/// the body's width, and `▸` in the key ink in the gutter's cell after its +/// number (the one a prompt's current place has, Prompt.paintGutter), on +/// each row it wraps onto. +fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, body_h: u16, line: usize) void { + const roles = &p.chromeTheme().roles; + const gutter = File.gutterWidth(pane); + const number = gutter -| File.laneCells(pane) -| pane.layers.heat -| 1; + const body_y = p.bodyTop(pane, r); + var vr: u16 = pane.context_rows; + while (vr < body_h) : (vr += 1) { + const w = pane.wrapAt(p.settings.tab, vr); + if (w.line != @as(i32, @intCast(line))) continue; + for (gutter..tw) |x| { + const cell = s.at(tx + @as(u16, @intCast(x)), body_y + vr); + cell.default = false; + cell.style.bg = .{ .rgb = roles.hit }; + } + if (gutter > 0 and w.at == 0) { + var style = s.at(tx + number, body_y + vr).style; + style.fg = .{ .rgb = roles.key }; + s.set(tx + number, body_y + vr, "▸", style); + } + } +} + +/// The landing line's matched span (a Grep's match at the row's column) on +/// the current hit's ground, over the places lit on it (UX D7). +fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void { + if (!pane.places.shows(pane)) return; + const hits = pane.places.hits.items; + const ls = File.lineStart(p.gpa, f, line); + const caret = ls + @as(usize, @intCast(@max(0, pane.body.cur_col))); + var i = panes.Places.firstFrom(hits, ls); + while (i < hits.len and hits[i].start <= caret) : (i += 1) { + if (hits[i].end <= caret) continue; + File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chromeTheme().roles.hit_current); + return; + } +} + /// Painted targets (SPEC §4.4), while a motion root's level shows in this /// body's tag: each of its keys at the line it would go to, in the gutter /// (`g e t b .` for `g`; for `]` the next and for `[` the previous @@ -708,10 +753,9 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, return; } if (cur.root != .goto and cur.root != .next and cur.root != .prev) return; - const th = p.theme(); - const style: CellStyle = .{ .fg = .{ .rgb = p.chromeTheme().box }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true }; - // The rows painted so far: a second key on a row goes after the first. - var painted: [bindings.max_children]u16 = undefined; + // Each target's row and key, in the level's order. + var rows: [bindings.max_children]u16 = undefined; + var keys: [bindings.max_children]u8 = undefined; var n: usize = 0; for (level) |c| { const leaf = (c.node orelse continue).leaf orelse continue; @@ -723,12 +767,34 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const w = pane.wrapAt(tab, row); if (w.line == line and w.at == 0) break; } else continue; - const x: u16 = @intCast(std.mem.count(u16, painted[0..n], &.{row})); - if (x >= tw) continue; - s.set(tx + x, body_y + row, bindings.keyName(c.key), style); - painted[n] = row; + rows[n] = row; + keys[n] = c.key; n += 1; } + // In place of the line's number (UX D10): its cells blank and the + // row's keys, as many as they hold, right-aligned to its last digit, + // bold in the key ink on the gutter's ground. With no numbers, over + // the line's first cells on the selection's ground. Never a shift. + const ink = p.chromeTheme().roles.key; + const number = File.gutterWidth(pane) -| File.laneCells(pane) -| pane.layers.heat -| 1; + const cells = @min(if (number > 0) number else tw, tw); + for (rows[0..n], 0..) |row, i| { + if (std.mem.indexOfScalar(u16, rows[0..i], row) != null) continue; + const y = body_y + row; + const shown = @min(std.mem.count(u16, rows[0..n], &.{row}), cells); + if (number > 0) for (0..cells) |x| { + s.at(tx + @as(u16, @intCast(x)), y).text[0] = ' '; + s.at(tx + @as(u16, @intCast(x)), y).len = 1; + }; + var x: u16 = if (number > 0) @intCast(cells - shown) else 0; + for (rows[i..n], keys[i..n]) |other, key| { + if (other != row) continue; + if (x >= (if (number > 0) cells else shown)) break; + const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.theme().sel_bg }; + s.set(tx + x, y, bindings.keyName(key), .{ .fg = .{ .rgb = ink }, .bg = bg, .bold = true }); + x += 1; + } + } } /// A hover's answer as ghost lines under the line it was asked at (SPEC @@ -1170,7 +1236,7 @@ test "a click under a message's detail lands on the row drawn there, a click on try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\nfive\nsix\n", pane.file.?.content); } -test "a motion root's level paints its targets in the gutter: `]` the next paragraph's p, `g` g and e; `m` browsed on `i` tints the braces' inside; nothing at rest" { +test "a motion root's level paints its targets in place of their lines' numbers, right-aligned to the last digit, bold in the key ink: `]` the next paragraph's p and an unsaved edit's g, which `]g` goes to; `g` g and e; `m` browsed on `i` tints the braces' inside; nothing at rest (UX D10)" { const Key = pardes.Key; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 }); defer p.deinit(); @@ -1182,34 +1248,59 @@ test "a motion root's level paints its targets in the gutter: `]` the next parag p.clock.now_ns = 5 * std.time.ns_per_s; p.clock.stepped_ns = p.clock.now_ns; pane.focus = .body; - pane.body.cur_row = 1; - pane.body.cur_col = 4; + // An edit on line 6, not saved; the caret back on line 2. + for ("5jAx") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.update(.{ .key = .{ .cp = Key.escape } }); + for ("4k") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); p.sync(); var s = try p.render(a); const body = s.region(.body, id).?.rect; const gutter = body.x; - const at_rest = [_][]const u8{ s.at(gutter, body.y).grapheme(), s.at(gutter, body.y + 4).grapheme(), s.at(gutter, body.y + 6).grapheme() }; - for (at_rest) |g| try std.testing.expect(!std.mem.eql(u8, g, "p") and !std.mem.eql(u8, g, "g") and !std.mem.eql(u8, g, "e")); + // The number's cells: the gutter less its blank. + const number = panes.File.gutterWidth(pane) - 1; + const Field = struct { + /// Row `y`'s number field, its blanks trimmed. + fn of(sf: *pardes.Surface, x: u16, y: u16, n: u16, buf: *[16]u8) []const u8 { + var w = std.Io.Writer.fixed(buf); + for (0..n) |i| w.writeAll(sf.at(x + @as(u16, @intCast(i)), y).grapheme()) catch {}; + return std.mem.trim(u8, w.buffered(), " "); + } + }; + var buf: [16]u8 = undefined; + try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf)); const plain_bg = s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 1).style.bg; - // `]`: nothing until its level shows; then `p` on the next paragraph. + // `]`: nothing until its level shows; then `p` on the next paragraph's + // number, `g` on the edit's, the digits gone. p.update(.{ .key = .{ .cp = ']' } }); p.advance(p.clock.now_ns); _ = frame.reset(.retain_capacity); s = try p.render(a); - try std.testing.expect(!std.mem.eql(u8, s.at(gutter, body.y + 4).grapheme(), "p")); + try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf)); p.clock.now_ns = p.view().tag_state.due_ns; _ = frame.reset(.retain_capacity); s = try p.render(a); - try std.testing.expectEqualStrings("p", s.at(gutter, body.y + 4).grapheme()); - p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqualStrings("p", Field.of(s, gutter, body.y + 4, number, &buf)); + const key = s.at(gutter + number - 1, body.y + 4); + try std.testing.expectEqualStrings("p", key.grapheme()); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.key }, key.style.fg); + try std.testing.expect(key.style.bold); + try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 5, number, &buf), 'g') != null); + try std.testing.expect(std.mem.indexOfAny(u8, Field.of(s, gutter, body.y + 5, number, &buf), "0123456789") == null); + // The text never shifts. + try std.testing.expectEqualStrings("t", s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 5).grapheme()); + // `]g` goes where its target is. + p.update(.{ .key = .{ .cp = 'g', .text = "g" } }); + try std.testing.expectEqual(@as(i32, 5), pane.body.cur_row); + for ("4k") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); // `g`: its first and last lines. p.update(.{ .key = .{ .cp = 'g' } }); p.advance(p.clock.now_ns); p.clock.now_ns = p.view().tag_state.due_ns; _ = frame.reset(.retain_capacity); s = try p.render(a); - try std.testing.expectEqualStrings("g", s.at(gutter, body.y).grapheme()); - try std.testing.expectEqualStrings("e", s.at(gutter, body.y + 6).grapheme()); + try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y, number, &buf), 'g') != null); + try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 6, number, &buf), 'e') != null); p.update(.{ .key = .{ .cp = Key.escape } }); // `m` unrolled, its cursor on `i`: the inside of the braces around the // caret tinted. @@ -1224,5 +1315,5 @@ test "a motion root's level paints its targets in the gutter: `]` the next parag p.update(.{ .key = .{ .cp = Key.escape } }); _ = frame.reset(.retain_capacity); s = try p.render(a); - try std.testing.expectEqualStrings(at_rest[1], s.at(gutter, body.y + 4).grapheme()); + try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf)); } |
