From c5e9913def2d6c5f2015b3cee7276759d1472da1 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Thu, 1 Aug 2024 18:57:37 -0500 Subject: [PATCH 1/2] Add +list-actions CLI action to list keybind actions. --- src/cli/action.zig | 5 ++++ src/cli/list_actions.zig | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/cli/list_actions.zig diff --git a/src/cli/action.zig b/src/cli/action.zig index 68bcf6448..afe46806a 100644 --- a/src/cli/action.zig +++ b/src/cli/action.zig @@ -8,6 +8,7 @@ const version = @import("version.zig"); const list_keybinds = @import("list_keybinds.zig"); const list_themes = @import("list_themes.zig"); const list_colors = @import("list_colors.zig"); +const list_actions = @import("list_actions.zig"); const show_config = @import("show_config.zig"); const validate_config = @import("validate_config.zig"); @@ -33,6 +34,9 @@ pub const Action = enum { /// List named RGB colors @"list-colors", + /// List keybind actions colors + @"list-actions", + /// Dump the config to stdout @"show-config", @@ -127,6 +131,7 @@ pub const Action = enum { .@"list-keybinds" => try list_keybinds.run(alloc), .@"list-themes" => try list_themes.run(alloc), .@"list-colors" => try list_colors.run(alloc), + .@"list-actions" => try list_actions.run(alloc), .@"show-config" => try show_config.run(alloc), .@"validate-config" => try validate_config.run(alloc), }; diff --git a/src/cli/list_actions.zig b/src/cli/list_actions.zig new file mode 100644 index 000000000..09feee6ab --- /dev/null +++ b/src/cli/list_actions.zig @@ -0,0 +1,53 @@ +const std = @import("std"); +const args = @import("args.zig"); +const Action = @import("action.zig").Action; +const Allocator = std.mem.Allocator; +const help_strings = @import("help_strings"); + +pub const Options = struct { + /// If `true`, print out documenation about the action associated with the + /// keybinds. + docs: bool = false, + + pub fn deinit(self: Options) void { + _ = self; + } + + /// Enables `-h` and `--help` to work. + pub fn help(self: Options) !void { + _ = self; + return Action.help_error; + } +}; + +/// The `list-actions` command is used to list all the available keybind actions +/// for Ghostty. +/// +/// The `--docs` argument will print out the documentation for each action. +pub fn run(alloc: Allocator) !u8 { + var opts: Options = .{}; + defer opts.deinit(); + + { + var iter = try std.process.argsWithAllocator(alloc); + defer iter.deinit(); + try args.parse(Options, alloc, &opts, &iter); + } + + const stdout = std.io.getStdOut().writer(); + const info = @typeInfo(help_strings.KeybindAction); + inline for (info.Struct.decls) |field| { + try stdout.print("{s}", .{field.name}); + if (opts.docs) { + try stdout.print(":\n", .{}); + var iter = std.mem.splitScalar(u8, std.mem.trimRight(u8, @field(help_strings.KeybindAction, field.name), &std.ascii.whitespace), '\n'); + while (iter.next()) |line| { + try stdout.print(" {s}\n", .{line}); + } + } else { + try stdout.print("\n", .{}); + } + } + + return 0; +} From c5d03bbbd658e678a4075e0aec73d2e1cc28c262 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 1 Aug 2024 20:12:22 -0700 Subject: [PATCH 2/2] comment --- src/cli/action.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/action.zig b/src/cli/action.zig index afe46806a..8113f991a 100644 --- a/src/cli/action.zig +++ b/src/cli/action.zig @@ -34,7 +34,7 @@ pub const Action = enum { /// List named RGB colors @"list-colors", - /// List keybind actions colors + /// List keybind actions @"list-actions", /// Dump the config to stdout