summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 11:00:44 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit80314064f6e81c8828340e010202b446f0e1f36d (patch)
treeaa56e86238ac9397055f601db924868bb6511538 /src/Output.zig
parenta53a1aafb9804e943bdcd720c2bb688ecb90a888 (diff)
downloadpardes-80314064f6e81c8828340e010202b446f0e1f36d.tar.gz
pardes-80314064f6e81c8828340e010202b446f0e1f36d.zip
Audit (misc): std mkdir -p and JSON escaping, a 9P late failure's errno from ctl.failureErrno, dead switches and dumpHex out
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig52
1 files changed, 12 insertions, 40 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 3fc08d9a..9a11b2fc 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -949,51 +949,23 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
"C-left-click definition, by mouse\n" ++
"SPC l ... hover, rename, symbols,\n" ++
" calls, types: above\n";
- var len: usize = if (prefix.len == 0)
- full_header.len + language_footer.len
- else
- group_header.len + prefix.len * 2 + 2;
- if (show_calls_help) len += calls_help.len;
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ errdefer out.deinit();
+ const w = &out.writer;
+ if (prefix.len == 0) try w.writeAll(full_header) else {
+ try w.writeAll(group_header);
+ for (prefix) |c| try w.print(" {c}", .{c});
+ try w.writeAll("\n\n");
+ }
for (pardes.builtin_rows) |row| {
// a path-less builtin filters as the empty path: in the full listing
// (which starts with nothing) and out of every group
if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue;
- len += row.line.len + 1;
- }
- const content = try gpa.alloc(u8, len);
- var at: usize = 0;
- if (prefix.len == 0) {
- @memcpy(content[0..full_header.len], full_header);
- at = full_header.len;
- } else {
- @memcpy(content[0..group_header.len], group_header);
- at = group_header.len;
- for (prefix) |c| {
- content[at] = ' ';
- content[at + 1] = c;
- at += 2;
- }
- content[at] = '\n';
- content[at + 1] = '\n';
- at += 2;
- }
- for (pardes.builtin_rows) |row| {
- if (!std.mem.startsWith(u8, row.path orelse "", prefix)) continue;
- @memcpy(content[at..][0..row.line.len], row.line);
- at += row.line.len;
- content[at] = '\n';
- at += 1;
- }
- if (show_calls_help) {
- @memcpy(content[at..][0..calls_help.len], calls_help);
- at += calls_help.len;
- }
- if (prefix.len == 0) {
- @memcpy(content[at..][0..language_footer.len], language_footer);
- at += language_footer.len;
+ try w.print("{s}\n", .{row.line});
}
- std.debug.assert(at == content.len);
- return content;
+ if (show_calls_help) try w.writeAll(calls_help);
+ if (prefix.len == 0) try w.writeAll(language_footer);
+ return out.toOwnedSlice();
}
pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void {