summaryrefslogtreecommitdiff
path: root/core/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 20:20:53 -0300
committerGabriel Schneider <[email protected]>2026-11-24 20:40:36 -0300
commit1ebc8974489e46aee26409d54d7f1de567dbbb4a (patch)
treec2e6147e9342f01de9dfae54117ef7552cc393cc /core/body_layer.zig
parentc40d447e63663d947f241d60a2bdb8ce1bd141c0 (diff)
downloadpardes-1ebc8974489e46aee26409d54d7f1de567dbbb4a.tar.gz
pardes-1ebc8974489e46aee26409d54d7f1de567dbbb4a.zip
messages: a message is said where its cause is: the mark in its pane's box, its words at its line, its detail under the caret, progress at its tag's end, and a failed run's report its places (pick-ui SPEC §10.2, walk UI line C item 3): the mark is the glyph of the most important live error, question, warning or progress about a pane (its pane, its file, a place's file: Messages.markOf), drawn in the box's second cell (the grid's dirty cell, its ground kept dirty under unsaved text) and never in the tag's text, so it rewraps no tag and moves no row (written as a prefix word it could push a column under its minimums: the random placement test in ninep/tree.zig caught that); a message's places in a file shown are its glyph and words two cells after the end of their line, and with the keyboard in that body and its caret on that line the message's detail as ghost rows under it, the rows below pushed down for as long (body_layer.zig messageGhosts: drawn, never written, ruling R3; bounded by the rows shown and 16 messages of 4 places); a pane's progress at its tag's first row's right end and a server's (a message of no pane: the language server's status, dev/Inbox.zig and runtime/macos.zig now say it of none) at the workspace tag's, where the row has room, and setStatus with no text ends it; a command pane's run that fails is read back from its last 400 rows for a compiler's places (path:line:col: error|warning|note, a relative path its directory's: Messages.readPlaces), and names them as an error of that pane ('exit N', its places, the rows after its first error its detail), which the pane's next run takes away (SPEC §11); say returns the message it made; tests: Messages.zig 'a compiler's report names its places ...', 'a burst of the same message is one message, counted, and moves nothing on the screen' (×10, rects and tag rows equal), body_layer.zig 'a build error is said where its cause is: the mark ..., its words after its line, its detail under the caret's line pushing the rows below down, the walk on the notice row', draw.zig 'progress is said at the right end of its tag ...', panes.zig 'a command whose run fails naming places is an error of its pane ...'; Term.zig's calls list takes the run's rows read (S1); tui: core-test, shell-test, pane-test, behaviour-test pass; process-test 0 of 146 failed after shellset's and lsp's goldens took the mark (✗ in the box of the pane whose refusal is live)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/body_layer.zig')
-rw-r--r--core/body_layer.zig120
1 files changed, 120 insertions, 0 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 9c4a4c73..c2a20213 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -468,6 +468,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
}
}
+ if (pane.file != null and p.messages.live_len > 0) messageGhosts(p, s, pane, tx, tw, body_y, body_h, active);
+
// `gw`'s labels, two letters over the start of each word
if (pane.jump.items.len > 0) labels: {
const flat = edit.flatSurface(p.editor(), &pane.body) catch break :labels;
@@ -548,6 +550,68 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
};
}
+/// A message at the lines it names, drawn and never written (SPEC §10.2,
+/// ruling R3): after the end of each such line shown, the message's glyph
+/// and its words there; under the caret's line, when the keyboard is in
+/// this body, the lines that explain it, pushing the rows below down (the
+/// rows past the body's foot are not shown meanwhile). Bounded by the rows
+/// shown and the live messages' places (Messages.max_live, Said.max_places).
+fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16, active: bool) void {
+ const Messages = pardes.Messages;
+ const f = pane.file.?;
+ const chrome = p.chromeTheme();
+ const th = p.theme();
+ const pane_bg: Color = if (th.bg) |c| .{ .rgb = c } else .default;
+ const Hit = struct { line: usize, said: *const Messages.Said, place: *const Messages.Place };
+ var hits: [Messages.max_live * Messages.Said.max_places]Hit = undefined;
+ var n: usize = 0;
+ for (p.messages.live[0..p.messages.live_len]) |*said| for (said.places[0..said.places_len]) |*place| {
+ if (place.line == 0 or !std.mem.eql(u8, place.path.slice(), f.path)) continue;
+ hits[n] = .{ .line = place.line - 1, .said = said, .place = place };
+ n += 1;
+ };
+ if (n == 0) return;
+ const caret_line: usize = @intCast(@max(0, pane.body.cur_row));
+ var detail: ?struct { row: u16, said: *const Messages.Said } = null;
+ var row: u16 = 0;
+ while (row < body_h) : (row += 1) {
+ const w = pane.wrapAt(p.settings.tab, row);
+ if (w.line < 0) continue;
+ const line: usize = @intCast(w.line);
+ // A line's words go after its last row.
+ if (row + 1 < body_h and pane.wrapAt(p.settings.tab, row + 1).line == w.line) continue;
+ const hit = for (hits[0..n]) |h| {
+ if (h.line == line) break h;
+ } else continue;
+ const cells = s.cells[@as(usize, body_y + row) * s.cols + tx ..][0..tw];
+ var end: usize = tw;
+ while (end > 0 and std.mem.eql(u8, cells[end - 1].grapheme(), " ")) end -= 1;
+ const at = end + 2;
+ if (at < tw) {
+ var buf: [160]u8 = undefined;
+ const words = std.fmt.bufPrint(&buf, "{s} {s}", .{ hit.said.kind.glyph(), hit.place.text.slice() }) catch &buf;
+ _ = s.print(tx + @as(u16, @intCast(at)), body_y + row, @intCast(tw - at), words, .{ .fg = .{ .rgb = Messages.ink(chrome, hit.said.kind) }, .bg = pane_bg });
+ }
+ if (active and pane.focus == .body and line == caret_line and hit.said.detail_len > 0 and detail == null) detail = .{ .row = row, .said = hit.said };
+ }
+ const under = detail orelse return;
+ // The rows below the caret's line move down by the detail's rows.
+ const k: u16 = @intCast(@min(under.said.detail_len, body_h - under.row - 1));
+ if (k == 0) return;
+ var dst: u16 = body_h - 1;
+ while (dst >= under.row + 1 + k) : (dst -= 1) {
+ const to = @as(usize, body_y + dst) * s.cols + tx;
+ const from = @as(usize, body_y + dst - k) * s.cols + tx;
+ @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]);
+ }
+ const gutter: u16 = panes.File.gutterWidth(pane);
+ for (under.said.detail[0..k], 0..) |*text, i| {
+ const y = body_y + under.row + 1 + @as(u16, @intCast(i));
+ s.fill(tx, y, tw, 1, .{ .bg = pane_bg });
+ if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, text.slice(), .{ .fg = .{ .rgb = Messages.ink(chrome, under.said.kind) }, .bg = pane_bg });
+ }
+}
+
pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane) ![]const u8 {
if (pane.addon != null) {
const buf = try arena.alloc(u8, pane.rows -| 1);
@@ -656,3 +720,59 @@ fn fillBody(dst: ?[]u8, pane: *Pane, viewport: []const []const u8) usize {
}
return written;
}
+
+/// Grid row `y` of `s` from column `x`, as text.
+fn rowText(s: *const Surface, x: u16, y: u16, buf: []u8) []const u8 {
+ var n: usize = 0;
+ for (x..s.cols) |col| {
+ const g = s.cells[@as(usize, y) * s.cols + col].grapheme();
+ if (n + g.len > buf.len) break;
+ @memcpy(buf[n..][0..g.len], g);
+ n += g.len;
+ }
+ return buf[0..n];
+}
+
+test "a build error is said where its cause is: the mark on its file's tag, its words after its line, its detail under the caret's line pushing the rows below down, the walk on the notice row" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\nsix\n");
+ const id = p.view().active;
+ const err = pardes.Messages.keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ err.places[0] = .{ .line = 3, .col = 1 };
+ err.places[0].path.set("/test.txt");
+ err.places[0].text.set("expected 2 argument(s), found 3");
+ err.places_len = 1;
+ err.detail[0] = .{};
+ err.detail[0].set("const x = f(1, 2, 3);");
+ err.detail[1] = .{};
+ err.detail[1].set(" ^");
+ err.detail_len = 2;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ pane.focus = .body;
+ pane.body.cur_row = 0;
+ p.sync();
+ var s = try p.render(frame.allocator());
+ const body = s.region(.body, id).?.rect;
+ // The mark, in the box's second cell; the tag's text as it was.
+ const r = p.view().rects[id];
+ try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme());
+ try std.testing.expect(std.mem.startsWith(u8, try tagline.tagPrefix(p, pane), "/test.txt"));
+ var buf: [512]u8 = undefined;
+ // Its words after line 3's end; nothing inserted while the caret is
+ // elsewhere.
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected 2 argument(s), found 3") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
+ // The caret on line 3: its detail under it, the rows below two rows down.
+ pane.body.cur_row = 2;
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "const x = f(1, 2, 3);") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 5, &buf), "four") != null);
+ // ...never written: the file is as it was.
+ try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\nfive\nsix\n", pane.file.?.content);
+ // The notice row offers the walk.
+ const foot = s.region(.notice_row, pardes.Region.none).?;
+ try std.testing.expect(std.mem.endsWith(u8, std.mem.trimEnd(u8, rowText(s, 0, foot.rect.y, &buf), " "), "SPC e walk"));
+}