summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig105
1 files changed, 95 insertions, 10 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 7cee0d25..c9166aed 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -521,19 +521,21 @@ pub fn answer(p: *Pardes, i: usize, key: u8) bool {
}
/// 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.
+/// leads with: an error that names places lands them as a list in pane
+/// `id`'s walk (Pick's `list`, its word `✗ <cause>` in the trail), the
+/// first landed on, n and N walking the rest, and the error goes (a
+/// +Search under the pane where jumps do not walk, or for a 9P script:
+/// Pick.asked); 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);
+ const lead = m.headline() orelse return history(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);
+ if (lead.kind != .@"error" or lead.places_len == 0 or id >= MAX_PANES) return history(p, id);
const pane = p.panes[id] orelse return;
var rows: std.Io.Writer.Allocating = .init(p.gpa);
errdefer rows.deinit();
@@ -544,11 +546,26 @@ pub fn act(p: *Pardes, id: usize) void {
} else return;
m.remove(lead_at);
const content = rows.toOwnedSlice() catch |err| return reportError(p, .at(id), "Message", err);
+ if (pardes.Pick.asked(p)) {
+ defer p.gpa.free(content);
+ // The cause cut at a character's start to the word's room.
+ const src = cause.slice();
+ var cut = @min(src.len, 24 - "\u{2717} ".len);
+ while (cut > 0 and cut < src.len and src[cut] & 0xC0 == 0x80) cut -= 1;
+ var word: Buf(24) = .{};
+ pardes.Pick.open(p, id, .list, word.print("\u{2717} {s}", .{src[0..cut]}), "", content);
+ return pardes.Pick.landHere(p);
+ }
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 {
+/// The history (SPC h m, the Messages word; SPC e with nothing to act on):
+/// where jumps walk a picker over it in pane `id`'s tag (Pick's
+/// `messages`), the newest first, Enter Looking a row, C-q keeping it as
+/// a +Messages; else (or for a 9P script, Pick.asked) the +Messages.
+pub fn history(p: *Pardes, id: usize) void {
+ if (pardes.Pick.asked(p) and id < MAX_PANES and p.panes[id] != null) return pardes.Pick.open(p, id, .messages, "", "", "");
pardes.panes.Output.openMessages(p, id) catch |err| reportError(p, .at(id), "messages", err);
}
@@ -1379,13 +1396,81 @@ test "SPC e on an error that names places lists them under the pane and lands on
_ = 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 said_so_far = 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").?);
+ const newer = std.mem.indexOf(u8, said_so_far, "! ") orelse return error.NoGlyph;
+ try std.testing.expect(newer < std.mem.indexOf(u8, said_so_far, "older words").?);
+}
+
+test "where jumps walk, SPC e lands an error's places as a list in the pane's walk, n walking them; SPC h m is a picker over the history in the pane's tag, the newest first, Enter on a message going to its cause, C-q keeping it as a +Messages" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\n");
+ const id = p.view().active;
+ 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;
+ var panes_before: usize = 0;
+ for (p.panes) |slot| panes_before += @intFromBool(slot != null);
+ for (" e") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.headline() == null);
+ // Landed in this reading pane, no pane made: on the first place, the
+ // list's word in its trail.
+ var panes_now: usize = 0;
+ for (p.panes) |slot| panes_now += @intFromBool(slot != null);
+ try std.testing.expectEqual(panes_before, panes_now);
+ try std.testing.expectEqual(id, p.view().active);
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "\u{2717} @p9 zig build 1/2") != null);
+ // n: the next place, the word saying so.
+ p.update(.{ .key = .{ .cp = 'n' } });
+ try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
+ try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "\u{2717} @p9 zig build 2/2") != null);
+ // SPC h m: the history in this pane's tag, a row a message, the newest
+ // first; no pane made.
+ _ = say(p, .echo, id, "older");
+ _ = say(p, .warn, id, "newest");
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.pick, p.view().tag_state.kind);
+ const pk = pardes.Pick.live(p).?;
+ try std.testing.expectEqual(pardes.Pick.Source.messages, pk.source);
+ var marks: [256]u16 = undefined;
+ var nmarks: usize = 0;
+ // (Row 0 is the word's own echo, `Messages`, said as it ran.)
+ try std.testing.expect(std.mem.indexOf(u8, pk.names.row(1, &marks, &nmarks), "newest") != null);
+ try std.testing.expect(std.mem.indexOf(u8, pk.names.row(2, &marks, &nmarks), "older") != null);
+ // Enter on a message: its cause's pane has the keyboard, the picker
+ // rolled up; then the history again.
+ p.update(.{ .key = .{ .cp = Key.down } });
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqual(id, p.view().active);
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.pick, p.view().tag_state.kind);
+ // C-q: kept as the +Messages, the picker rolled up.
+ p.update(.{ .key = .{ .cp = 'q', .ctrl = true } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expectEqual(pardes.TagState.Kind.rest, p.view().tag_state.kind);
+ panes_now = 0;
+ for (p.panes) |slot| panes_now += @intFromBool(slot != null);
+ try std.testing.expectEqual(panes_before + 1, panes_now);
+ const kept = p.panes[p.view().active].?;
+ try std.testing.expect(std.mem.endsWith(u8, kept.file.?.path, config.messages_buffer));
}
test "Esc at rest takes a search's tints first, then the warnings and errors, and only then goes back" {