diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 22:40:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 22:55:08 -0300 |
| commit | 7018de2abcf585e26024952cc0b4c97d25b3dc27 (patch) | |
| tree | 27867e8c1eadd7c702a252e5c3c6447a3c0e445f /core/Messages.zig | |
| parent | 1dd5ae7a37588c42ae4b612deb767847b8a5a020 (diff) | |
| download | pardes-7018de2abcf585e26024952cc0b4c97d25b3dc27.tar.gz pardes-7018de2abcf585e26024952cc0b4c97d25b3dc27.zip | |
Messages, draw: a rolled level's last leaf is said on the notice row, the whole row, and the leader's chip is gone (walk UI G item 2a, SPEC §3.7's first mockup: `k Hover: the language server's hover (last used here)` on the row under the panes while SPC l is rolled): A's line under a rolled level (TagState.lastUsed) was a chip over the body's top rows, the last notice band kind but a prompt's; now Messages.noticeRow leads with it while the level shows, cut to the row's width, nothing on the right (the prototype's status() for an open leader step), and Row.lead names the message the left says, so paintNoticeRow tints the glyph and fades only a message's (it read headline() again); Pane.Notices.Kind is `prompt` alone (the notice bands' layers a pane 1 for 2: 64 fewer tag layers a Surface, A2's measure of what a layer costs a temporary Surface), Messages.leaderText and leader_room go, noticeText takes the pane alone, bands and collectNotices lose the view and slot they no longer read; the TreeContext test keeps its message half (no chip to look for); TEST FIRST: Messages.zig 'a rolled level's last leaf is said on the notice row, the whole row, never in a chip over the body; at rest the row is the messages' again' (on the merge the row says `/test.txt:1` and the pane has the chip); tui core-test 1033/1202 (169 skipped), process-test 0 of 146 failed (no golden shows a rolled level with a last leaf)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 3fef1842..8ecf2919 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -3,8 +3,8 @@ //! that explain it, kept in a fixed list while it lives; the log of //! everything said behind them (the history, `SPC h m`, and 9P `/log`); //! the notice row at the window's foot that indexes them; and the -//! transient bands a pane shows over its body's top rows (the pending -//! leader chord, a prompt waiting for input). +//! transient band a pane shows over its body's top rows (a prompt waiting +//! for input). const pardes = @import("root.zig"); const memory = @import("memory.zig"); const std = @import("std"); @@ -190,16 +190,6 @@ pub const LoggedMessage = struct { } }; -/// The room the leader band's line takes (TagState.lastUsed): a leaf's -/// key, word and summary (builtins.summary_max), and "(last used here)". -pub const leader_room = 192; - -/// The leaf the current which-key level ran last, and what it does: the -/// line under a rolled level (walk UI SPEC §3.7). -fn leaderText(p: *const Pardes, buf: *[leader_room]u8) []const u8 { - return pardes.TagState.lastUsed(p, p.view(), buf) orelse ""; -} - pub const Message = struct { const libc = std.c; const Tm = extern struct { @@ -683,6 +673,8 @@ pub const Row = struct { left: usize = 0, right: usize = 0, text: []const u8 = "", + /// The message the left says, when it says one. + lead: ?*const Said = null, }; /// Room for the notice row's line: the widest window's at the tagline's @@ -691,6 +683,15 @@ pub const notice_row_cap = 1024; pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { const m = &p.messages; + const tab = p.settings.tab; + // A rolled level's last leaf, while the level shows: what it does, the + // whole row (SPEC §3.7's first mockup). + if (pardes.TagState.lastUsed(p, p.view(), out)) |used| { + var end = @min(used.len, panes.File.rawAtDisplay(tab, used, width)); + while (end > 0 and panes.File.displayWidth(tab, used[0..end]) > width) end -= 1; + while (end > 0 and end < used.len and used[end] & 0xC0 == 0x80) end -= 1; + return .{ .left = end, .right = end, .text = used[0..end] }; + } var w: std.Io.Writer = .fixed(out); var live: usize = 0; var questions: usize = 0; @@ -723,7 +724,6 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { r.print("{d} message{s} \u{b7} SPC h m", .{ m.len, if (m.len == 1) "" else "s" }) catch {}; const tail = r.buffered(); // The left cut to make room for the right, a blank between them. - const tab = p.settings.tab; const tail_w = panes.File.displayWidth(tab, tail); const room = width -| (tail_w + 1); var cut = left_end; @@ -739,14 +739,13 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { for (0..gap) |_| w.writeByte(' ') catch {}; const right_at = w.end; w.writeAll(tail) catch {}; - return .{ .left = cut, .right = right_at, .text = w.buffered() }; + return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead }; } /// What notice band `i` says. The grid pass and the band layers both /// read it here, so a terminal and a pixel shell show the same line. -pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[leader_room]u8) []const u8 { +pub fn noticeText(pane: *const Pane, i: usize) []const u8 { return switch (pane.notices.kinds[i]) { - .leader => leaderText(p, leader_buf), .prompt => pane.promptText() orelse "", }; } @@ -915,8 +914,8 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { /// in what order. Everything downstream reads the answer: the body layer /// so it does not paint under them, and the paint pass so it can stack /// them instead of letting the last one win the row. -pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { - pane.notices = bands(p, p.view(), pane, pane.tag_rows, r, id); +pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect) void { + pane.notices = bands(p, pane, pane.tag_rows, r); // Each band's chip at the right edge, as wide as its own text and a // blank cell either side, the pane's width at most: a click finds it // whether or not a frame has drawn it. An overlay over the body's top @@ -925,21 +924,18 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { // draws, and a chip narrower than its text there would clip it. const tx = r.x + config.GUTTER; const tw = r.w -| config.GUTTER; - var leader_buf: [leader_room]u8 = undefined; for (0..pane.notices.len) |i| { - const chip = panes.File.displayWidth(p.settings.tab, noticeText(p, pane, i, &leader_buf)) + 2; + const chip = panes.File.displayWidth(p.settings.tab, noticeText(pane, i)) + 2; pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw))); } } -/// The bands pane `id` shows in view `v`, over `r` below its `tag_rows`: -/// the live view's each step, and any view's for its kind's facts -/// (Kind.viewOf), made from what a dump keeps (the bands are derived). -pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_rows: u16, r: Rect, id: usize) Pane.Notices { +/// The bands a pane shows over `r` below its `tag_rows`: the live view's +/// each step, and any view's for its kind's facts (Kind.viewOf), made from +/// what a dump keeps (the bands are derived). +pub fn bands(p: *const Pardes, pane: *const Pane, tag_rows: u16, r: Rect) Pane.Notices { var n: Pane.Notices = .{}; if (r.w <= config.GUTTER or r.h <= tag_rows) return n; - var used_buf: [leader_room]u8 = undefined; - if (id == v.active and pardes.TagState.lastUsed(p, v, &used_buf) != null) n.push(.leader); // Del's question shows once its delay is up: answered before that, it // was never there. const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns; @@ -1195,6 +1191,39 @@ test "the notice row leads with the most important live message, its count and p try std.testing.expect(std.mem.endsWith(u8, row.text, "+2 \u{b7} 1 question \u{b7} SPC e")); } +test "a rolled level's last leaf is said on the notice row, the whole row, never in a chip over the body; at rest the row is the messages' again" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + p.messages.live_len = 0; + p.clock.now_ns = 5 * std.time.ns_per_s; + p.clock.stepped_ns = p.clock.now_ns; + // SPC t w: Wrap, run from SPC t; then SPC t again, shown. + for (" tw t") |c| p.update(.{ .key = .{ .cp = c } }); + p.advance(p.clock.now_ns); + p.clock.now_ns = p.view().tag_state.due_ns; + p.sync(); + _ = try p.render(p.scratch.allocator()); + var buf: [notice_row_cap]u8 = undefined; + var row = noticeRow(p, 110, &buf); + try std.testing.expect(std.mem.startsWith(u8, row.text, "w Wrap: ")); + try std.testing.expect(std.mem.endsWith(u8, row.text, " (last used here)")); + try std.testing.expectEqual(row.text.len, row.right); + try std.testing.expect(row.lead == null); + try std.testing.expectEqual(@as(u8, 0), pane.notices.len); + // Narrower than the line: cut to the width, never past it. + row = noticeRow(p, 12, &buf); + try std.testing.expectEqualStrings("w Wrap: Long", row.text); + // Esc: at rest, the messages' (Wrap's echo), and with none where the + // caret is. + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + row = noticeRow(p, 110, &buf); + try std.testing.expect(row.lead != null); + p.messages.live_len = 0; + row = noticeRow(p, 110, &buf); + try std.testing.expect(std.mem.startsWith(u8, row.text, "/test.txt:1")); +} + test "an idle core wants no wake, and a message wakes it once, when it dims" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); |
