diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 21:27:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 21:28:51 -0300 |
| commit | 2e29f8ffebda59aa528c392535b7f1db31be91f8 (patch) | |
| tree | badd7ae81363eb86fb366619952fd6658415b5a0 /core/Messages.zig | |
| parent | e91261ff4f4602afec14d2fb958fd3e51a4dc62d (diff) | |
| download | pardes-2e29f8ffebda59aa528c392535b7f1db31be91f8.tar.gz pardes-2e29f8ffebda59aa528c392535b7f1db31be91f8.zip | |
messages: SPC e acts on the message the notice row leads with, SPC h m is the history newest first, and Esc at rest takes a thing at a time (pick-ui SPEC §10.4, walk UI line C item 5): the Message word (SPC e, quiet: what it does shows) lists an error's places in a +Search under the pane and lands on the first (today's list, walked by the Look walk until agent D's picker lands lists in the pane), the error gone; a question gets the keyboard in its tag (View.answering, item 4); anything else, or nothing, opens the history; the history (Messages, SPC h m) is the log ring newest first, each line its kind's glyph, a live error's places under it, a question's answer logged after it; Esc in normal mode at rest takes a search's tints first (Places.clear), then the warnings and errors, then the extra selections (the primary kept), and only then goes back to the previous pane; tests: Messages.zig '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', 'Esc at rest takes a search's tints first, then the warnings and errors, and only then goes back'; docs/typ/builtins-tui.json from the registry; tui: core-test, shell-test, pane-test, behaviour-test pass; process-test 0 of 146 failed after the builtins and leader goldens took the Messages word's longer doc line
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 92 |
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); +} |
