From f26cf0be705280ff28ca69aaef6cc64e1466ed4e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 18:52:44 -0300 Subject: messages: one session-wide list of live messages replaces each pane's stack of chips (pick-ui SPEC §10.1, walk UI line C item 1): Messages.Said is a kind (echo, notice, warn, error, question, progress), its cause first as a word a Look understands (a file's path, @pN and its command), its text, the places it names and the lines that explain it, the pane it is about, the question it asks, ×n and the core's clock, in a fixed list of 16 (Messages.live); a new message retires every echo and notice, a new error the error before it, the same message right after itself is counted, progress from the same cause runs in place and is never the notice row's; an echo or a notice dims after MessageLinger (now 4000 ms, a warning twice as long: test configs' MessageLinger 0 keep their meaning, nothing dims and nothing wakes), and the core sleeps to that dim (Messages.dimDue in nextWake) instead of a frame-counted linger; no key or click dismisses a message any more: Esc in normal mode takes the warnings and errors first, then goes back as before; every call site says what it said, mapped by its entry: setMessage a notice, setStatus progress, reportError and reportFailure an error, a builtin's announcement an echo (exec.zig), the sent-to-a-REPL arrow an echo; the log ring stays the history and 9P /log (each line now with its kind); gone: Pane.msg, msg_older and their lives, slots, announcement, status and sent flags, dismissMessage, advanceMessages, holdMessages, messageWake, expireUnattended and the detached shells' 100 ms message waits; until the notice row (item 2) a pane's one message chip shows the newest message said of it (Messages.saidBy); an Upgrade's outcome is said once and is every view's; tests: Messages.zig 'an echo or a notice retires those before it, an error the error before it, a repeat counts and progress runs in place', 'Msg says a notice by hand ... and the next message retires it', 'an idle core wants no wake, and a message wakes it once, when it dims', runtime/upgrade.zig 'an upgrade's outcome stays on every view's notice row until something else is said'; core-test 862 pass 162 skip, pane-test and shell-test pass; behaviour-test: the pdf addon's script golden and one PDF Restore test move with the chip over a PDF's body, which item 2 takes away MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/exec.zig | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'core/exec.zig') diff --git a/core/exec.zig b/core/exec.zig index 2528805f..dbea2b2f 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -617,8 +617,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { p.setMessage(.at(from), warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id})); } var said: pardes.Kind.Buf(64) = .{}; - p.setMessage(.at(from), said.print("\u{2192} {s}", .{id})); - src.msg_sent = true; + pardes.Messages.say(p, .echo, from, said.print("\u{2192} {s}", .{id})); var rec: [96]u8 = undefined; pardes.ctlfs.events.notePath(p, "send", std.fmt.bufPrint(&rec, "{d} {d} {s}", .{ src.serial, dst.serial, id }) catch return); } @@ -974,15 +973,14 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? // No pane at all (the window Delcol emptied): a word runs all the same, // with a stand-in that is no pane (New, Newcol, Exit are what make sense). const pane = p.panes[id] orelse (if (builtins.registry.scope(b) == .session or panes.anyPane(p) == null) panes.standIn(p) orelse return else return); - // A builtin says its own name before it runs, so a tagline click is - // legible even when what it did is invisible. Whatever the builtin - // then says for itself replaces the announcement. It is the message - // row's only, never /log's: a msg record is something said. + // A builtin says its own name before it runs, an echo, so a tagline + // click is legible even when what it did is invisible. Whatever the + // builtin then says for itself retires it. It is the message row's + // only, never /log's: a msg record is something said. if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { p.fs.unlogged = true; - p.setMessage(.at(id), @tagName(b)); + pardes.Messages.say(p, .echo, id, @tagName(b)); p.fs.unlogged = false; - pane.msg_announcement = true; } // A word for one kind of pane, on another: refused with why, not a // silent nothing (Palette on a file, Filter on a PDF). -- cgit v1.3 From 1ebc8974489e46aee26409d54d7f1de567dbbb4a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 20:20:53 -0300 Subject: 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) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Messages.zig | 200 ++++++++++++++++++++++++++++++++++------- core/Term.zig | 4 +- core/body_layer.zig | 120 +++++++++++++++++++++++++ core/draw.zig | 65 ++++++++++++++ core/exec.zig | 9 +- core/panes.zig | 49 ++++++++++ dev/Inbox.zig | 3 +- runtime/macos.zig | 2 +- runtime/upgrade.zig | 2 +- test/snapshots/lsp.golden | 1 + test/snapshots/shellset.golden | 3 +- 11 files changed, 420 insertions(+), 38 deletions(-) (limited to 'core/exec.zig') diff --git a/core/Messages.zig b/core/Messages.zig index b4950b4f..282482ea 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -262,30 +262,49 @@ pub const Message = struct { /// and is not logged; a message is an event. pub const setStatus = pardes.tape.taped(setStatusInner); fn setStatusInner(p: *Pardes, id: Pane.Id, text: []const u8) void { - say(p, .progress, id.index(), text); + // No text: the pane's progress is over, and goes. + if (text.len == 0) { + const serial: u32 = if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| pane.serial else 0 else 0; + const m = &p.messages; + for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .progress and s.pane == serial) { + m.remove(i); + p.needs_frame = true; + break; + }; + return; + } + _ = say(p, .progress, id.index(), text); } pub const setMessage = pardes.tape.taped(setMessageInner); fn setMessageInner(p: *Pardes, id: Pane.Id, text: []const u8) void { - say(p, .notice, id.index(), text); + _ = say(p, .notice, id.index(), text); } /// Say `text`, a message of `kind` about pane `id` (MAX_PANES and up: /// none in particular), its cause first: logged (progress is not), and -/// live (`keep`). -pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) void { +/// live (`keep`); the message, for the places it names. +pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) *Said { if (kind != .progress) logMessage(p, id, kind, text); const pane: ?*Pane = if (id < MAX_PANES and !p.fs.session_write) p.panes[id] else null; var src: Buf(96) = .{}; - if (pane) |cause| { - if (cause.file) |f| src.set(f.path) else if (if (cause.addon) |k| k.path.len > 0 else false) src.set(cause.addon.?.path) else if (cause.command) |line| { - const first = line[0 .. std.mem.indexOfAny(u8, line, "\r\n") orelse line.len]; - var cut = @min(first.len, 64); - while (cut < first.len and cut > 0 and first[cut] & 0xC0 == 0x80) cut -= 1; - _ = src.print(config.pane_addr ++ "{d} {s}", .{ cause.serial, first[0..cut] }); - } else _ = src.print(config.pane_addr ++ "{d}", .{cause.serial}); - } - _ = keep(p, kind, if (pane) |cause| cause.serial else 0, src.slice(), text); + if (pane) |cause| causeWord(cause, &src); + return keep(p, kind, if (pane) |cause| cause.serial else 0, src.slice(), text); +} + +/// A pane as a message names its cause: a file's path (a kind's too), else +/// `@pN` and the command it runs. +fn causeWord(pane: *const Pane, out: *Buf(96)) void { + if (pane.file) |f| return out.set(f.path); + if (pane.addon) |k| if (k.path.len > 0) return out.set(k.path); + const line = pane.command orelse { + _ = out.print(config.pane_addr ++ "{d}", .{pane.serial}); + return; + }; + const first = line[0 .. std.mem.indexOfAny(u8, line, "\r\n") orelse line.len]; + var cut = @min(first.len, 64); + while (cut < first.len and cut > 0 and first[cut] & 0xC0 == 0x80) cut -= 1; + _ = out.print(config.pane_addr ++ "{d} {s}", .{ pane.serial, first[0..cut] }); } /// Make a message live, and return it (for its places and its detail): @@ -349,7 +368,7 @@ pub fn keep(p: *Pardes, kind: Kind, serial: u32, src: []const u8, text: []const return s; } -fn remove(m: *Messages, i: usize) void { +pub fn remove(m: *Messages, i: usize) void { std.mem.copyForwards(Said, m.live[i .. m.live_len - 1], m.live[i + 1 .. m.live_len]); m.live_len -= 1; } @@ -379,6 +398,80 @@ pub fn headline(m: *const Messages) ?*const Said { return best; } +/// The kind a pane's mark shows, one cell after its box (SPEC §10.2): the +/// most important live error, question, warning or progress about it (an +/// echo or a notice marks nothing); null for none. +pub fn markOf(m: *const Messages, pane: *const Pane) ?Kind { + var best: ?Kind = null; + for (m.live[0..m.live_len]) |*s| { + if (s.kind == .echo or s.kind == .notice or !s.about(pane)) continue; + if (best == null or s.kind.rank() > best.?.rank()) best = s.kind; + } + return best; +} + +/// A kind's ink, for its glyph, its mark and its words at a line. +pub fn ink(chrome: *const pardes.colors.ChromeTheme, kind: Kind) [3]u8 { + return switch (kind) { + .@"error" => chrome.diagnostic_error, + .warn => chrome.diagnostic_warning, + .question => chrome.diagnostic_info, + else => chrome.diagnostic_hint, + }; +} + +/// The places a compiler's report names put on `s`: each +/// `path:line:col: error|warning|note: words` row (a relative path is +/// `dir`'s), its words there, and the rows after the first error, up to +/// the next place, its detail. How many it found; none without an error. +pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { + var errors: usize = 0; + var detailing = false; + for (rows) |raw| { + const row = std.mem.trimEnd(u8, raw, " \t\r\n"); + const found = placeOf(row) orelse { + if (detailing and row.len > 0 and s.detail_len < Said.max_detail) { + s.detail[s.detail_len] = .{}; + s.detail[s.detail_len].set(row); + s.detail_len += 1; + } + continue; + }; + detailing = false; + const is_error = std.mem.startsWith(u8, found.text, "error"); + if (is_error) { + detailing = errors == 0; + errors += 1; + } + if (s.places_len == Said.max_places) continue; + const place = &s.places[s.places_len]; + place.* = .{ .line = found.line, .col = found.col }; + if (std.Io.Dir.path.isAbsolute(found.path)) place.path.set(found.path) else _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), found.path }); + place.text.set(if (std.mem.startsWith(u8, found.text, "error: ")) found.text["error: ".len..] else found.text); + s.places_len += 1; + } + if (errors == 0) s.places_len = 0; + return s.places_len; +} + +/// A compiler's place row: `path:line:col: error|warning|note...`. +fn placeOf(row: []const u8) ?struct { path: []const u8, line: u32, col: u32, text: []const u8 } { + const a = std.mem.indexOfScalar(u8, row, ':') orelse return null; + const path = row[0..a]; + if (path.len == 0 or std.mem.indexOfAny(u8, path, " \t") != null) return null; + var rest = row[a + 1 ..]; + const b = std.mem.indexOfScalar(u8, rest, ':') orelse return null; + const line = std.fmt.parseInt(u32, rest[0..b], 10) catch return null; + rest = rest[b + 1 ..]; + const c = std.mem.indexOfScalar(u8, rest, ':') orelse return null; + const col = std.fmt.parseInt(u32, rest[0..c], 10) catch return null; + const text = std.mem.trim(u8, rest[c + 1 ..], " "); + for ([_][]const u8{ "error", "warning", "note" }) |word| { + if (std.mem.startsWith(u8, text, word)) return .{ .path = path, .line = line, .col = col, .text = text }; + } + return null; +} + /// The words the newest live message said of `pane` has, "" for none: /// what its band shows, and what a write that failed on it answers. pub fn saidBy(m: *const Messages, pane: *const Pane) []const u8 { @@ -641,9 +734,10 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { if (failing_write) { p.fs.unlogged = true; defer p.fs.unlogged = false; - return say(p, .@"error", id, text); + _ = say(p, .@"error", id, text); + return; } - say(p, .@"error", id, text); + _ = say(p, .@"error", id, text); } /// The one place that decides which transient lines a pane is showing and @@ -799,26 +893,26 @@ test "an echo or a notice retires those before it, an error the error before it, const id = p.view().active; const m = &p.messages; m.live_len = 0; - say(p, .notice, id, "first"); - say(p, .echo, id, "second"); + _ = say(p, .notice, id, "first"); + _ = say(p, .echo, id, "second"); try std.testing.expectEqual(@as(u8, 1), m.live_len); try std.testing.expectEqualStrings("second", m.headline().?.text.slice()); - say(p, .@"error", id, "broke"); - say(p, .warn, id, "careful"); + _ = say(p, .@"error", id, "broke"); + _ = say(p, .warn, id, "careful"); // The echo went with the error; the warning stands beside it. try std.testing.expectEqual(@as(u8, 2), m.live_len); try std.testing.expectEqual(Kind.@"error", m.headline().?.kind); - say(p, .@"error", id, "broke again"); + _ = say(p, .@"error", id, "broke again"); try std.testing.expectEqual(@as(u8, 2), m.live_len); try std.testing.expectEqualStrings("broke again", m.headline().?.text.slice()); // The same again right after itself: one message, counted, its newest // wording (and clock) kept. - for (0..9) |_| say(p, .@"error", id, "broke again"); + for (0..9) |_| _ = say(p, .@"error", id, "broke again"); try std.testing.expectEqual(@as(u8, 2), m.live_len); try std.testing.expectEqual(@as(u16, 10), m.headline().?.n); // Progress updates its line in place and retires nothing. - say(p, .progress, id, "Changes: jj 1/4"); - say(p, .progress, id, "Changes: jj 3/4"); + _ = say(p, .progress, id, "Changes: jj 1/4"); + _ = say(p, .progress, id, "Changes: jj 3/4"); try std.testing.expectEqual(@as(u8, 3), m.live_len); try std.testing.expectEqualStrings("Changes: jj 3/4", m.saidBy(p.panes[id].?)); try std.testing.expectEqual(Kind.@"error", m.headline().?.kind); @@ -831,7 +925,7 @@ test "an echo or a notice retires those before it, an error the error before it, m.live_len = 0; for (0..max_live + 3) |i| { var buf: [16]u8 = undefined; - say(p, .warn, id, std.fmt.bufPrint(&buf, "w{d}", .{i}) catch unreachable); + _ = say(p, .warn, id, std.fmt.bufPrint(&buf, "w{d}", .{i}) catch unreachable); } try std.testing.expectEqual(@as(u8, max_live), m.live_len); try std.testing.expectEqualStrings("w3", m.live[0].text.slice()); @@ -899,14 +993,14 @@ test "the notice row leads with the most important live message, its count and p try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text)); // A notice, then an error and a warning: the error leads, newest first // within a rank; the others are counted. - say(p, .notice, id, "indexed"); - say(p, .warn, id, "careful"); - say(p, .@"error", id, "broke"); + _ = say(p, .notice, id, "indexed"); + _ = say(p, .warn, id, "careful"); + _ = say(p, .@"error", id, "broke"); row = noticeRow(p, 60, &buf); try std.testing.expectEqualStrings("\u{2717} /test.txt broke", row.text[0..row.left]); try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} 3 messages \u{b7} SPC h m")); // A burst of the same: one message, counted; the row keeps its width. - for (0..9) |_| say(p, .@"error", id, "broke"); + for (0..9) |_| _ = say(p, .@"error", id, "broke"); row = noticeRow(p, 60, &buf); try std.testing.expectEqualStrings("\u{2717} /test.txt broke \u{d7}10", row.text[0..row.left]); try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text)); @@ -950,6 +1044,52 @@ test "an idle core wants no wake, and a message wakes it once, when it dims" { try std.testing.expectEqual(@as(?u64, null), p.nextWake()); // A warning is bright twice as long; with no linger nothing wakes. try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 0")); - say(p, .warn, p.view().active, "careful"); + _ = say(p, .warn, p.view().active, "careful"); try std.testing.expectEqual(@as(?u64, null), p.nextWake()); } + +test "a compiler's report names its places: each place's words, the first error's rows after it its detail, a relative path the run's directory's" { + var s: Said = .{}; + const rows = [_][]const u8{ + "install", + "+- compile exe pardes Debug native 1 errors", + "core/pick.zig:25:12: error: expected 2 argument(s), found 3", + " const best = rank(q, name, 3) orelse continue;", + " ^~~~", + "core/look.zig:14:5: note: function declared here", + "pub fn rank(q: []const u8, name: []const u8) ?u32 {", + "error: the following command failed with 1 compilation errors:", + }; + try std.testing.expectEqual(@as(usize, 2), readPlaces(&s, "/src/pardes/", &rows)); + try std.testing.expectEqualStrings("/src/pardes/core/pick.zig", s.places[0].path.slice()); + try std.testing.expectEqual(@as(u32, 25), s.places[0].line); + try std.testing.expectEqual(@as(u32, 12), s.places[0].col); + try std.testing.expectEqualStrings("expected 2 argument(s), found 3", s.places[0].text.slice()); + try std.testing.expectEqualStrings("note: function declared here", s.places[1].text.slice()); + try std.testing.expectEqual(@as(u8, 2), s.detail_len); + try std.testing.expectEqualStrings(" const best = rank(q, name, 3) orelse continue;", s.detail[0].slice()); + try std.testing.expectEqualStrings(" ^~~~", s.detail[1].slice()); + // No error among them: no places. + var none: Said = .{}; + try std.testing.expectEqual(@as(usize, 0), readPlaces(&none, "/", &.{ "x.zig:1:1: note: only a note", "grep: nothing" })); +} + +test "a burst of the same message is one message, counted, and moves nothing on the screen" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("text\n"); + const id = p.view().active; + _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files"); + p.sync(); + const rects = p.view().rects; + const tag_rows = pane.tag_rows; + for (0..9) |_| _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files"); + p.sync(); + try std.testing.expectEqual(@as(u8, 1), p.messages.live_len); + try std.testing.expectEqual(@as(u16, 10), p.messages.headline().?.n); + try std.testing.expectEqual(rects, p.view().rects); + try std.testing.expectEqual(tag_rows, pane.tag_rows); + var buf: [notice_row_cap]u8 = undefined; + const row = noticeRow(p, 78, &buf); + try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10")); +} diff --git a/core/Term.zig b/core/Term.zig index a83bf927..d4baf4e8 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -422,7 +422,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{ .{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" }, .{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest), counted when it held any (the feed's own unit, which filled it); only the session writes it to the pty (pty_write is off the tape)" }, // ---- reads by a step: in the digest ---- - .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:5 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, + .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" }, .{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 panes.zig:2 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's; panes.zig: a view scrolls no history on the alternate screen)" }, .{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" }, .{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" }, @@ -441,7 +441,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{ .{ "commandOutput", "ninep/pty.zig:1", "READ, NOT COVERED: a command's output rows (a 9P pty/run): taped as the session's answer" }, .{ "textRows", "edit.zig:2", "READ, NOT COVERED: every row's text, the history's among them (a selection, a Look over a shell)" }, .{ "viewport", "body_layer.zig:1 replica.zig:1", "READ: the rows' text a view's place (in the digest, with its pane) shows (body_layer.zig: a draw's; replica.zig: a test's)" }, - .{ "editRows", "ansi.zig:1", "READ: rows' text for a draw" }, + .{ "editRows", "ansi.zig:1 panes.zig:1", "READ: rows' text for a draw; a command's last rows read for the places its report names when it fails (panes.zig commandDone): in the digest as the emulator's rows are" }, // ---- local ---- .{ "due", "Core.zig:1", "LOCAL: its next wake (a blink, an animation): the loop's, never a step's state" }, .{ "cellPixels", "ansi.zig:1 panes.zig:2", "LOCAL: a frontend's draw sets its view's cell size (ansi.zig); a step sets the view's (in the digest) before each feed (panes.zig), so a reply to CSI 16 t is the step's" }, 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")); +} diff --git a/core/draw.zig b/core/draw.zig index a7513468..8baca6ca 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -470,6 +470,12 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: s.fill(r.x, tag_y, config.GUTTER, @min(1, pane.tag_rows), box_style); if (dirty and pane.tag_rows > 0 and config.GUTTER > 1) s.set(r.x + config.GUTTER - 1, tag_y, "*", .{ .fg = .{ .rgb = inkOn(boxDirty(p)) }, .bg = .{ .rgb = boxDirty(p) }, .bold = true, .font_role = .tagline }); + // The mark (pick-ui SPEC §2): the status of the most important live + // message about the pane, in the box's second cell, on the dirty ground + // when there is unsaved text: a cell of the box's, never the tag's + // text, so it moves nothing. + if (pane.tag_rows > 0 and config.GUTTER > 1) if (p.messages.markOf(pane)) |kind| + s.set(r.x + config.GUTTER - 1, tag_y, kind.glyph(), .{ .fg = .{ .rgb = Messages.ink(chrome, kind) }, .bg = .{ .rgb = if (dirty) boxDirty(p) else box_bg }, .bold = true, .font_role = .tagline }); s.fill(r.x, tag_y + 1, config.GUTTER, pane.tag_rows -| 1, .{ .bg = .{ .rgb = band }, .font_role = .tagline, @@ -547,6 +553,19 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void { viewport.x += inset; viewport.w -= inset; try renderHeaderLayer(p, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tagline_bg, chrome.tagline_fg); + // A server's progress (a message of no pane) at its first row's + // right end, where the row has room for it. + if (layer.rows > 0 and top == 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + if (said.kind != .progress or said.pane != 0) continue; + var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; + const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; + const width = panes.File.displayWidth(p.settings.tab, text); + const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(tagline.topbar(p), 0)); + const room = layout.tagCapacity(p, viewport.w); + var row: Surface = .{ .cols = layer.cols, .rows = 1, .cells = layer.cells[0..layer.cols], .tab = p.settings.tab }; + if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline }); + break; + }; joinHeaderRows(s, layer, chrome.tagline_fg); } const column_rows = layout.columnBarHeight(p); @@ -887,6 +906,17 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll)); _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } + // The pane's progress at its first row's right end, where the row has + // room for it (SPEC §10.2). + if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + if (said.kind != .progress or said.pane != pane.serial) continue; + var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; + const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; + const width = panes.File.displayWidth(p.settings.tab, text); + const used = panes.File.displayWidth(p.settings.tab, lines[0]); + if (used + 2 + width <= tw) _ = s.print(tx + @as(u16, @intCast(tw - width)), tag_y, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); + break; + }; // The name's tint, in the tag's first line, over whichever rows it // wrapped onto. const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len]; @@ -1528,3 +1558,38 @@ fn apart(a: *const Pardes, b: *const Pardes) bool { } return any; } + +test "progress is said at the right end of its tag: a pane's at its tag's, a server's at the workspace tag's, and it goes when it ends" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 160, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("text\n"); + const id = p.view().active; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + var buf: [512]u8 = undefined; + const Row = struct { + fn of(s: *const Surface, y: u16, out: []u8) []const u8 { + var n: usize = 0; + for (0..s.cols) |x| { + const g = s.cells[@as(usize, y) * s.cols + x].grapheme(); + @memcpy(out[n..][0..g.len], g); + n += g.len; + } + return std.mem.trimEnd(u8, out[0..n], " "); + } + }; + p.setStatus(.at(id), "Changes: jj\u{2026}"); + p.setStatus(.at(pardes.MAX_PANES), "--:--:-- lsp zls: indexing 3/10"); + p.sync(); + var s = try p.render(frame.allocator()); + const tag_y = p.tagTop(pane, p.view().rects[id]); + try std.testing.expect(std.mem.endsWith(u8, Row.of(s, tag_y, &buf), "\u{22ef} Changes: jj\u{2026}")); + try std.testing.expect(std.mem.endsWith(u8, Row.of(s, 0, &buf), "\u{22ef} lsp zls: indexing 3/10")); + // Its mark meanwhile, and neither is the notice row's. + try std.testing.expectEqualStrings("\u{22ef}", s.at(p.view().rects[id].x + config.GUTTER - 1, tag_y).grapheme()); + try std.testing.expect(p.messages.headline() == null); + p.setStatus(.at(id), ""); + _ = frame.reset(.retain_capacity); + s = try p.render(frame.allocator()); + try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null); +} diff --git a/core/exec.zig b/core/exec.zig index dbea2b2f..3bb6e809 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -617,7 +617,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { p.setMessage(.at(from), warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id})); } var said: pardes.Kind.Buf(64) = .{}; - pardes.Messages.say(p, .echo, from, said.print("\u{2192} {s}", .{id})); + _ = pardes.Messages.say(p, .echo, from, said.print("\u{2192} {s}", .{id})); var rec: [96]u8 = undefined; pardes.ctlfs.events.notePath(p, "send", std.fmt.bufPrint(&rec, "{d} {d} {s}", .{ src.serial, dst.serial, id }) catch return); } @@ -760,6 +760,11 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize { pane.command_done = false; pane.command_status = null; pane.command_pty = true; + // Its last run's errors go with it (SPEC §11). + var i: usize = 0; + while (i < p.messages.live_len) { + if (p.messages.live[i].pane == pane.serial and p.messages.live[i].kind == .@"error") p.messages.remove(i) else i += 1; + } pane.body.mode = .tty; // What the last program left the emulator in goes first: the // alternate screen left (only if it is there: leaving restores a @@ -979,7 +984,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? // only, never /log's: a msg record is something said. if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { p.fs.unlogged = true; - pardes.Messages.say(p, .echo, id, @tagName(b)); + _ = pardes.Messages.say(p, .echo, id, @tagName(b)); p.fs.unlogged = false; } // A word for one kind of pane, on another: refused with why, not a diff --git a/core/panes.zig b/core/panes.zig index ea0ff86d..479d4702 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1042,6 +1042,23 @@ pub const Pane = struct { pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code })); pane.noteRun(p, "exit", code); p.needs_frame = true; + // A failed run whose report names places (a compiler's + // `path:line:col: error: ...`): an error of this pane, the places + // its words, the rows after its first its detail (SPEC §10.2). Its + // last rows only: a report's places are at its end. + if (status != 0) if (pane.terminal) |state| report: { + const grid = Term.grid(state); + const first = grid.total -| 400; + const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report; + var found: pardes.Messages.Said = .{}; + if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report; + var words: pardes.Kind.Buf(32) = .{}; + const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code})); + kept.places = found.places; + kept.places_len = found.places_len; + kept.detail = found.detail; + kept.detail_len = found.detail_len; + }; } }; @@ -1902,3 +1919,35 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(pane.prompt == .none and pane.input.own == null); } + +test "a command whose run fails naming places is an error of its pane, those places its words, and the pane's next run takes it away" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{}); + defer p.deinit(); + while (p.nextEffect()) |_| {} + p.setCwd(.at(0), "/tmp/pardes-cmd"); + _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); + const dst = exec.execute(p, 1, "zig build") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + const pane = p.panes[dst].?; + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "core/pick.zig:25:12: error: expected 2 argument(s), found 3\r\n const best = rank(q, name, 3);\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 1 } }); + const said = p.messages.headline() orelse return error.NothingSaid; + try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind); + try std.testing.expectEqualStrings("exit 1", said.text.slice()); + try std.testing.expect(std.mem.endsWith(u8, said.src.slice(), " zig build")); + try std.testing.expectEqual(@as(u8, 1), said.places_len); + try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice()); + try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice()); + var frame = std.heap.ArenaAllocator.init(gpa); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[dst]; + try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme()); + // Its next run: the last run's error goes. + p.update(.{ .eof = .{ .pane = .at(dst) } }); + try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build")); + while (p.nextEffect()) |_| {} + try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); +} diff --git a/dev/Inbox.zig b/dev/Inbox.zig index 1df516cb..bc7c7e8a 100644 --- a/dev/Inbox.zig +++ b/dev/Inbox.zig @@ -354,7 +354,8 @@ pub fn land(q: *Inbox, core: *pardes.Pardes, m: Msg) void { }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; - core.setStatus(.at(core.view().active), pardes.Messages.Message.stamp(&mbuf, "lsp", text)); + // A server's progress, of no pane: the workspace tag's. + core.setStatus(.at(pardes.MAX_PANES), pardes.Messages.Message.stamp(&mbuf, "lsp", text)); q.lsp_allocator.free(text); }, .pipe => |response_value| { diff --git a/runtime/macos.zig b/runtime/macos.zig index 3221737a..ff30061a 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -818,7 +818,7 @@ fn drainInbox(st: *State) bool { }, .lsp_status => |text| { var mbuf: [256]u8 = undefined; - st.core.setStatus(.at(st.core.view().active), message.stamp(&mbuf, "lsp", text)); + st.core.setStatus(.at(pardes.MAX_PANES), message.stamp(&mbuf, "lsp", text)); }, .pipe => |value| { st.core.update(.{ .pipe_resp = .{ diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 7e836141..62f49ffa 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -483,7 +483,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op /// no pane in particular, it is on every view's notice row (each client /// reads it on its own screen). fn tellEveryView(p: *pardes.Pardes, text: []const u8) void { - pardes.Messages.say(p, .notice, pardes.MAX_PANES, text); + _ = pardes.Messages.say(p, .notice, pardes.MAX_PANES, text); } test "an upgrade's outcome is said in every view, at the pane its keyboard is on, whichever view's input came last" { diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 5fce5d9a..e0690838 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -62,4 +62,5 @@ |40: ✓ /tmp/pardes-snap/lsp/cwd/a.zig Symbols 2 messages · SPC h m == snap step grid=120x41 cursor=15,3 == snap nothing grid=120x41 cursor=7,5 +|2: ✗/tmp/pardes-snap/lsp/cwd/a.zig Save Term Collapse Follow TreeContext Def Refs Del |40: ✗ /tmp/pardes-snap/lsp/cwd/a.zig Def: not found 3 messages · SPC h m diff --git a/test/snapshots/shellset.golden b/test/snapshots/shellset.golden index 73072bd6..d4dc80c4 100644 --- a/test/snapshots/shellset.golden +++ b/test/snapshots/shellset.golden @@ -21,10 +21,11 @@ | | /tmp/pardes-snap/shellset/cwd/cmd.txt:1 == snap builtin-ran grid=90x21 cursor=25,3 +|2: ✗/tmp/pardes-snap/shellset/cwd/cmd.txt Save Term Collapse Follow Del |20: ✗ /tmp/pardes-snap/shellset/cwd/cmd.txt Shell: shell "zznosuchshel 3 messages · SPC h m == snap fallback-shell grid=90x21 cursor=49,6 |1: New Term Find Grep Joincol Delcol New Term Find Grep Joincol Delcol -|2: /tmp/pardes-snap/shellset/cwd/cmd.txt Save /tmp/pardes-snap/shellset/cwd Term+bash Sav +|2: ✗/tmp/pardes-snap/shellset/cwd/cmd.txt Save /tmp/pardes-snap/shellset/cwd Term+bash Sav |3: Term Collapse Follow Del e Mode Filter Collapse Del |4: 1 Shell zznosuchshell ls |5: cmd.txt zmarkfile.txt -- cgit v1.3 From e91261ff4f4602afec14d2fb958fd3e51a4dc62d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 21:01:37 -0300 Subject: messages: a background question waits in its pane's tag and never takes the keyboard; SPC e gives it the keyboard, Esc leaves it waiting (pick-ui SPEC §10.2, §10.4, §3.2 asking, walk UI line C item 4): a file that changes on disk under unsaved text is now a question of its pane (one at a time: File.changed), its answers r Reload, k Keep mine and d Diff (Messages.Ask.answers); while the tag is at rest the question is drawn after the path as computed prefix text, 'changed on disk ▸ r Reload k Keep mine d Diff · SPC e to answer' (Messages.askingText; the tag's own words stay after it until the head of ruling R1 takes their place), its mark ? in the box and the notice row's '1 question · SPC e'; the keys stay the body's: View.answering (a pane's serial, the view's own keyboard state, ruling R4) is set by SPC e (item 5) and makes the answer's key answer it in handleKey's first slot, Esc leaving it waiting; the own-command questions (Del's side, a REPL's choice) keep that slot as they were; B2 on an answer's word in its tag answers it (exec.execute: Messages.answerWord); r reads the file again with the consent Get would ask for, k keeps the text and says so, d reads the disk's text (the host's read, taped) and shows where it parts from the buffer as ghost rows under that line, the disk's + lines first (Messages.diskDiff, Said.open: shown whatever the caret), d again hides them; an answer is logged ('... · answered Reload'); Messages.waitingAnswers is what a : lists first (for agent E); 9P /log says 'msg N changed on disk' (monkey9p's checker reads that); tests: Messages.zig 'a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again', ninep/ctl.zig's disk-change test now finds the question; tui: core-test, shell-test, pane-test, behaviour-test pass; process-test: filewatch's golden takes the question (its tag row and its notice row), Restore's root-ctl case failed once under load and passes alone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- core/Core.zig | 4 + core/File.zig | 5 +- core/Messages.zig | 192 ++++++++++++++++++++++++++++++++++++++++ core/exec.zig | 2 + core/keys.zig | 17 ++++ core/ninep/ctl.zig | 4 +- core/tagline.zig | 7 +- test/monkey9p.zig | 2 +- test/snapshots/filewatch.golden | 5 +- 9 files changed, 231 insertions(+), 7 deletions(-) (limited to 'core/exec.zig') diff --git a/core/Core.zig b/core/Core.zig index 27a0da4f..92c81ba6 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -177,6 +177,10 @@ pub const View = struct { /// A key that waits for the next: the leader (SPC) or the window prefix /// (Ctrl-w), one at a time. prefix: enum { none, leader, window } = .none, + /// A background question SPC e gave the keyboard: the serial of the + /// pane it waits on (0: none). Its next key answers it; Esc leaves it + /// waiting (keys.zig handleKey). + answering: u32 = 0, /// The register the running normal command names (`"`); 0 for the /// default one. register: u21 = 0, diff --git a/core/File.zig b/core/File.zig index 58544b62..f611bbbd 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2439,8 +2439,9 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { if (f.disk_newer == disk) return; f.disk_newer = disk; f.disk_newer_warned = false; - var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{}; - p.setMessage(.at(id), said.print("{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]})); + // A question in its tag, never the keyboard's (pick-ui SPEC §10.2): + // one waiting already is the one about it. + if (p.messages.waiting(pane) == null) pardes.Messages.say(p, .question, id, "changed on disk").asks = .disk; var rec: [16]u8 = undefined; pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d}", .{pane.serial}) catch unreachable); // a u32 fits 16 return; diff --git a/core/Messages.zig b/core/Messages.zig index 282482ea..e421a32c 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -104,8 +104,19 @@ pub const Ask = enum(u8) { none, /// A file changed on disk under unsaved text. disk, + + /// Its answers, as its pane's tag offers them: the key that gives one, + /// and its word (an Exec of the word's first word gives it too). + pub fn answers(a: Ask) []const Answer { + return switch (a) { + .none => &.{}, + .disk => &.{ .{ .key = 'r', .word = "Reload" }, .{ .key = 'k', .word = "Keep mine" }, .{ .key = 'd', .word = "Diff" } }, + }; + } }; +pub const Answer = struct { key: u8, word: []const u8 }; + /// One live message. pub const Said = struct { pub const replica = .{ .len = .{ .{ "places", "places_len" }, .{ "detail", "detail_len" } } }; @@ -125,6 +136,9 @@ pub const Said = struct { /// 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). + open: bool = false, /// How many times in a row it was said. n: u16 = 1, /// When it was last said, on the core's clock (`Pardes.clock.now_ns`). @@ -472,6 +486,135 @@ fn placeOf(row: []const u8) ?struct { path: []const u8, line: u32, col: u32, tex return null; } +/// The question waiting on `pane`, an index into `live`; null for none. +pub fn waiting(m: *const Messages, pane: *const Pane) ?usize { + for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .question and s.pane == pane.serial) return i; + return null; +} + +/// The answers of the question waiting on `pane`: what a `:` lists first +/// (pick-ui SPEC §10.4); none without one. +pub fn waitingAnswers(m: *const Messages, pane: *const Pane) []const Answer { + const i = m.waiting(pane) orelse return &.{}; + return m.live[i].asks.answers(); +} + +/// The waiting question's words as its pane's tag asks them, while the tag +/// is at rest (SPEC §3.2 asking): what it asks, its answers, and how to +/// give one. `answering`: SPC e gave it the keyboard. +pub fn askingText(m: *const Messages, pane: *const Pane, answering: bool, out: []u8) []const u8 { + const i = m.waiting(pane) orelse return ""; + const s = &m.live[i]; + var w: std.Io.Writer = .fixed(out); + w.print("{s} \u{25b8}", .{s.words()}) catch {}; + for (s.asks.answers()) |a| w.print(" {c} {s} ", .{ a.key, a.word }) catch {}; + w.writeAll(if (answering) "\u{b7} Esc later" else "\u{b7} SPC e to answer") catch {}; + return w.buffered(); +} + +/// Answer live question `i` with `key`: `r` reads the file again over its +/// unsaved text, `k` keeps the text and lets the disk's be, `d` shows (or +/// hides again) the disk's lines where they differ, as ghosts in its +/// body. False for a key that is none of its answers. +pub fn answer(p: *Pardes, i: usize, key: u8) bool { + const m = &p.messages; + const s = &m.live[i]; + const a = for (s.asks.answers()) |a| { + if (a.key == key) break a; + } else return false; + p.needs_frame = true; + const id = p.paneBySerial(s.pane) orelse { + m.remove(i); + return true; + }; + var said: Buf(256) = .{}; + if (key == 'd') { + if (s.open) { + s.open = false; + return true; + } + diskDiff(p, s, id); + return true; + } + logMessage(p, id, .echo, said.print("{s} {s} \u{b7} answered {s}", .{ s.src.slice(), s.words(), a.word })); + m.remove(i); + if (key == 'r') { + const pane = p.panes[id].?; + // The answer is the consent Get would ask for. + if (pane.file) |f| pane.discard_warned = .{ .revision = f.revision, .by = .get }; + pardes.exec.runBuiltin(p, .Get, id, "", null); + } else _ = say(p, .echo, id, "kept yours; the disk's is not read"); + return true; +} + +/// An Exec of an answer's word in the tag of a pane a question waits on +/// (B2 on `Reload`): that answer. False for any other word. +pub fn answerWord(p: *Pardes, id: usize, word: []const u8) bool { + if (id >= MAX_PANES) return false; + const pane = p.panes[id] orelse return false; + const i = p.messages.waiting(pane) orelse return false; + const typed = std.mem.trim(u8, word, " \t\r\n"); + for (p.messages.live[i].asks.answers()) |a| { + const first = a.word[0 .. std.mem.indexOfScalar(u8, a.word, ' ') orelse a.word.len]; + if (std.mem.eql(u8, typed, first)) return answer(p, i, a.key); + } + return false; +} + +/// A question's Diff: the disk's text read (the host's read, taped) and +/// set against the buffer's, the lines they share at either end left out; +/// where they part, its place, and up to `Said.max_detail` of the lines +/// there, the disk's `+` and then the buffer's `-`, its detail, shown. +fn diskDiff(p: *Pardes, s: *Said, id: usize) void { + const pane = p.panes[id].?; + const f = if (pane.file) |*file| file else return; + const disk = @import("fs.zig").read(p, f.path) catch |err| return pardes.Messages.reportError(p, .at(id), "Diff", err); + defer p.gpa.free(disk); + const mine = pardes.panes.File.fileText(f, p.scratch.allocator()) catch return; + var a = std.mem.splitScalar(u8, mine, '\n'); + var b = std.mem.splitScalar(u8, disk, '\n'); + var line: u32 = 1; + var ours: []const u8 = ""; + var theirs: []const u8 = ""; + while (true) : (line += 1) { + const x = a.next(); + const y = b.next(); + if (x == null and y == null) return; + if (x != null and y != null and std.mem.eql(u8, x.?, y.?)) continue; + ours = if (x) |l| mine[@intFromPtr(l.ptr) - @intFromPtr(mine.ptr) ..] else ""; + theirs = if (y) |l| disk[@intFromPtr(l.ptr) - @intFromPtr(disk.ptr) ..] else ""; + break; + } + // The lines both end with, left out. + var ours_end = ours.len; + var theirs_end = theirs.len; + while (ours_end > 0 and theirs_end > 0) { + const ol = std.mem.lastIndexOfScalar(u8, ours[0 .. ours_end - 1], '\n'); + const tl = std.mem.lastIndexOfScalar(u8, theirs[0 .. theirs_end - 1], '\n'); + const o_line = ours[if (ol) |nl| nl + 1 else 0..ours_end]; + const t_line = theirs[if (tl) |nl| nl + 1 else 0..theirs_end]; + if (!std.mem.eql(u8, o_line, t_line)) break; + ours_end = if (ol) |nl| nl + 1 else 0; + theirs_end = if (tl) |nl| nl + 1 else 0; + } + s.places[0] = .{ .line = line, .col = 1 }; + s.places[0].path.set(f.path); + s.places[0].text.set("the disk's differs here"); + s.places_len = 1; + s.detail_len = 0; + // The disk's first: it is what the answer shows. + for ([_]struct { []const u8, []const u8 }{ .{ "+", theirs[0..theirs_end] }, .{ "-", ours[0..ours_end] } }) |side| { + var rows = std.mem.splitScalar(u8, std.mem.trimEnd(u8, side[1], "\n"), '\n'); + while (rows.next()) |row| { + if (side[1].len == 0 or s.detail_len == Said.max_detail) break; + s.detail[s.detail_len] = .{}; + _ = s.detail[s.detail_len].print("{s}{s}", .{ side[0], row }); + s.detail_len += 1; + } + } + s.open = true; +} + /// The words the newest live message said of `pane` has, "" for none: /// what its band shows, and what a write that failed on it answers. pub fn saidBy(m: *const Messages, pane: *const Pane) []const u8 { @@ -1093,3 +1236,52 @@ test "a burst of the same message is one message, counted, and moves nothing on const row = noticeRow(p, 78, &buf); try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10")); } + +test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); + defer p.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = "one\ntwo\nthree\n" }); + var dir: [4096]u8 = undefined; + const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/c.zig", .{dir[0..try tmp.dir.realPath(std.testing.io, &dir)]}); + defer std.testing.allocator.free(path); + const pane = try p.setTestFile("one\ntwo\nthree\n"); + const id = p.view().active; + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, path); + const f = &pane.file.?; + f.saved_hash = panes.File.fileHash(f); + // Unsaved: a line typed at the end. + for ([_]u21{ 'G', 'o', 'f', 'o', 'u', 'r', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } }); + try std.testing.expect(f.revision != f.saved_revision); + const disk = "zero\none\ntwo\nthree\n"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk }); + p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } }); + const i = p.messages.waiting(pane) orelse return error.NotAsked; + try std.testing.expectEqual(Kind.question, p.messages.live[i].kind); + // In its tag at rest, its answers offered; its mark `?`. + const prefix = try pardes.tagline.tagPrefix(p, pane); + try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk \u{25b8} r Reload k Keep mine d Diff \u{b7} SPC e to answer") != null); + try std.testing.expectEqualStrings("Reload", p.messages.waitingAnswers(pane)[0].word); + // The keyboard is not its: `r` is the body's (helix's replace). + p.update(.{ .key = .{ .cp = 'k' } }); + try std.testing.expect(p.messages.waiting(pane) != null); + // Given the keyboard: `d` shows the disk's lines and keeps asking; Esc + // leaves it waiting. + p.view().answering = pane.serial; + p.update(.{ .key = .{ .cp = 'd' } }); + const asked = &p.messages.live[p.messages.waiting(pane).?]; + try std.testing.expect(asked.open); + try std.testing.expectEqual(@as(u32, 1), asked.places[0].line); + try std.testing.expectEqualStrings("+zero", asked.detail[0].slice()); + try std.testing.expectEqual(pane.serial, p.view().answering); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(u32, 0), p.view().answering); + try std.testing.expect(p.messages.waiting(pane) != null); + // B2 on `Reload` in its tag: read again, the question gone. + try std.testing.expectEqual(@as(?usize, null), pardes.exec.execute(p, id, "Reload")); + while (p.nextEffect()) |_| {} + try std.testing.expect(p.messages.waiting(pane) == null); + try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content); +} diff --git a/core/exec.zig b/core/exec.zig index 3bb6e809..6b05cb8e 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -633,6 +633,8 @@ const max_exec_depth = 8; /// child is `$SHELL -c` the line, which shows its output and `exit N` when /// done, and which Kill signals. Answers the pane it went to. pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize { + // A question's answer word, on the pane it waits on (B2 on `Reload`). + if (pardes.Messages.answerWord(p, id, txt)) return null; return executeFrom(p, id, txt, false); } diff --git a/core/keys.zig b/core/keys.zig index 5257a093..68e3585d 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -206,6 +206,23 @@ pub fn handleKey(p: *Pardes, key: Key) void { } return; } + // A background question SPC e gave the keyboard: one of its answers' + // keys answers it (Diff leaves it asking), Esc leaves it waiting, and + // nothing else gets past it (pick-ui SPEC §10.4). + if (p.view().answering != 0) answering: { + const v = p.view(); + const at = p.paneBySerial(v.answering) orelse break :answering; + const i = p.messages.waiting(p.panes[at].?) orelse break :answering; + if (key.cp == Key.escape and !key.ctrl and !key.alt) { + v.answering = 0; + p.needs_frame = true; + return; + } + if (key.ctrl or key.alt or key.cp > 0x7f) return; + if (pardes.Messages.answer(p, i, @intCast(key.cp)) and key.cp != 'd') v.answering = 0; + return; + } + p.view().answering = 0; if (p.view().window_pick != null) return layout.windowKey(p, key); const pane = p.panes[p.view().active] orelse return; layout.noteTyped(p); diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index c7f22b9a..e47aec94 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -2388,7 +2388,9 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge pardes.panes.File.changed(p, 0, "three\n"); try testing.expectEqualStrings("two\nmine\n", f.content); try testing.expect(f.revision != f.saved_revision); - try testing.expect(th.logHas(p, "changed on disk (get reloads it, Save overwrites it)")); + // ...and asks, in its tag (Messages.waiting), which /log hears. + try testing.expect(p.messages.waiting(p.panes[0].?) != null); + try testing.expect(th.logHas(p, "changed on disk\n")); var want: [32]u8 = undefined; try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "changed {d}\n", .{serial}))); // Exit and get still ask about the edits. diff --git a/core/tagline.zig b/core/tagline.zig index 02d1b277..a389bb6d 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -172,7 +172,12 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 { /// The prefix as the tag shows it, built in `arena`. pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - const prefix = try pathPrefix(p, arena, pane); + const path = try pathPrefix(p, arena, pane); + // Asking (SPEC §3.2): a question waiting on it, after the path while + // the tag is at rest (not while it has the keyboard). + var asking: [512]u8 = undefined; + const asks = if (pane.focus == .tag or pane.prompt == .name) "" else p.messages.askingText(pane, p.view().answering == pane.serial, &asking); + const prefix = if (asks.len > 0) try std.mem.concat(arena, u8, &.{ path, " ", asks }) else path; // The space between the prefix and the tag's own text is the text's // (every default starts with one), but the prefix is computed, so it // cannot trust the text to keep it: with it deleted, Look and Exec diff --git a/test/monkey9p.zig b/test/monkey9p.zig index 1f213a3b..aaef1de6 100644 --- a/test/monkey9p.zig +++ b/test/monkey9p.zig @@ -1318,7 +1318,7 @@ fn oneFailureRule(c: *Ctx, a: Allocator, res: *Res) ?[]const u8 { // is the host's news, said whenever it arrives: no write's. var msgs: std.ArrayList([]const u8) = .empty; for (occurrences(a, window, "msg")) |m| { - if (std.mem.indexOf(u8, m, " deleted on disk (") != null or std.mem.indexOf(u8, m, " changed on disk (") != null or + if (std.mem.indexOf(u8, m, " deleted on disk (") != null or std.mem.indexOf(u8, m, " changed on disk") != null or std.mem.indexOf(u8, m, " reloaded ") != null) continue; msgs.append(a, m) catch oom(); } diff --git a/test/snapshots/filewatch.golden b/test/snapshots/filewatch.golden index 1e10ec08..b9716691 100644 --- a/test/snapshots/filewatch.golden +++ b/test/snapshots/filewatch.golden @@ -31,7 +31,8 @@ | | · @p1 a copy of the terminal's text: Tab or B2 runs it; what the program draws next replaces it (Ctrl-b types to the program) 1 message · SPC h m == snap kept grid=210x31 cursor=15,7 -|30: · /tmp/pardes-snap/filewatch/cwd/w.txt changed on disk (get reloads it, Save overwrites it) 2 messages · SPC h m +|6: ?/tmp/pardes-snap/filewatch/cwd/w.txt changed on disk ▸ r Reload k Keep mine d Diff · SPC e to answer Save Term Collapse Follow Del +|30: ? /tmp/pardes-snap/filewatch/cwd/w.txt changed on disk 1 question · SPC e == snap reloaded_sub grid=210x31 cursor=15,7 |19: 1 RENAMED |20: ~ @@ -42,4 +43,4 @@ |25: |26: |27: -|30: · reloaded /tmp/pardes-snap/filewatch/cwd/sub/s.txt 3 messages · SPC h m +|30: ? /tmp/pardes-snap/filewatch/cwd/w.txt changed on disk +1 · 1 question · SPC e -- cgit v1.3