summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 10:02:29 -0300
committerGabriel Schneider <[email protected]>2026-11-25 10:02:29 -0300
commit98f5abfc10d9984a69940a6805d974018e5ea01e (patch)
tree6742290772cb87a8cfdd57bd3fa85d5b4043f21f /core/Messages.zig
parenta6d2b61bd78768cf4bbf177717ffea319825de69 (diff)
downloadpardes-98f5abfc10d9984a69940a6805d974018e5ea01e.tar.gz
pardes-98f5abfc10d9984a69940a6805d974018e5ea01e.zip
Messages, body_layer, normal, mouse, Core: a message's detail unrolls only on request (UX D13, E5 fix 3): K with one selection on a line a message with a detail names, SPC e there, or a Look (B3) on its words after the line unrolls it under that line, and the caret leaving the line (or the keyboard another pane) rolls it up; the caret passing a line never inserts or removes rows; THE CAUSE: Messages.detailUnder showed the detail of the message naming the caret's line whenever the caret was on it (C's rule, spec §10.2), so j over a build error pushed the text below down and k pulled it back (UX A16, E2 "detail still unrolls under the caret"); THE FIX: Said.open (the question's Diff's flag, already in the dump and the digest; its doc said "whatever the caret" and nothing read it) is the request: detailUnder shows the message whose words the caret's line shows (the first naming it, firstAt, as messageGhosts draws them) only while it is open, and a question's Diff under its place whatever the caret; Messages.detailAt finds it (not a question's: its Diff is `d`); normal.zig's K takes it with one selection, else keep's prompt as before; Messages.act (SPC e) unrolls it first when the caret's line has one not shown, the walk as before when asked again; mouse.zig: a Look on its words after the line (body_layer.messageAt: from their glyph two blanks after the line, read from the frame drawn last, as wordAt reads a detail's word; wordAt and it share drawnRow) toggles it; Core.update: around a key and a click, Messages.unrolledAt/rollUp roll every unrolled detail (not a question's Diff) up when the keyboard's pane or its caret's line changed (a motion along the line, or a click on the detail, which puts the caret on the line it explains, keeps it: C's G-fixed rule holds, the detail's rows are read-only text for the mouse); nothing read with no detail unrolled; the Message builtin's doc says it (docs/typ/builtins-tui.json and -gui.json the same text); TEST FIRST: body_layer.zig "a message's detail unrolls only on request (UX D13): the caret passing its line inserts no rows; K there unrolls it ...; K with two selections is keep's" (fails on the base at body_layer.zig:1346: the caret on line 3 put its detail under it); C's two tests ask for the detail (err.open, and K after k k) where they set the caret; core-test 1084/1255 (171 skipped), process-test 0 of 147 failed (no golden moved); a user hit it: every build error and diagnostic with detail lines pushed the text below down as the caret passed
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig98
1 files changed, 81 insertions, 17 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 2cb196f6..b821ab35 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -129,15 +129,17 @@ pub const Said = struct {
text: Buf(256) = .{},
places: [max_places]Place = undefined,
places_len: u8 = 0,
- /// The lines that explain it, shown under its first place's line while
- /// the caret is on it.
+ /// The lines that explain it, shown under the line it names when asked
+ /// (`open`).
detail: [max_detail]Buf(128) = undefined,
detail_len: u8 = 0,
/// The serial of the pane it is about, 0 for none in particular.
pane: u32 = 0,
asks: Ask = .none,
- /// Its detail shown under its first place's line whatever the caret
- /// (a question's Diff).
+ /// Its detail unrolled, on request only (UX D13): K, SPC e or a Look on
+ /// its words on the caret's line (detailAt), shown under that line until
+ /// the caret leaves it (rollUp); a question's Diff under its place
+ /// whatever the caret, until `d` again.
open: bool = false,
/// How many times in a row it was said.
n: u16 = 1,
@@ -520,8 +522,9 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool {
return true;
}
-/// SPC e (the Message word, SPEC §10.4), on the message the notice row
-/// leads with: an error that names places lands them as a list in pane
+/// SPC e (the Message word, SPEC §10.4): on a line a message names, its
+/// detail not unrolled, that detail (UX D13); else on the message the
+/// notice row leads with: an error that names places lands them as a list in pane
/// `id`'s walk (Pick's `list`, its word `✗ <cause>` in the trail), the
/// first landed on, n and N walking the rest, and the error goes (a
/// +Search under the pane where jumps do not walk, or for a 9P script:
@@ -529,6 +532,13 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool {
/// else, or nothing, opens the history.
pub fn act(p: *Pardes, id: usize) void {
const m = &p.messages;
+ // On a line a message names, its detail not unrolled: unrolled (UX
+ // D13), the message kept; asked again, the walk below.
+ if (id < MAX_PANES) if (p.panes[id]) |pane| if (pane.focus == .body) if (detailAt(p, pane, pane.body.cur_row)) |s| if (!s.open) {
+ s.open = true;
+ p.needs_frame = true;
+ return;
+ };
const lead = m.headline() orelse return history(p, id);
if (lead.kind == .question) {
p.view().answering = lead.pane;
@@ -949,29 +959,83 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect) void {
}
}
-/// A message's detail under the caret's line (SPEC §10.2), as a body of
-/// `body_h` rows shows it: the row of that line's last row, how many of the
-/// detail's lines fit under it, the message (the first naming the line, as
-/// the words after it are); only in the pane with the keyboard, in its body.
-/// Bounded by the live messages' places and the rows shown.
+/// A message's detail unrolled (SPEC §10.2, UX D13: on request only), as a
+/// body of `body_h` rows shows it: the row of its line's last row, how many
+/// of the detail's lines fit under it, the message. The line is the
+/// caret's, where it was asked (the caret leaving it rolls it up), or a
+/// question's place; its message the first naming it, as the words after
+/// it are (firstAt). The caret passing a line never unrolls one. Only in
+/// the pane with the keyboard, in its body. Bounded by the live messages'
+/// places and the rows shown.
pub fn detailUnder(p: *const Pardes, pane: *Pane, active: bool, body_h: u16) ?struct { row: u16, rows: u16, said: *const Said } {
if (!active or pane.focus != .body or p.messages.live_len == 0) return null;
const f = pane.file orelse return null;
- const caret = @max(0, pane.body.cur_row);
- const said = found: for (p.messages.live[0..p.messages.live_len]) |*s| {
- for (s.places[0..s.places_len]) |*place| if (place.line == caret + 1 and std.mem.eql(u8, place.path.slice(), f.path)) break :found s;
- } else return null;
+ const m = &p.messages;
+ const caret: u32 = @intCast(@max(0, pane.body.cur_row));
+ const said, const line = found: {
+ if (m.firstAt(f.path, caret + 1)) |i| if (m.live[i].open) break :found .{ &m.live[i], @as(i32, @intCast(caret)) };
+ for (m.live[0..m.live_len], 0..) |*s, i| if (s.open and s.kind == .question and s.places_len > 0 and std.mem.eql(u8, s.places[0].path.slice(), f.path))
+ if (m.firstAt(f.path, s.places[0].line) == i) break :found .{ s, @as(i32, @intCast(s.places[0].line -| 1)) };
+ return null;
+ };
if (said.detail_len == 0) return null;
var row: u16 = 0;
while (row < body_h) : (row += 1) {
- if (pane.wrapAt(p.settings.tab, row).line != caret) continue;
- if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == caret) continue;
+ if (pane.wrapAt(p.settings.tab, row).line != line) continue;
+ if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == line) continue;
const k: u16 = @intCast(@min(said.detail_len, body_h - row - 1));
return if (k == 0) null else .{ .row = row, .rows = k, .said = said };
}
return null;
}
+/// The first live message naming line `line` (1-based) of `path`: the one
+/// whose words are drawn after that line (body_layer messageGhosts).
+fn firstAt(m: *const Messages, path: []const u8, line: u32) ?usize {
+ for (m.live[0..m.live_len], 0..) |*s, i| for (s.places[0..s.places_len]) |*place| {
+ if (line > 0 and place.line == line and std.mem.eql(u8, place.path.slice(), path)) return i;
+ };
+ return null;
+}
+
+/// The message whose words line `row` (0-based) of `pane`'s file shows,
+/// when it has a detail to unroll (UX D13): what K with one selection, SPC
+/// e and a Look on those words ask for. Not a question's (its Diff is `d`).
+pub fn detailAt(p: *Pardes, pane: *const Pane, row: i32) ?*Said {
+ const f = pane.file orelse return null;
+ if (row < 0) return null;
+ const s = &p.messages.live[p.messages.firstAt(f.path, @intCast(row + 1)) orelse return null];
+ if (s.detail_len == 0 or s.kind == .question) return null;
+ return s;
+}
+
+/// The keyboard's pane and its caret's line while a detail is unrolled on
+/// request; null with none (nothing to roll up: nothing else read).
+pub const Caret = struct { active: usize, row: i32 };
+
+pub fn unrolledAt(p: *const Pardes) ?Caret {
+ const v = p.view();
+ for (p.messages.live[0..p.messages.live_len]) |*s| if (s.open and s.kind != .question) {
+ const pane = p.panes[v.active] orelse return .{ .active = v.active, .row = -1 };
+ return .{ .active = v.active, .row = pane.body.cur_row };
+ };
+ return null;
+}
+
+/// After a key or a click (Core.update): the caret left its line, or the
+/// keyboard went to another pane, since `was`: every detail unrolled on
+/// request rolls up (UX D13: the next motion; a motion along the line, or
+/// a click on the detail, which puts the caret on the line it explains,
+/// keeps it), a question's Diff stays.
+pub fn rollUp(p: *Pardes, was: ?Caret) void {
+ const before = was orelse return;
+ const now = unrolledAt(p) orelse return;
+ if (std.meta.eql(before, now)) return;
+ for (p.messages.live[0..p.messages.live_len]) |*s| if (s.kind != .question) {
+ s.open = false;
+ };
+}
+
/// 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).