From 8107a0d2b8cbb6e9002e64c08ac8d1de6829b45f Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 13 Aug 2025 19:19:45 +0200 Subject: [PATCH] feat: display command hints in task_palette --- src/tui/mode/overlay/task_palette.zig | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/tui/mode/overlay/task_palette.zig b/src/tui/mode/overlay/task_palette.zig index d7d0821..0a91870 100644 --- a/src/tui/mode/overlay/task_palette.zig +++ b/src/tui/mode/overlay/task_palette.zig @@ -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 {};