diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 15:47:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 15:55:44 -0300 |
| commit | 544d7265a8527be11ad9e8f944fa3723ae113a31 (patch) | |
| tree | bf014e290626ad88e546b06079b94dc53326d938 /core/Output.zig | |
| parent | 33b1f209162f94a9200f8c00d131aae772eb02f2 (diff) | |
| download | pardes-544d7265a8527be11ad9e8f944fa3723ae113a31.tar.gz pardes-544d7265a8527be11ad9e8f944fa3723ae113a31.zip | |
help: bare `Help` lists every builtin of this view as before, a row each (its keys, its name, its other shortcuts), now with its whole documentation under it, a line a paragraph, and a blank line after; `Help <name>` shows that one alone, and `Help <keys>` the builtins under SPC and those keys (the user's words of 2026-11-23: "the Help command wiht no arguments should list all builtins like now but with their larger-ish documentation, and the Help builtin with arguments should show the documentation specific for that builtin only"): Help took no argument, so `Help l` ran as a shell command and only `SPC l ?` opened a group; now `Help` takes one (core/builtins.zig `Help`): a builtin's name as the registry takes it, or an addon's word, opens its row, its documentation and what the list does not say, a line each (core/Output.zig `writeWordHelp`: its keys spelled out, its argument, a setting's values (`Settings.takes`), what it acts on and so which ctl takes it, a window's word in a terminal, and `pardes do <Word> [ARG]`); SPC keys open that group (`openHelp`, as `SPC <keys> ?` does); a word that is neither fails, `Help: <word>: no such builtin, nor SPC keys`, the +Help left as it was; every Help fills the one +Help (openRead, as before: a second replaces its text); the header is one paragraph, wrapped by the pane, not three lines broken for a 40-column pane; an addon's word's row puts its name in the builtins' name column, `(addon <kind>)` after it and its doc under it; the paragraph "Callstack: static caller chains, ..." is gone, Callstack's and Callers' documentation say it; tests: test/behaviour/builtins.zig "builtins: Help holds every builtin with its whole documentation, `Help <name>` that one's alone, and B2 on a builtin's name in it runs it" (through 9P alone: for every word of /commands, `Help <word>`'s documentation is in bare Help's text whole under its row, begins with its /commands summary and holds no other word's; `Help diff` refused; `Help c` the column group; B2 on `Newcol` in `Help Newcol`'s row adds a column), core/Output.zig's full-Help test (rows, each one's paragraphs, the language keys), test/behaviour/addons.zig's addon row, test/panes.zig's Tutor click finds its row by the pane's wrap map (the documentation above it wraps), test/process/tty_boot.zig's waits for the new header; docs/typ/builtins-tui.json regenerated (Help takes an argument); core-test (Help) 12/12, behaviour-test (Help) 4/4, pane-test (Help) 4/4, Debug tui; the whole suites run on item 4's change, and the process-test goldens the Help pane shows change in the last change (the full index's scroll is set once the documentation is written)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Output.zig')
| -rw-r--r-- | core/Output.zig | 171 |
1 files changed, 137 insertions, 34 deletions
diff --git a/core/Output.zig b/core/Output.zig index 09ec2a51..a1e5865e 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -757,13 +757,16 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void { look.armLookWalk(p, free); } +/// The +Help's text: a builtin a row (its keys, its name, its other +/// shortcuts) with its documentation under it, a line a paragraph, and a +/// blank line; bare (`prefix` empty) every builtin of this view, then the +/// addons' words, the language keys and how a query pane is driven; with +/// `prefix`, the builtins under SPC and those keys. fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![]u8 { - const full_header = "pardes builtins, and how to run each:\nSPC and its keys, a chord, a button, the\ntopbar - or the name, executed anywhere.\n\n"; + const full_header = "pardes builtins: each one's keys and its name, then what it does. Run one by its keys, or by its name anywhere: B2 on the word, Exec <name>, a line of a ctl file, or `pardes do <name>` from a shell. `Help <name>` shows one builtin alone; `Help <keys>` (or SPC, those keys, then ?) the builtins under SPC and those keys.\n\n"; const group_header = "pardes builtins under SPC"; - const calls_help = "\nCallstack: static caller chains,\nwith signatures and clickable call sites.\nCallers / Callees: one direction at a time.\n"; - const show_calls_help = prefix.len == 0 or std.mem.eql(u8, prefix, "l"); const language_footer = - "\nlanguage keys (motions, not words):\n" ++ + "language keys (motions, not words):\n" ++ "gd gD gy gi gr goto: definition,\n" ++ " declaration, type-def,\n" ++ " implementation, refs\n" ++ @@ -775,7 +778,7 @@ fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![] "Tab after a . completion, in insert\n" ++ "C-left-click definition, by mouse\n" ++ "SPC l ... hover, rename, symbols,\n" ++ - " calls, types: above\n"; + " calls, types: above\n\n"; var out: std.Io.Writer.Allocating = .init(gpa); errdefer out.deinit(); const w = &out.writer; @@ -790,26 +793,15 @@ fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![] // word is none in a terminal's view if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue; if (!builtins.registry.here(p, row.cmd)) continue; - try w.print("{s}\n", .{row.line}); + try w.print("{s}\n{s}\n\n", .{ row.line, builtins.registry.doc(row.cmd).text }); } // An addon's words, after the core's, each saying whose it is. for (p.kinds.words[0..p.kinds.nwords]) |*kw| { const path = kw.leader.slice(); if (!std.mem.startsWith(u8, path, prefix) or (prefix.len > 0 and path.len == 0)) continue; - var keys: [64]u8 = undefined; - var n: usize = 0; - if (path.len > 0) for ("SPC") |ch| { - keys[n] = ch; - n += 1; - }; - for (path) |ch| if (n + 2 <= keys.len) { - keys[n] = ' '; - keys[n + 1] = ch; - n += 2; - }; - try w.print("{s: <12}{s} {s} (addon {s})\n", .{ keys[0..n], kw.name.slice(), kw.doc.slice(), p.kinds.kinds[kw.kind].nameOf() }); + try addonRow(w, p, kw); + try w.print("{s}\n\n", .{kw.doc.slice()}); } - if (show_calls_help) try w.writeAll(calls_help); if (prefix.len == 0) try w.writeAll(language_footer); // The paths that run a builtin with a word (config.leader_args), and how // a query pane is driven: under SPC f, b, s and in the whole listing. @@ -817,7 +809,7 @@ fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![] if (std.mem.startsWith(u8, la.path, prefix)) break true; } else std.mem.eql(u8, prefix, "f"); if (prefix.len == 0 or search_group) { - try w.writeAll("\nsearch: a query pane under the text,\nits line 1 the query, its first word\nthe source (/ Find Grep Recent Panes\nSymbols All Refs Def Impl Diagnostics)\n"); + try w.writeAll("search: a query pane under the text,\nits line 1 the query, its first word\nthe source (/ Find Grep Recent Panes\nSymbols All Refs Def Impl Diagnostics)\n"); for (config.leader_args) |la| { if (!std.mem.startsWith(u8, la.path, prefix)) continue; var keys: [16]u8 = @splat(' '); @@ -836,6 +828,91 @@ fn helpContent(p: *const Pardes, gpa: std.mem.Allocator, prefix: []const u8) ![] return out.toOwnedSlice(); } +/// The column a builtin's name stands at in its row (pardes.builtin_rows): +/// an addon's word's row puts its name there too. +const name_column = std.mem.indexOf(u8, pardes.builtin_rows[0].line, @tagName(pardes.builtin_rows[0].cmd)).?; + +/// An addon's word's row: its keys, its name, whose it is. +fn addonRow(w: *std.Io.Writer, p: *const Pardes, kw: *const pardes.Kind.Word) std.Io.Writer.Error!void { + var key_buf: [32]u8 = undefined; + var keys: std.Io.Writer = .fixed(&key_buf); + const path = kw.leader.slice(); + if (path.len > 0) keys.writeAll("SPC") catch {}; + for (path) |ch| keys.print(" {c}", .{ch}) catch {}; + try w.print("{s}", .{keys.buffered()}); + try w.splatByteAll(' ', name_column -| keys.buffered().len); + try w.print("{s} (addon {s})\n", .{ kw.name.slice(), p.kinds.kinds[kw.kind].nameOf() }); +} + +/// Builtin `b` alone (`Help <name>`, `pardes help <name>`): its row, its +/// documentation, and what the list does not say, a line each: its keys +/// spelled out, its argument, what it acts on, and the same word from a +/// shell. +pub fn writeWordHelp(w: *std.Io.Writer, b: Builtin) std.Io.Writer.Error!void { + const row = for (pardes.builtin_rows) |r| { + if (r.cmd == b) break r; + } else unreachable; // a row a builtin + const name = @tagName(b); + try w.print("{s}\n\n{s}\n\n", .{ row.line, builtins.registry.doc(b).text }); + try w.writeAll("keys: "); + const shortcuts = std.mem.trim(u8, row.line[std.mem.indexOf(u8, row.line, name).? + name.len ..], " "); + var first = true; + if (row.path) |path| { + try w.writeAll("SPC"); + for (path) |c| try w.print(" {c}", .{c}); + try w.writeAll(" in normal mode"); + first = false; + } + var parts = std.mem.splitSequence(u8, shortcuts, ", "); + while (parts.next()) |part| if (part.len > 0) { + if (!first) try w.writeAll("; "); + first = false; + try w.writeAll(if (std.mem.eql(u8, part, "topbar")) "its word in the workspace tag" else part); + }; + if (row.path == null and shortcuts.len == 0) try w.print("none: run its name (B2 on it, Exec {s})", .{name}); + try w.writeAll("\nargument: "); + if (config.Settings.find(name)) |setting| { + try w.writeAll(config.Settings.takes(setting.action) orelse "a value"); + if (!builtins.registry.requiresArg(b)) try w.writeAll(", or none"); + } else try w.writeAll(if (!builtins.registry.takesArg(b)) "none" else if (builtins.registry.requiresArg(b)) "required" else "optional"); + try w.writeAll("\nacts on: "); + if (builtins.registry.needs(b)) |kind| try w.print("{s}, ", .{kind.noun()}); + try w.writeAll(if (b == .Edit) + "the pane it runs from (over 9P, a pane's ctl, or the root's for the pane with the keyboard)" + else if (builtins.registry.scope(b) == .session) + "the session (over 9P, the root ctl)" + else + "the pane it runs from (over 9P, that pane's ctl)"); + if (!builtins.registry.hereFor(b, builtins.capabilities, false)) try w.writeAll("; a window's word: none in a terminal"); + try w.print("\nfrom a shell: pardes do {s}{s}\n", .{ name, if (!builtins.registry.takesArg(b)) "" else if (builtins.registry.requiresArg(b)) " ARG" else " [ARG]" }); +} + +/// An addon's word alone, as `writeWordHelp` writes a builtin. +fn writeAddonWordHelp(w: *std.Io.Writer, p: *const Pardes, kw: *const pardes.Kind.Word) std.Io.Writer.Error!void { + try addonRow(w, p, kw); + try w.print("\n{s}\n\nkeys: ", .{kw.doc.slice()}); + const path = kw.leader.slice(); + if (path.len == 0) try w.print("none: run its name (B2 on it, Exec {s})", .{kw.name.slice()}) else { + try w.writeAll("SPC"); + for (path) |c| try w.print(" {c}", .{c}); + try w.writeAll(" in normal mode"); + } + const arg = switch (kw.arg) { + pardes.Kind.c.PA_ARG_NONE => "none", + pardes.Kind.c.PA_ARG_REQUIRED => "required", + else => "optional", + }; + try w.print("\nargument: {s}\nacts on: {s} pane, the one it runs from (over 9P, that pane's ctl)\nfrom a shell: pardes do {s}{s}\n", .{ + arg, + p.kinds.kinds[kw.kind].nameOf(), + kw.name.slice(), + if (kw.arg == pardes.Kind.c.PA_ARG_NONE) "" else if (kw.arg == pardes.Kind.c.PA_ARG_REQUIRED) " ARG" else " [ARG]", + }); +} + +/// The +Help (keys.zig's `SPC ... ?`, the `Help` word): bare, every +/// builtin; `prefix`, those under SPC and those keys. One +Help: a second +/// fills it again. pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { const content = try helpContent(p, p.gpa, prefix); // content is handed off unfreed on purpose: openRead adopts it or frees @@ -843,6 +920,35 @@ pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { return openRead(p, id, .{ .cmd = .Help }, prefix, content); } +/// `Help <what>`: a builtin's name or an addon's word, as the registry +/// takes them, that one alone in the +Help; SPC keys, the builtins under +/// them. False for a word that is neither, the +Help left as it was. +pub fn openHelpOn(p: *Pardes, id: usize, what: []const u8) !bool { + const b = std.meta.stringToEnum(Builtin, what); + const word = for (p.kinds.words[0..p.kinds.nwords]) |*kw| { + if (std.mem.eql(u8, kw.name.slice(), what)) break kw; + } else null; + if (b == null and word == null) { + if (!underKeys(p, what)) return false; + try openHelp(p, id, what); + return true; + } + var out: std.Io.Writer.Allocating = .init(p.gpa); + errdefer out.deinit(); + if (b) |one| try writeWordHelp(&out.writer, one) else try writeAddonWordHelp(&out.writer, p, word.?); + try openRead(p, id, .{ .cmd = .Help }, what, try out.toOwnedSlice()); + return true; +} + +/// Whether some builtin of this view, or an addon's word, is under SPC and +/// `keys`. +fn underKeys(p: *const Pardes, keys: []const u8) bool { + for (pardes.builtin_rows) |row| if (row.path) |path| if (std.mem.startsWith(u8, path, keys) and builtins.registry.here(p, row.cmd)) return true; + for (config.leader_args) |la| if (std.mem.startsWith(u8, la.path, keys)) return true; + for (p.kinds.words[0..p.kinds.nwords]) |*kw| if (kw.leader.slice().len > 0 and std.mem.startsWith(u8, kw.leader.slice(), keys)) return true; + return false; +} + /// Where a dump goes by default, as the session's environment says (the /// authority's, `tape.authority`): in `buf`. fn dumpDirectory(buf: []u8) []const u8 { @@ -1078,33 +1184,30 @@ test "plain output does not opt into location decoration" { try std.testing.expect(traits(.{ .query = .completion }).locations); } -test "full Help renders builtin rows, a call hierarchy guide, then language keys" { +test "full Help renders each builtin's row with its documentation under it, then language keys" { const core = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer core.deinit(); const content = try helpContent(core, std.testing.allocator, ""); defer std.testing.allocator.free(content); - // FIRST blank line: the end of the header (the footer opens with one too) + // FIRST blank line: the end of the header const body = content[(std.mem.indexOf(u8, content, "\n\n") orelse return error.MissingHelpHeader) + 2 ..]; var lines = std.mem.splitScalar(u8, body, '\n'); - for (pardes.builtin_rows) |row| if (builtins.registry.here(core, row.cmd)) - try std.testing.expectEqualStrings(row.line, lines.next() orelse - return error.MissingBuiltinHelpRow); - // The short call guide disambiguates the three related commands. - try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("Callstack: static caller chains,", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("with signatures and clickable call sites.", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("Callers / Callees: one direction at a time.", lines.next() orelse return error.MissingCallHelp); + for (pardes.builtin_rows) |row| if (builtins.registry.here(core, row.cmd)) { + try std.testing.expectEqualStrings(row.line, lines.next() orelse return error.MissingBuiltinHelpRow); + // A line a paragraph, then a blank line. + var paragraphs = std.mem.splitScalar(u8, builtins.registry.doc(row.cmd).text, '\n'); + while (paragraphs.next()) |paragraph| try std.testing.expectEqualStrings(paragraph, lines.next() orelse return error.MissingDocumentation); + try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingBlank); + }; // The language keys close the page. - try std.testing.expectEqualStrings("", lines.next() orelse - return error.MissingLanguageKeys); try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse return error.MissingLanguageKeys); try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null); - // The language group also explains call commands, without the motion footer. + // The language group: its words' documentation, without the motion footer. const group = try helpContent(core, std.testing.allocator, "l"); defer std.testing.allocator.free(group); try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null); - try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null); + try std.testing.expect(std.mem.indexOf(u8, group, builtins.registry.doc(.Callstack).text) != null); } |
