diff --git a/src/tui/mode/input/flow.zig b/src/keybind/static/input/flow.zig similarity index 96% rename from src/tui/mode/input/flow.zig rename to src/keybind/static/input/flow.zig index ee32dc2..6dc9ec5 100644 --- a/src/tui/mode/input/flow.zig +++ b/src/keybind/static/input/flow.zig @@ -1,38 +1,28 @@ +const std = @import("std"); const tp = @import("thespian"); -const root = @import("root"); - const key = @import("renderer").input.key; const mod = @import("renderer").input.modifier; const event_type = @import("renderer").input.event_type; const ucs32_to_utf8 = @import("renderer").ucs32_to_utf8; const command = @import("command"); const EventHandler = @import("EventHandler"); - -const tui = @import("../../tui.zig"); - -const Allocator = @import("std").mem.Allocator; -const ArrayList = @import("std").ArrayList; -const eql = @import("std").mem.eql; +const keybind = @import("../keybind.zig"); const Self = @This(); const input_buffer_size = 1024; -allocator: Allocator, -input: ArrayList(u8), +allocator: std.mem.Allocator, +input: std.ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, -pub fn create(allocator: Allocator) !tui.Mode { +pub fn create(allocator: std.mem.Allocator) !EventHandler { const self: *Self = try allocator.create(Self); self.* = .{ .allocator = allocator, - .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), - }; - return .{ - .input_handler = EventHandler.to_owned(self), - .name = root.application_name, - .keybind_hints = &hints, + .input = try std.ArrayList(u8).initCapacity(allocator, input_buffer_size), }; + return EventHandler.to_owned(self); } pub fn deinit(self: *Self) void { @@ -304,9 +294,9 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result { } fn cmd_cycle3(self: *Self, name1: []const u8, name2: []const u8, name3: []const u8, ctx: command.Context) tp.result { - return if (eql(u8, self.last_cmd, name2)) + return if (std.mem.eql(u8, self.last_cmd, name2)) self.cmd(name3, ctx) - else if (eql(u8, self.last_cmd, name1)) + else if (std.mem.eql(u8, self.last_cmd, name1)) self.cmd(name2, ctx) else self.cmd(name1, ctx); @@ -317,7 +307,7 @@ fn cmd_async(self: *Self, name_: []const u8) tp.result { return tp.self_pid().send(.{ "cmd", name_ }); } -const hints = tui.KeybindHints.initComptime(.{ +pub const hints = keybind.KeybindHints.initComptime(.{ .{ "add_cursor_all_matches", "C-S-l" }, .{ "add_cursor_down", "S-A-down" }, .{ "add_cursor_next_match", "C-d" }, diff --git a/src/keybind/static/keybind.zig b/src/keybind/static/keybind.zig index 2d159bc..77a0855 100644 --- a/src/keybind/static/keybind.zig +++ b/src/keybind/static/keybind.zig @@ -1,5 +1,6 @@ pub const mode = struct { pub const input = struct { + pub const flow = @import("input/flow.zig"); pub const home = @import("input/home.zig"); }; pub const overlay = struct { diff --git a/src/tui/tui.zig b/src/tui/tui.zig index a9adfb0..307a615 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -668,12 +668,12 @@ const cmds = struct { else if (std.mem.eql(u8, mode, "helix/select")) try @import("mode/input/helix/select.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "flow")) - try @import("mode/input/flow.zig").create(self.allocator) + try self.static_mode(keybind.mode.input.flow, "flow") else if (std.mem.eql(u8, mode, "home")) 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); + break :ret try self.static_mode(keybind.mode.input.flow, "flow"); }; // self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description}); }