From e73d3db497d66b17155c5fedfb62e0aa281bc7e2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Nov 2023 17:51:34 -0700 Subject: [PATCH] cli/list-keybindings: stylistic changes --- src/cli/list_keybinds.zig | 55 ++++++++++++++------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/cli/list_keybinds.zig b/src/cli/list_keybinds.zig index 1ce0d317c..8d9585be9 100644 --- a/src/cli/list_keybinds.zig +++ b/src/cli/list_keybinds.zig @@ -6,57 +6,40 @@ const Allocator = std.mem.Allocator; const Config = @import("../config/Config.zig"); pub const Options = struct { - _arena: ?Arena = null, + /// If true, print out the default keybinds instead of the ones + /// configured in the config file. default: bool = false, - pub fn deinit(self: *Options) void { - if (self._arena) |arena| arena.deinit(); - self.* = undefined; + pub fn deinit(self: Options) void { + _ = self; } }; -/// The "list-keybinds" command is used to list all the available keybinds for Ghostty. +/// The "list-keybinds" command is used to list all the available keybinds +/// for Ghostty. /// -/// When executed without any arguments this will list the current keybinds loaded by the config file. -/// If no config file is found or there aren't any changes to the keybinds it will print out the default ones configured for Ghostty +/// When executed without any arguments this will list the current keybinds +/// loaded by the config file. If no config file is found or there aren't any +/// changes to the keybinds it will print out the default ones configured for +/// Ghostty /// -/// The "--default" argument will print out all the default keybinds configured for Ghostty +/// The "--default" argument will print out all the default keybinds +/// configured for Ghostty 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); - - if (opts.default) { - return try listDefaultKeybinds(alloc); + { + var iter = try std.process.argsWithAllocator(alloc); + defer iter.deinit(); + try args.parse(Options, alloc, &opts, &iter); } - return try listKeybinds(alloc); -} - -fn listKeybinds(alloc: Allocator) !u8 { - var loaded_config = try Config.load(alloc); - defer loaded_config.deinit(); + var config = if (opts.default) try Config.default(alloc) else try Config.load(alloc); + defer config.deinit(); const stdout = std.io.getStdOut().writer(); - var iter = loaded_config.keybind.set.bindings.iterator(); - - return try iterConfig(&stdout, &iter); -} - -fn listDefaultKeybinds(alloc: Allocator) !u8 { - var default = try Config.default(alloc); - defer default.deinit(); - - const stdout = std.io.getStdOut().writer(); - var iter = default.keybind.set.bindings.iterator(); - - return try iterConfig(&stdout, &iter); -} - -fn iterConfig(stdout: anytype, iter: anytype) !u8 { + var iter = config.keybind.set.bindings.iterator(); while (iter.next()) |next| { const keys = next.key_ptr.*; const value = next.value_ptr.*;