From 17b3f152d5c24a834ac17b0e70992a6f3077d0dc Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 13 Aug 2025 22:33:17 +0200 Subject: [PATCH] feat: add style switching command (alt+f9) to home screen --- src/keybind/builtin/flow.json | 1 + src/tui/home.zig | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index cf0a20e..cbecedd 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -254,6 +254,7 @@ "inherit": "project", "on_match_failure": "ignore", "press": [ + ["alt+f9", "home_next_widget_style"], ["ctrl+e", "find_file"], ["f", "find_file"], ["e", "find_file"], diff --git a/src/tui/home.zig b/src/tui/home.zig index 6fd3c3d..1c45c00 100644 --- a/src/tui/home.zig +++ b/src/tui/home.zig @@ -70,6 +70,8 @@ fire: ?Fire = null, commands: Commands = undefined, menu: *Menu.State(*Self), menu_w: usize = 0, +menu_label_max: usize = 0, +menu_count: usize = 0, menu_len: usize = 0, max_desc_len: usize = 0, input_namespace: []const u8, @@ -109,7 +111,6 @@ pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget { try self.commands.init(self); var it = std.mem.splitAny(u8, self.home_style.menu_commands, "\n "); while (it.next()) |command_name| { - self.menu_len += 1; const id = command.get_id(command_name) orelse { logger.print("{s} is not defined", .{command_name}); continue; @@ -118,13 +119,14 @@ pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget { logger.print("{s} has no description", .{command_name}); continue; }; + self.menu_count += 1; var hints = std.mem.splitScalar(u8, keybind_mode.keybind_hints.get(command_name) orelse "", ','); const hint = hints.first(); self.max_desc_len = @max(self.max_desc_len, description.len + hint.len + 5); try self.add_menu_command(command_name, description, hint, self.menu); } const padding = Widget.Style.from_type(widget_style_type).padding; - self.menu_len += padding.top + padding.bottom; + self.menu_len = self.menu_count + padding.top + padding.bottom; self.position_menu(15, 9); return w; } @@ -154,7 +156,8 @@ fn add_menu_command(self: *Self, command_name: []const u8, description: []const try writer.print(" :{s}", .{hint}); const label = fis.getWritten(); const padding = Widget.Style.from_type(widget_style_type).padding; - self.menu_w = @max(self.menu_w, label.len + 2 + padding.left + padding.right); + self.menu_label_max = @max(self.menu_label_max, label.len); + self.menu_w = self.menu_label_max + 2 + padding.left + padding.right; } var value = std.ArrayList(u8).init(self.allocator); @@ -397,6 +400,15 @@ const cmds = struct { } pub const home_menu_activate_meta: Meta = .{}; + pub fn home_next_widget_style(self: *Self, _: Ctx) Result { + Widget.Style.set_next_style(widget_style_type); + const padding = Widget.Style.from_type(widget_style_type).padding; + self.menu_len = self.menu_count + padding.top + padding.bottom; + self.menu_w = self.menu_label_max + 2 + padding.left + padding.right; + tui.need_render(); + } + pub const home_next_widget_style_meta: Meta = .{}; + pub fn home_sheeran(self: *Self, _: Ctx) Result { self.fire = if (self.fire) |*fire| ret: { fire.deinit();