From f41f70c977d50ae18e84e1641d7f52dc5ee912a4 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 21 Jan 2024 19:48:48 -0600 Subject: [PATCH] Use keybind actions help strings in +list-keybinds. --- src/cli/list_keybinds.zig | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/cli/list_keybinds.zig b/src/cli/list_keybinds.zig index ef80d6442..a17f23504 100644 --- a/src/cli/list_keybinds.zig +++ b/src/cli/list_keybinds.zig @@ -1,17 +1,20 @@ const std = @import("std"); -const inputpkg = @import("../input.zig"); const args = @import("args.zig"); const Action = @import("action.zig").Action; +const KeybindAction = @import("../input/Binding.zig").Action; const Arena = std.heap.ArenaAllocator; const Allocator = std.mem.Allocator; const configpkg = @import("../config.zig"); const Config = configpkg.Config; +const help_strings = @import("help_strings"); pub const Options = struct { /// If true, print out the default keybinds instead of the ones /// configured in the config file. default: bool = false, + docs: bool = false, + pub fn deinit(self: Options) void { _ = self; } @@ -47,6 +50,24 @@ pub fn run(alloc: Allocator) !u8 { defer config.deinit(); const stdout = std.io.getStdOut().writer(); + if (opts.docs) { + const info = @typeInfo(KeybindAction); + var first = true; + inline for (info.Union.fields) |field| { + if (field.name[0] == '_') continue; + if (@hasDecl(help_strings.KeybindAction, field.name)) { + if (!first) try stdout.print("#\n", .{}); + try stdout.print("# {s}\n", .{field.name}); + const help = @field(help_strings.KeybindAction, field.name); + var lines = std.mem.splitScalar(u8, help, '\n'); + while (lines.next()) |line| { + try stdout.print("# {s}\n", .{line}); + } + first = false; + } + } + } + try config.keybind.formatEntry(configpkg.entryFormatter("keybind", stdout)); return 0;