summaryrefslogtreecommitdiff
path: root/src/cli/list_keybinds.zig
diff options
context:
space:
mode:
authorkarei <mail@karei.dev>2024-08-06 22:06:19 +0300
committerTim Culverhouse <tim@timculverhouse.com>2024-08-06 14:16:17 -0500
commit85f19bcd1207b418737dc79c090e6e22d3ca793e (patch)
treeced898b21e409ccca43aec2c1f09e14e0b344b80 /src/cli/list_keybinds.zig
parent8b834c1588bef8de89e0ea3c9b584622daf89af9 (diff)
cli/list-keybinds: align actions at the same column
Diffstat (limited to 'src/cli/list_keybinds.zig')
-rw-r--r--src/cli/list_keybinds.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cli/list_keybinds.zig b/src/cli/list_keybinds.zig
index 79ef62ba1..5492f8622 100644
--- a/src/cli/list_keybinds.zig
+++ b/src/cli/list_keybinds.zig
@@ -123,6 +123,8 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
const alt_style: vaxis.Style = .{ .fg = .{ .index = 3 } };
const shift_style: vaxis.Style = .{ .fg = .{ .index = 4 } };
+ var longest_col: usize = 0;
+
// Print the list
for (bindings.items) |bind| {
win.clear();
@@ -155,6 +157,8 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
// nice alignment no matter what was printed for mods
_ = try win.printSegment(.{ .text = key }, .{ .col_offset = result.col });
+ if (longest_col < result.col) longest_col = result.col;
+
const action = try std.fmt.allocPrint(alloc, "{}", .{bind.action});
// If our action has an argument, we print the argument in a different color
if (std.mem.indexOfScalar(u8, action, ':')) |idx| {
@@ -162,9 +166,9 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
.{ .text = action[0..idx] },
.{ .text = action[idx .. idx + 1], .style = .{ .dim = true } },
.{ .text = action[idx + 1 ..], .style = .{ .fg = .{ .index = 5 } } },
- }, .{ .col_offset = result.col + widest_key + 2 });
+ }, .{ .col_offset = longest_col + widest_key + 2 });
} else {
- _ = try win.printSegment(.{ .text = action }, .{ .col_offset = result.col + widest_key + 2 });
+ _ = try win.printSegment(.{ .text = action }, .{ .col_offset = longest_col + widest_key + 2 });
}
try vx.prettyPrint(writer);
}