Skip to content

Commit 4211061

Browse files
mitchellhliby
authored andcommitted
Revert "Fixed documentation generation in list-actions --docs command (ghostty-org#4974)"
This reverts commit f3d0c7c, reversing changes made to 4b77a1c.
1 parent 882ac3f commit 4211061

File tree

4 files changed

+69
-114
lines changed

4 files changed

+69
-114
lines changed

src/build/webgen/main_actions.zig

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
11
const std = @import("std");
22
const help_strings = @import("help_strings");
3-
const helpgen_actions = @import("../../helpgen_actions.zig");
3+
const KeybindAction = @import("../../input/Binding.zig").Action;
44

55
pub fn main() !void {
66
const output = std.io.getStdOut().writer();
7-
try helpgen_actions.generate(output, .markdown, std.heap.page_allocator);
7+
try genKeybindActions(output);
8+
}
9+
10+
pub fn genKeybindActions(writer: anytype) !void {
11+
// Write the header
12+
try writer.writeAll(
13+
\\---
14+
\\title: Keybinding Action Reference
15+
\\description: Reference of all Ghostty keybinding actions.
16+
\\editOnGithubLink: https://github.com/ghostty-org/ghostty/edit/main/src/input/Binding.zig
17+
\\---
18+
\\
19+
\\This is a reference of all Ghostty keybinding actions.
20+
\\
21+
\\
22+
);
23+
24+
@setEvalBranchQuota(5_000);
25+
26+
var buffer = std.ArrayList(u8).init(std.heap.page_allocator);
27+
defer buffer.deinit();
28+
29+
const fields = @typeInfo(KeybindAction).Union.fields;
30+
inline for (fields) |field| {
31+
if (field.name[0] == '_') continue;
32+
33+
// Write previously stored doc comment below all related actions
34+
if (@hasDecl(help_strings.KeybindAction, field.name)) {
35+
try writer.writeAll(buffer.items);
36+
try writer.writeAll("\n");
37+
38+
buffer.clearRetainingCapacity();
39+
}
40+
41+
// Write the field name.
42+
try writer.writeAll("## `");
43+
try writer.writeAll(field.name);
44+
try writer.writeAll("`\n");
45+
46+
if (@hasDecl(help_strings.KeybindAction, field.name)) {
47+
var iter = std.mem.splitScalar(
48+
u8,
49+
@field(help_strings.KeybindAction, field.name),
50+
'\n',
51+
);
52+
while (iter.next()) |s| {
53+
try buffer.appendSlice(s);
54+
try buffer.appendSlice("\n");
55+
}
56+
}
57+
}
858
}

src/cli/list_actions.zig

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22
const args = @import("args.zig");
33
const Action = @import("action.zig").Action;
44
const Allocator = std.mem.Allocator;
5-
const helpgen_actions = @import("../helpgen_actions.zig");
5+
const help_strings = @import("help_strings");
66

77
pub const Options = struct {
88
/// If `true`, print out documentation about the action associated with the
@@ -38,7 +38,19 @@ pub fn run(alloc: Allocator) !u8 {
3838
}
3939

4040
const stdout = std.io.getStdOut().writer();
41-
try helpgen_actions.generate(stdout, .plaintext, std.heap.page_allocator);
41+
const info = @typeInfo(help_strings.KeybindAction);
42+
inline for (info.Struct.decls) |field| {
43+
try stdout.print("{s}", .{field.name});
44+
if (opts.docs) {
45+
try stdout.print(":\n", .{});
46+
var iter = std.mem.splitScalar(u8, std.mem.trimRight(u8, @field(help_strings.KeybindAction, field.name), &std.ascii.whitespace), '\n');
47+
while (iter.next()) |line| {
48+
try stdout.print(" {s}\n", .{line});
49+
}
50+
} else {
51+
try stdout.print("\n", .{});
52+
}
53+
}
4254

4355
return 0;
4456
}

src/input/Binding.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ pub const Action = union(enum) {
236236
/// Send an `ESC` sequence.
237237
esc: []const u8,
238238

239-
/// Send the given text. Uses Zig string literal syntax. This is currently
240-
/// not validated. If the text is invalid (i.e. contains an invalid escape
241-
/// sequence), the error will currently only show up in logs.
239+
// Send the given text. Uses Zig string literal syntax. This is currently
240+
// not validated. If the text is invalid (i.e. contains an invalid escape
241+
// sequence), the error will currently only show up in logs.
242242
text: []const u8,
243243

244244
/// Send data to the pty depending on whether cursor key mode is enabled

src/input/helpgen_actions.zig

-107
This file was deleted.

0 commit comments

Comments
 (0)