Use keybind actions help strings in +list-keybinds.

This commit is contained in:
Jeffrey C. Ollie
2024-01-21 19:48:48 -06:00
parent cab28c3940
commit f41f70c977

View File

@ -1,17 +1,20 @@
const std = @import("std"); const std = @import("std");
const inputpkg = @import("../input.zig");
const args = @import("args.zig"); const args = @import("args.zig");
const Action = @import("action.zig").Action; const Action = @import("action.zig").Action;
const KeybindAction = @import("../input/Binding.zig").Action;
const Arena = std.heap.ArenaAllocator; const Arena = std.heap.ArenaAllocator;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const configpkg = @import("../config.zig"); const configpkg = @import("../config.zig");
const Config = configpkg.Config; const Config = configpkg.Config;
const help_strings = @import("help_strings");
pub const Options = struct { pub const Options = struct {
/// If true, print out the default keybinds instead of the ones /// If true, print out the default keybinds instead of the ones
/// configured in the config file. /// configured in the config file.
default: bool = false, default: bool = false,
docs: bool = false,
pub fn deinit(self: Options) void { pub fn deinit(self: Options) void {
_ = self; _ = self;
} }
@ -47,6 +50,24 @@ pub fn run(alloc: Allocator) !u8 {
defer config.deinit(); defer config.deinit();
const stdout = std.io.getStdOut().writer(); 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)); try config.keybind.formatEntry(configpkg.entryFormatter("keybind", stdout));
return 0; return 0;