summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Messages.zig200
-rw-r--r--core/Term.zig4
-rw-r--r--core/body_layer.zig120
-rw-r--r--core/draw.zig65
-rw-r--r--core/exec.zig9
-rw-r--r--core/panes.zig49
-rw-r--r--dev/Inbox.zig3
-rw-r--r--runtime/macos.zig2
-rw-r--r--runtime/upgrade.zig2
-rw-r--r--test/snapshots/lsp.golden1
-rw-r--r--test/snapshots/shellset.golden3
11 files changed, 420 insertions, 38 deletions
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