port +list-keybinds to latest libvaxis

This commit is contained in:
furtidev
2024-11-16 19:39:48 +06:00
parent eb9b7681c7
commit e7b9a2ac95

View File

@ -111,7 +111,7 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
// align things nicely // align things nicely
var iter = keybinds.set.bindings.iterator(); var iter = keybinds.set.bindings.iterator();
var bindings = std.ArrayList(Binding).init(alloc); var bindings = std.ArrayList(Binding).init(alloc);
var widest_key: usize = 0; var widest_key: u16 = 0;
var buf: [64]u8 = undefined; var buf: [64]u8 = undefined;
while (iter.next()) |bind| { while (iter.next()) |bind| {
const action = switch (bind.value_ptr.*) { const action = switch (bind.value_ptr.*) {
@ -134,7 +134,7 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
const alt_style: vaxis.Style = .{ .fg = .{ .index = 3 } }; const alt_style: vaxis.Style = .{ .fg = .{ .index = 3 } };
const shift_style: vaxis.Style = .{ .fg = .{ .index = 4 } }; const shift_style: vaxis.Style = .{ .fg = .{ .index = 4 } };
var longest_col: usize = 0; var longest_col: u16 = 0;
// Print the list // Print the list
for (bindings.items) |bind| { for (bindings.items) |bind| {
@ -143,20 +143,20 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
var result: vaxis.Window.PrintResult = .{ .col = 0, .row = 0, .overflow = false }; var result: vaxis.Window.PrintResult = .{ .col = 0, .row = 0, .overflow = false };
const trigger = bind.trigger; const trigger = bind.trigger;
if (trigger.mods.super) { if (trigger.mods.super) {
result = try win.printSegment(.{ .text = "super", .style = super_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "super", .style = super_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.ctrl) { if (trigger.mods.ctrl) {
result = try win.printSegment(.{ .text = "ctrl ", .style = ctrl_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "ctrl ", .style = ctrl_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.alt) { if (trigger.mods.alt) {
result = try win.printSegment(.{ .text = "alt ", .style = alt_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "alt ", .style = alt_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
if (trigger.mods.shift) { if (trigger.mods.shift) {
result = try win.printSegment(.{ .text = "shift", .style = shift_style }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = "shift", .style = shift_style }, .{ .col_offset = result.col });
result = try win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col }); result = win.printSegment(.{ .text = " + " }, .{ .col_offset = result.col });
} }
const key = switch (trigger.key) { const key = switch (trigger.key) {
@ -166,20 +166,20 @@ fn prettyPrint(alloc: Allocator, keybinds: Config.Keybinds) !u8 {
}; };
// We don't track the key print because we index the action off the *widest* key so we get // We don't track the key print because we index the action off the *widest* key so we get
// nice alignment no matter what was printed for mods // nice alignment no matter what was printed for mods
_ = try win.printSegment(.{ .text = key }, .{ .col_offset = result.col }); _ = win.printSegment(.{ .text = key }, .{ .col_offset = result.col });
if (longest_col < result.col) longest_col = result.col; if (longest_col < result.col) longest_col = result.col;
const action = try std.fmt.allocPrint(alloc, "{}", .{bind.action}); const action = try std.fmt.allocPrint(alloc, "{}", .{bind.action});
// If our action has an argument, we print the argument in a different color // If our action has an argument, we print the argument in a different color
if (std.mem.indexOfScalar(u8, action, ':')) |idx| { if (std.mem.indexOfScalar(u8, action, ':')) |idx| {
_ = try win.print(&.{ _ = win.print(&.{
.{ .text = action[0..idx] }, .{ .text = action[0..idx] },
.{ .text = action[idx .. idx + 1], .style = .{ .dim = true } }, .{ .text = action[idx .. idx + 1], .style = .{ .dim = true } },
.{ .text = action[idx + 1 ..], .style = .{ .fg = .{ .index = 5 } } }, .{ .text = action[idx + 1 ..], .style = .{ .fg = .{ .index = 5 } } },
}, .{ .col_offset = longest_col + widest_key + 2 }); }, .{ .col_offset = longest_col + widest_key + 2 });
} else { } else {
_ = try win.printSegment(.{ .text = action }, .{ .col_offset = longest_col + widest_key + 2 }); _ = win.printSegment(.{ .text = action }, .{ .col_offset = longest_col + widest_key + 2 });
} }
try vx.prettyPrint(writer); try vx.prettyPrint(writer);
} }