feat: display command hints in task_palette

This commit is contained in:
CJ van den Berg 2025-08-13 19:19:45 +02:00
parent cef495cb53
commit 8107a0d2b8
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -60,7 +60,7 @@ pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !v
palette.items += 1;
}
pub fn on_render_menu(_: *Type, button: *Type.ButtonState, theme: *const Widget.Theme, selected: bool) bool {
pub fn on_render_menu(palette: *Type, button: *Type.ButtonState, theme: *const Widget.Theme, selected: bool) bool {
var entry: Entry = undefined;
var iter = button.opts.label; // label contains cbor entry object and matches
if (!(cbor.matchValue(&iter, cbor.extract(&entry)) catch false))
@ -84,10 +84,30 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonState, theme: *const Widget.
button.plane.set_style(style_label);
button.plane.fill(" ");
button.plane.home();
button.plane.set_style(style_hint);
tui.render_pointer(&button.plane, selected);
button.plane.set_style(style_label);
_ = button.plane.print("{s} ", .{entry.label}) catch {};
if (entry.command) |command_name| blk: {
button.plane.set_style(style_hint);
var label_: std.ArrayListUnmanaged(u8) = .empty;
defer label_.deinit(palette.allocator);
const id = command.get_id(command_name) orelse break :blk;
if (command.get_icon(id)) |icon|
label_.writer(palette.allocator).print("{s} ", .{icon}) catch {};
if (command.get_description(id)) |desc|
label_.writer(palette.allocator).print("{s}", .{desc}) catch {};
_ = button.plane.print("{s} ", .{label_.items}) catch {};
const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints");
if (hints.get(command_name)) |hint|
_ = button.plane.print_aligned_right(0, "{s} ", .{hint}) catch {};
} else {
_ = button.plane.print("{s} ", .{entry.label}) catch {};
}
var index: usize = 0;
var len = cbor.decodeArrayHeader(&iter) catch return false;
while (len > 0) : (len -= 1) {
@ -102,9 +122,9 @@ fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
var entry: Entry = undefined;
var iter = button.opts.label;
if (!(cbor.matchValue(&iter, cbor.extract(&entry)) catch false)) return;
if (entry.command) |cmd| {
if (entry.command) |command_name| {
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", cmd, .{} }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", command_name, .{} }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
} else {
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
project_manager.add_task(entry.label) catch {};