summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig92
1 files changed, 92 insertions, 0 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index e421a32c..a26cbad9 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -547,6 +547,38 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool {
return true;
}
+/// SPC e (the Message word, SPEC ยง10.4), on the message the notice row
+/// leads with: an error that names places lists them in a +Search under
+/// pane `id`, where n and N walk them, the first landed on, and the error
+/// goes; a question takes the keyboard in its pane's tag; anything else,
+/// or nothing, opens the history.
+pub fn act(p: *Pardes, id: usize) void {
+ const m = &p.messages;
+ const lead = m.headline() orelse return openHistory(p, id);
+ if (lead.kind == .question) {
+ p.view().answering = lead.pane;
+ p.needs_frame = true;
+ return;
+ }
+ if (lead.kind != .@"error" or lead.places_len == 0 or id >= MAX_PANES) return openHistory(p, id);
+ const pane = p.panes[id] orelse return;
+ var rows: std.Io.Writer.Allocating = .init(p.gpa);
+ errdefer rows.deinit();
+ for (lead.places[0..lead.places_len]) |*place| rows.writer.print("{s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() }) catch |err| return reportError(p, .at(id), "Message", err);
+ const cause = lead.src;
+ const lead_at = for (m.live[0..m.live_len], 0..) |*s, k| {
+ if (s == lead) break k;
+ } else return;
+ m.remove(lead_at);
+ const content = rows.toOwnedSlice() catch |err| return reportError(p, .at(id), "Message", err);
+ pardes.panes.Output.fillResults(p, id, pardes.panes.paneDir(pane), .search, cause.slice(), content, null) catch |err| return reportError(p, .at(id), "Message", err);
+ _ = @import("look.zig").searchStep(p, id, 1);
+}
+
+fn openHistory(p: *Pardes, id: usize) void {
+ pardes.panes.Output.openMessages(p, id) catch |err| reportError(p, .at(id), "messages", err);
+}
+
/// 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 {
@@ -1285,3 +1317,63 @@ test "a file changed on disk under unsaved text asks in its tag and never takes
try std.testing.expect(p.messages.waiting(pane) == null);
try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content);
}
+
+test "SPC e on an error that names places lists them under the pane and lands on the first, on a question gives its tag the keyboard, and on anything else opens the history, the newest first" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\n");
+ const serial = pane.serial;
+ p.messages.live_len = 0;
+ const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ for ([_]u32{ 2, 4 }, 0..) |line, k| {
+ err.places[k] = .{ .line = line, .col = 1 };
+ err.places[k].path.set("/test.txt");
+ err.places[k].text.set("bad");
+ }
+ err.places_len = 2;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'e' } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.headline() == null);
+ const here = p.paneBySerial(serial).?;
+ const list = p.panes[p.panes[here].?.search_pane orelse return error.NoList].?;
+ try std.testing.expect(std.mem.indexOf(u8, list.file.?.content, "/test.txt:4:1") != null);
+ try std.testing.expectEqual(@as(i32, 1), p.panes[here].?.body.cur_row);
+ // A question: its tag gets the keyboard.
+ keep(p, .question, serial, "/test.txt", "changed on disk").asks = .disk;
+ try std.testing.expect(p.executeBuiltinLine(here, "Message"));
+ try std.testing.expectEqual(serial, p.view().answering);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u32, 0), p.view().answering);
+ // Anything else: the history, the newest first, each with its glyph.
+ p.messages.live_len = 0;
+ _ = say(p, .notice, here, "older words");
+ _ = say(p, .warn, here, "newer words");
+ try std.testing.expect(p.executeBuiltinLine(here, "Message"));
+ const history = for (p.panes) |slot| {
+ const shown = slot orelse continue;
+ const f = shown.file orelse continue;
+ if (std.mem.endsWith(u8, f.path, config.messages_buffer)) break f.content;
+ } else return error.NoHistory;
+ const newer = std.mem.indexOf(u8, history, "! ") orelse return error.NoGlyph;
+ try std.testing.expect(newer < std.mem.indexOf(u8, history, "older words").?);
+}
+
+test "Esc at rest takes a search's tints first, then the warnings and errors, and only then goes back" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("alpha beta alpha\n");
+ const id = p.view().active;
+ p.messages.live_len = 0;
+ p.update(.{ .key = .{ .cp = '*' } });
+ p.update(.{ .key = .{ .cp = 'n' } });
+ while (p.nextEffect()) |_| {}
+ if (pane.places.pattern.len == 0 and pane.places.hits.items.len == 0) return error.NoTints;
+ _ = say(p, .@"error", id, "broke");
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(pane.places.pattern.len == 0 and pane.places.hits.items.len == 0);
+ try std.testing.expectEqual(@as(u8, 1), p.messages.live_len);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(@as(u8, 0), p.messages.live_len);
+ try std.testing.expectEqual(id, p.view().active);
+}