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 | |
| 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]>
| -rw-r--r-- | core/Messages.zig | 92 | ||||
| -rw-r--r-- | core/Output.zig | 18 | ||||
| -rw-r--r-- | core/builtins.zig | 17 | ||||
| -rw-r--r-- | core/config.zig | 1 | ||||
| -rw-r--r-- | core/normal.zig | 13 | ||||
| -rw-r--r-- | docs/typ/builtins-gui.json | 5 | ||||
| -rw-r--r-- | docs/typ/builtins-tui.json | 3 | ||||
| -rw-r--r-- | test/snapshots/builtins.golden | 6 | ||||
| -rw-r--r-- | test/snapshots/leader.golden | 4 |
9 files changed, 144 insertions, 15 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); +} diff --git a/core/Output.zig b/core/Output.zig index 380fadb1..a7398ccf 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -979,19 +979,27 @@ pub fn openConfig(p: *Pardes, id: usize) !void { return openRead(p, id, .{ .cmd = .DumpConfig }, "", content); } -/// The message-row log, oldest first — the lines that were said in passing and -/// then cleared by the next keystroke. +/// The messages' history (the log ring), the newest first, each with its +/// kind's glyph, a live error's places under it (SPC h m). pub fn openMessages(p: *Pardes, id: usize) !void { var out: std.Io.Writer.Allocating = .init(p.gpa); errdefer out.deinit(); - var i: usize = 0; - while (p.messages.at(i)) |m| : (i += 1) { + var i: usize = p.messages.len; + while (i > 0) { + i -= 1; + const m = p.messages.at(i).?; + try out.writer.print("{s} ", .{m.kind.glyph()}); if (m.serial != 0) try out.writer.print("{d}: ", .{m.serial}); try out.writer.writeAll(m.slice()); if (m.repeats > 1) try out.writer.print(" (x{d})", .{m.repeats}); try out.writer.writeByte('\n'); + for (p.messages.live[0..p.messages.live_len]) |*s| { + if (s.kind != .@"error" or s.places_len == 0 or !std.mem.eql(u8, pardes.Messages.Message.body(s.text.slice()), pardes.Messages.Message.body(m.slice()))) continue; + for (s.places[0..s.places_len]) |*place| try out.writer.print(" {s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() }); + break; + } } - if (i == 0) try out.writer.writeAll("nothing has been said yet\n"); + if (p.messages.len == 0) try out.writer.writeAll("nothing has been said yet\n"); const content = try out.toOwnedSlice(); return openRead(p, id, .{ .cmd = .Messages }, "", content); } diff --git a/core/builtins.zig b/core/builtins.zig index 0c643a18..af53fa6f 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1709,7 +1709,22 @@ pub const LocationsConfig = struct { } }; -/// Show the messages said so far in a +Messages. +/// Act on the message the notice row leads with. +/// +/// An error that names places lists them in a +Search, which the Look walk +/// steps through; a question takes the keyboard in its pane's tag (its +/// answer's key answers it, Esc leaves it waiting); anything else opens the +/// history. +pub const Message = struct { + pub const quiet = true; + pub const scope: Scope = .session; + pub fn run(c: Ctx) void { + pardes.Messages.act(c.p, c.id); + } +}; + +/// Show the messages said so far in a +Messages, the newest first, an +/// error's places under it. pub const Messages = struct { pub const scope: Scope = .session; pub const output: OutputTraits = .{ .name = config.messages_buffer }; diff --git a/core/config.zig b/core/config.zig index 9673da73..dd8ad5d3 100644 --- a/core/config.zig +++ b/core/config.zig @@ -115,6 +115,7 @@ pub const leader_path = paths: { .Changelog = "hc", .Build = "hb", .Messages = "hm", + .Message = "e", .Newcol = "cn", .Delcol = "cd", .Joincol = "cj", diff --git a/core/normal.zig b/core/normal.zig index 7efe0bf6..3dade7a6 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1094,8 +1094,19 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { if (comptime Editor.lib) return; // typed again by a macro, Esc is only helix's if (e.p.macro.replaying > 0) return; - // The warnings and errors first, then the previous pane. + // At rest a thing at a time (pick-ui SPEC §10.4): a search's + // tints, then the warnings and errors, then the selections + // (the primary kept); with none of them left, the previous pane. + if (e.p.panes[e.p.view().active]) |pane| if (t == &pane.body and (pane.places.pattern.len > 0 or pane.places.hits.items.len > 0)) { + pane.places.clear(e.p.gpa); + e.p.needs_frame = true; + return; + }; if (e.p.messages.retire(&.{ .warn, .@"error" }) > 0) return; + if (t.nsel > 0) { + t.nsel = 0; + return; + } tagline.exitHeader(e.p); // out of a header too, as Shift-Esc return exec.runBuiltin(e.p, .Last, e.p.view().active, "", null); }, diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 8ec78384..3d8819a0 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -66,8 +66,9 @@ {"name": "LookPrev", "leader": "SPC j p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the previous thing a Look would open, as LookNext walks forward.", "text": "Select the previous thing a Look would open, as LookNext walks forward.\nEnter opens what it selected."}, {"name": "Lspinfo", "leader": "SPC l i", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show which index and language server serve this file, and their state, in a +Lsp.", "text": "Show which index and language server serve this file, and their state, in a +Lsp.\nThe index.scip it asks (or the Index that would write one), its server and the server's state (not started yet, failed and waiting to retry), and what answered each query lately."}, {"name": "Lspwhy", "leader": "SPC l w", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Explain, step by step in a +Lsp, how the last language server request was answered.", "text": "Explain, step by step in a +Lsp, how the last language server request was answered."}, - {"name": "MessageLinger", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "How long, in milliseconds, a message stays after what dismisses it.", "text": "How long, in milliseconds, a message stays after what dismisses it."}, - {"name": "Messages", "leader": "SPC h m", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Show the messages said so far in a +Messages.", "text": "Show the messages said so far in a +Messages."}, + {"name": "Message", "leader": "SPC e", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Act on the message the notice row leads with.", "text": "Act on the message the notice row leads with.\nAn error that names places lists them in a +Search, which the Look walk steps through; a question takes the keyboard in its pane's tag (its answer's key answers it, Esc leaves it waiting); anything else opens the history."}, + {"name": "MessageLinger", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "How long, in milliseconds, an echo or a notice stays bright before it dims; a warning twice as long.", "text": "How long, in milliseconds, an echo or a notice stays bright before it dims; a warning twice as long."}, + {"name": "Messages", "leader": "SPC h m", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Show the messages said so far in a +Messages, the newest first, an error's places under it.", "text": "Show the messages said so far in a +Messages, the newest first, an error's places under it."}, {"name": "Mini", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Map a file of this pane's directory in braille dots: `Mini notes.txt`.", "text": "Map a file of this pane's directory in braille dots: `Mini notes.txt`.\nA pane of its own, drawn once: a Mini of the same file again draws it anew."}, {"name": "Mode", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Step this pane to its next input mode: normal, insert, and in a terminal raw.", "text": "Step this pane to its next input mode: normal, insert, and in a terminal raw.\nFrom the last it goes back to normal. The keyboard goes to the pane's text."}, {"name": "More", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Let a query pane's Grep stopped at its 2000 lines go on for 2000 more.", "text": "Let a query pane's Grep stopped at its 2000 lines go on for 2000 more."}, diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 14e8a9d4..1e7c80f7 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -62,8 +62,9 @@ {"name": "LookPrev", "leader": "SPC j p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select the previous thing a Look would open, as LookNext walks forward.", "text": "Select the previous thing a Look would open, as LookNext walks forward.\nEnter opens what it selected."}, {"name": "Lspinfo", "leader": "SPC l i", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show which index and language server serve this file, and their state, in a +Lsp.", "text": "Show which index and language server serve this file, and their state, in a +Lsp.\nThe index.scip it asks (or the Index that would write one), its server and the server's state (not started yet, failed and waiting to retry), and what answered each query lately."}, {"name": "Lspwhy", "leader": "SPC l w", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Explain, step by step in a +Lsp, how the last language server request was answered.", "text": "Explain, step by step in a +Lsp, how the last language server request was answered."}, + {"name": "Message", "leader": "SPC e", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Act on the message the notice row leads with.", "text": "Act on the message the notice row leads with.\nAn error that names places lists them in a +Search, which the Look walk steps through; a question takes the keyboard in its pane's tag (its answer's key answers it, Esc leaves it waiting); anything else opens the history."}, {"name": "MessageLinger", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "How long, in milliseconds, an echo or a notice stays bright before it dims; a warning twice as long.", "text": "How long, in milliseconds, an echo or a notice stays bright before it dims; a warning twice as long."}, - {"name": "Messages", "leader": "SPC h m", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Show the messages said so far in a +Messages.", "text": "Show the messages said so far in a +Messages."}, + {"name": "Messages", "leader": "SPC h m", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Show the messages said so far in a +Messages, the newest first, an error's places under it.", "text": "Show the messages said so far in a +Messages, the newest first, an error's places under it."}, {"name": "Mini", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Map a file of this pane's directory in braille dots: `Mini notes.txt`.", "text": "Map a file of this pane's directory in braille dots: `Mini notes.txt`.\nA pane of its own, drawn once: a Mini of the same file again draws it anew."}, {"name": "Mode", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Step this pane to its next input mode: normal, insert, and in a terminal raw.", "text": "Step this pane to its next input mode: normal, insert, and in a terminal raw.\nFrom the last it goes back to normal. The keyboard goes to the pane's text."}, {"name": "More", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Let a query pane's Grep stopped at its 2000 lines go on for 2000 more.", "text": "Let a query pane's Grep stopped at its 2000 lines go on for 2000 more."}, diff --git a/test/snapshots/builtins.golden b/test/snapshots/builtins.golden index cfcb9d88..86d26b29 100644 --- a/test/snapshots/builtins.golden +++ b/test/snapshots/builtins.golden @@ -91,7 +91,7 @@ |30: ~ |56: +Search 1/1 Save Undock Del |57: /^ +Look -|58: @p2:220:1 Look enter, right-click +|58: @p2:224:1 Look enter, right-click |66: /tmp/pardes-snap/builtins/cwd/+Help:1 == snap docs-group grid=120x67 cursor=7,10 |10: 1 pardes builtins under SPC h @@ -103,7 +103,7 @@ |18: 8 Show this build's version and what changed to reach it, in a +Changelog. |19: 9 |20: 10 SPC h m Messages -|21: 11 Show the messages said so far in a +Messages. +|21: 11 Show the messages said so far in a +Messages, the newest first, an error's places under it. |22: 12 |23: 13 SPC h t Tutor topbar |24: 14 Open the tutor, a document to work through. @@ -116,7 +116,7 @@ == snap tutor-from-index grid=120x67 cursor=7,37 |26: +Search 1/1 Save Undock Del |27: /^ +Look -|28: @p2:220:1 Look enter, right-click +|28: @p2:224:1 Look enter, right-click |36: /tmp/pardes-snap/builtins/cwd/+Tutor Save Term Collapse Follow Del |37: 1 |38: 2 PARDES TUTOR diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index 2076b9b9..8c45af73 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -58,7 +58,7 @@ |14: 8 Show this build's version and what changed to reach it, in a +Changelog. |15: 9 |16: 10 SPC h m Messages -|17: 11 Show the messages said so far in a +Messages. +|17: 11 Show the messages said so far in a +Messages, the newest first, an error's places under it. |18: 12 |19: 13 SPC h t Tutor topbar |20: 14 Open the tutor, a document to work through. @@ -116,7 +116,7 @@ |32: 8 Show this build's version and what changed to reach it, in a +Changelog. |33: 9 |34: 10 SPC h m Messages -|35: 11 Show the messages said so far in a +Messages. +|35: 11 Show the messages said so far in a +Messages, the newest first, an error's places under it. |36: 12 |37: 13 SPC h t Tutor topbar |38: 14 Open the tutor, a document to work through. |
