From 65bf22af99440a2f4165fa166ab49324e1a63f70 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 21 Jan 2024 19:50:15 -0600 Subject: [PATCH] add keybind actions docs to manpages --- src/build/mdgen/mdgen.zig | 33 +++++++++++++++++++++++++++++++++ src/mdgen_ghostty_5.zig | 1 + 2 files changed, 34 insertions(+) diff --git a/src/build/mdgen/mdgen.zig b/src/build/mdgen/mdgen.zig index ec7eb9b47..d94691441 100644 --- a/src/build/mdgen/mdgen.zig +++ b/src/build/mdgen/mdgen.zig @@ -3,6 +3,7 @@ const help_strings = @import("help_strings"); const build_options = @import("build_options"); const Config = @import("../../config/Config.zig"); const Action = @import("../../cli/action.zig").Action; +const KeybindAction = @import("../../input/Binding.zig").Action; pub fn substitute(alloc: std.mem.Allocator, input: []const u8, writer: anytype) !void { const version_string = try std.fmt.allocPrint(alloc, "{}", .{build_options.version}); @@ -83,3 +84,35 @@ pub fn genActions(writer: anytype) !void { } } } + +pub fn genKeybindActions(writer: anytype) !void { + try writer.writeAll( + \\ + \\# KEYBIND ACTIONS + \\ + \\ + ); + + const info = @typeInfo(KeybindAction); + std.debug.assert(info == .Union); + + inline for (info.Union.fields) |field| { + if (field.name[0] == '_') continue; + + try writer.writeAll("`"); + try writer.writeAll(field.name); + try writer.writeAll("`\n\n"); + + if (@hasDecl(help_strings.KeybindAction, field.name)) { + var iter = std.mem.splitScalar(u8, @field(help_strings.KeybindAction, field.name), '\n'); + var first = true; + while (iter.next()) |s| { + try writer.writeAll(if (first) ": " else " "); + try writer.writeAll(s); + try writer.writeAll("\n"); + first = false; + } + try writer.writeAll("\n\n"); + } + } +} diff --git a/src/mdgen_ghostty_5.zig b/src/mdgen_ghostty_5.zig index e23d4e536..8773b433a 100644 --- a/src/mdgen_ghostty_5.zig +++ b/src/mdgen_ghostty_5.zig @@ -8,5 +8,6 @@ pub fn main() !void { const output = std.io.getStdOut().writer(); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_header.md"), output); try gen.genConfig(output, false); + try gen.genKeybindActions(output); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_footer.md"), output); }