diff --git a/src/tui/mode/input/home.zig b/src/keybind/static/input/home.zig similarity index 94% rename from src/tui/mode/input/home.zig rename to src/keybind/static/input/home.zig index c68a355..f6840b2 100644 --- a/src/tui/mode/input/home.zig +++ b/src/keybind/static/input/home.zig @@ -1,14 +1,11 @@ const std = @import("std"); const tp = @import("thespian"); -const root = @import("root"); - const key = @import("renderer").input.key; const event_type = @import("renderer").input.event_type; const mod = @import("renderer").input.modifier; const command = @import("command"); const EventHandler = @import("EventHandler"); - -const tui = @import("../../tui.zig"); +const keybind = @import("../root.zig"); const Self = @This(); @@ -16,16 +13,12 @@ allocator: std.mem.Allocator, f: usize = 0, leader: ?struct { keypress: u32, modifiers: u32 } = null, -pub fn create(allocator: std.mem.Allocator) !tui.Mode { +pub fn create(allocator: std.mem.Allocator) !EventHandler { const self: *Self = try allocator.create(Self); self.* = .{ .allocator = allocator, }; - return .{ - .input_handler = EventHandler.to_owned(self), - .name = root.application_name, - .keybind_hints = &hints, - }; + return EventHandler.to_owned(self); } pub fn deinit(self: *Self) void { @@ -155,7 +148,7 @@ fn sheeran(self: *Self) void { } } -const hints = tui.KeybindHints.initComptime(.{ +pub const hints = keybind.KeybindHints.initComptime(.{ .{ "find_in_files", "C-S-f" }, .{ "open_file", "o, C-o" }, .{ "open_recent", "e, C-e" }, diff --git a/src/keybind/static/root.zig b/src/keybind/static/root.zig index 3daa26e..2d159bc 100644 --- a/src/keybind/static/root.zig +++ b/src/keybind/static/root.zig @@ -1,4 +1,7 @@ pub const mode = struct { + pub const input = struct { + pub const home = @import("input/home.zig"); + }; pub const overlay = struct { pub const palette = @import("overlay/palette.zig"); }; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index b4f1b19..a9adfb0 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -561,6 +561,14 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result { self.refresh_hover(); } +fn static_mode(self: *Self, mode: anytype, name: []const u8) !Mode { + return .{ + .input_handler = try mode.create(self.allocator), + .name = name, + .keybind_hints = &mode.hints, + }; +} + const cmds = struct { pub const Target = Self; const Ctx = command.Context; @@ -662,7 +670,7 @@ const cmds = struct { else if (std.mem.eql(u8, mode, "flow")) try @import("mode/input/flow.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "home")) - try @import("mode/input/home.zig").create(self.allocator) + try self.static_mode(keybind.mode.input.home, "home") else ret: { self.logger.print("unknown mode {s}", .{mode}); break :ret try @import("mode/input/flow.zig").create(self.allocator);