From 9b036b1763def62f5f2f0dba5b22d3a3efe9c211 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 20 Aug 2024 09:43:13 -0500 Subject: [PATCH] cli(list-keybinds): format key sequences Implement formatting of key sequences in the list-keybinds command when *not* pretty printing. Pretty printing will come in a separate commit. The print style for that needs some thought, but in the meantime this removes the panic cause by redirecting output of the command. --- src/config/Config.zig | 2 +- src/input/Binding.zig | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 906a762b9..a69371dd9 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -3430,7 +3430,7 @@ pub const Keybinds = struct { []const u8, std.fmt.bufPrint( &buf, - "{}={}", + "{}{}", .{ k, v }, ) catch return error.OutOfMemory, ); diff --git a/src/input/Binding.zig b/src/input/Binding.zig index c0850ec94..2e30741f0 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -800,11 +800,20 @@ pub const Set = struct { _ = opts; switch (self) { - .leader => @panic("TODO"), + .leader => |set| { + // the leader key was already printed. + var iter = set.bindings.iterator(); + while (iter.next()) |binding| { + try writer.print( + ">{s}{s}", + .{ binding.key_ptr.*, binding.value_ptr.* }, + ); + } + }, .action, .action_unconsumed => |action| { // action implements the format - try writer.print("{s}", .{action}); + try writer.print("={s}", .{action}); }, } }