From f67bfab5b7cc21788770e17746275cb2250e286f Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 26 Oct 2024 16:33:59 +0200 Subject: [PATCH] refactor: move mini mode name and remove unused mode description field --- src/keybind/static/goto.zig | 4 ---- src/keybind/static/root.zig | 3 +-- src/tui/mode/input/flow.zig | 1 - src/tui/mode/input/helix/insert.zig | 1 - src/tui/mode/input/helix/normal.zig | 1 - src/tui/mode/input/helix/select.zig | 1 - src/tui/mode/input/home.zig | 1 - src/tui/mode/input/vim/insert.zig | 1 - src/tui/mode/input/vim/normal.zig | 1 - src/tui/mode/input/vim/visual.zig | 1 - src/tui/mode/mini/file_browser.zig | 6 +++--- src/tui/mode/mini/find.zig | 6 +++--- src/tui/mode/mini/find_in_files.zig | 6 +++--- src/tui/mode/mini/goto.zig | 1 + src/tui/mode/mini/move_to_char.zig | 6 +++--- src/tui/mode/overlay/open_recent.zig | 1 - src/tui/mode/overlay/palette.zig | 1 - src/tui/tui.zig | 8 +++++++- 18 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/keybind/static/goto.zig b/src/keybind/static/goto.zig index 044b896..45c0c5c 100644 --- a/src/keybind/static/goto.zig +++ b/src/keybind/static/goto.zig @@ -10,13 +10,9 @@ const fmt = @import("std").fmt; const Mode = @import("root.zig").Mode; -const name = "#goto"; - pub fn create(_: Allocator) error{OutOfMemory}!Mode { return .{ .handler = EventHandler.static(@This()), - .name = name, - .description = name, }; } diff --git a/src/keybind/static/root.zig b/src/keybind/static/root.zig index 4cc22b2..ec03304 100644 --- a/src/keybind/static/root.zig +++ b/src/keybind/static/root.zig @@ -6,8 +6,7 @@ pub const mode = struct { pub const Mode = struct { handler: EventHandler, - name: []const u8, - description: []const u8, + name: []const u8 = "", line_numbers: enum { absolute, relative } = .absolute, keybind_hints: ?*const KeybindHints = null, cursor_shape: renderer.CursorShape = .block, diff --git a/src/tui/mode/input/flow.zig b/src/tui/mode/input/flow.zig index 45cb7fd..f886530 100644 --- a/src/tui/mode/input/flow.zig +++ b/src/tui/mode/input/flow.zig @@ -31,7 +31,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = root.application_name, - .description = "default", .keybind_hints = &hints, }; } diff --git a/src/tui/mode/input/helix/insert.zig b/src/tui/mode/input/helix/insert.zig index d8250d6..990981d 100644 --- a/src/tui/mode/input/helix/insert.zig +++ b/src/tui/mode/input/helix/insert.zig @@ -32,7 +32,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "INS", - .description = "helix", .line_numbers = if (tui.current().config.vim_insert_gutter_line_numbers_relative) .relative else .absolute, .cursor_shape = .beam, }; diff --git a/src/tui/mode/input/helix/normal.zig b/src/tui/mode/input/helix/normal.zig index 39ff407..d7ba850 100644 --- a/src/tui/mode/input/helix/normal.zig +++ b/src/tui/mode/input/helix/normal.zig @@ -33,7 +33,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "NOR", - .description = "helix", .line_numbers = if (tui.current().config.vim_normal_gutter_line_numbers_relative) .relative else .absolute, .keybind_hints = &hints, .cursor_shape = .block, diff --git a/src/tui/mode/input/helix/select.zig b/src/tui/mode/input/helix/select.zig index fc8d052..30d9618 100644 --- a/src/tui/mode/input/helix/select.zig +++ b/src/tui/mode/input/helix/select.zig @@ -33,7 +33,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "SEL", - .description = "helix", .line_numbers = if (tui.current().config.vim_visual_gutter_line_numbers_relative) .relative else .absolute, .keybind_hints = &hints, .cursor_shape = .block, diff --git a/src/tui/mode/input/home.zig b/src/tui/mode/input/home.zig index bacab8d..10d5dff 100644 --- a/src/tui/mode/input/home.zig +++ b/src/tui/mode/input/home.zig @@ -24,7 +24,6 @@ pub fn create(allocator: std.mem.Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = root.application_name, - .description = "home", .keybind_hints = &hints, }; } diff --git a/src/tui/mode/input/vim/insert.zig b/src/tui/mode/input/vim/insert.zig index 14830a6..ab89a6b 100644 --- a/src/tui/mode/input/vim/insert.zig +++ b/src/tui/mode/input/vim/insert.zig @@ -41,7 +41,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "INSERT", - .description = "vim", .line_numbers = if (tui.current().config.vim_insert_gutter_line_numbers_relative) .relative else .absolute, .cursor_shape = .beam, }; diff --git a/src/tui/mode/input/vim/normal.zig b/src/tui/mode/input/vim/normal.zig index fbab0f8..b5a7168 100644 --- a/src/tui/mode/input/vim/normal.zig +++ b/src/tui/mode/input/vim/normal.zig @@ -33,7 +33,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "NORMAL", - .description = "vim", .line_numbers = if (tui.current().config.vim_normal_gutter_line_numbers_relative) .relative else .absolute, .keybind_hints = &hints, .cursor_shape = .block, diff --git a/src/tui/mode/input/vim/visual.zig b/src/tui/mode/input/vim/visual.zig index e03e0cd..306f302 100644 --- a/src/tui/mode/input/vim/visual.zig +++ b/src/tui/mode/input/vim/visual.zig @@ -33,7 +33,6 @@ pub fn create(allocator: Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "VISUAL", - .description = "vim", .line_numbers = if (tui.current().config.vim_visual_gutter_line_numbers_relative) .relative else .absolute, .keybind_hints = &hints, .cursor_shape = .underline, diff --git a/src/tui/mode/mini/file_browser.zig b/src/tui/mode/mini/file_browser.zig index 85037c9..2ea3eea 100644 --- a/src/tui/mode/mini/file_browser.zig +++ b/src/tui/mode/mini/file_browser.zig @@ -50,10 +50,10 @@ pub fn Create(options: type) type { return .{ .{ .handler = EventHandler.to_owned(self), - .name = options.name(self), - .description = options.name(self), }, - .{}, + .{ + .name = options.name(self), + }, }; } diff --git a/src/tui/mode/mini/find.zig b/src/tui/mode/mini/find.zig index a382a47..31b5aac 100644 --- a/src/tui/mode/mini/find.zig +++ b/src/tui/mode/mini/find.zig @@ -45,10 +45,10 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui. return .{ .{ .handler = EventHandler.to_owned(self), - .name = name, - .description = name, }, - .{}, + .{ + .name = name, + }, }; }; return error.NotFound; diff --git a/src/tui/mode/mini/find_in_files.zig b/src/tui/mode/mini/find_in_files.zig index dca629f..9a95fbb 100644 --- a/src/tui/mode/mini/find_in_files.zig +++ b/src/tui/mode/mini/find_in_files.zig @@ -39,10 +39,10 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui. return .{ .{ .handler = EventHandler.to_owned(self), - .name = name, - .description = name, }, - .{}, + .{ + .name = name, + }, }; } return error.NotFound; diff --git a/src/tui/mode/mini/goto.zig b/src/tui/mode/mini/goto.zig index acba191..d98a7ff 100644 --- a/src/tui/mode/mini/goto.zig +++ b/src/tui/mode/mini/goto.zig @@ -36,6 +36,7 @@ pub fn create(allocator: Allocator, _: command.Context) !struct { tui.Mode, tui. try keybind.mode.mini.goto.create(allocator), .{ .event_handler = EventHandler.to_owned(self), + .name = name, }, }; }; diff --git a/src/tui/mode/mini/move_to_char.zig b/src/tui/mode/mini/move_to_char.zig index 7d9e2aa..a84a616 100644 --- a/src/tui/mode/mini/move_to_char.zig +++ b/src/tui/mode/mini/move_to_char.zig @@ -42,10 +42,10 @@ pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tu return .{ .{ .handler = EventHandler.to_owned(self), - .name = self.name(), - .description = self.name(), }, - .{}, + .{ + .name = self.name(), + }, }; } diff --git a/src/tui/mode/overlay/open_recent.zig b/src/tui/mode/overlay/open_recent.zig index 71e410b..21b2fcb 100644 --- a/src/tui/mode/overlay/open_recent.zig +++ b/src/tui/mode/overlay/open_recent.zig @@ -64,7 +64,6 @@ pub fn create(allocator: std.mem.Allocator) !tui.Mode { return .{ .handler = EventHandler.to_owned(self), .name = "󰈞 open recent", - .description = "open recent", }; } diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index f4614ed..6edfb74 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -86,7 +86,6 @@ pub fn Create(options: type) type { return .{ .handler = EventHandler.to_owned(self), .name = options.name, - .description = options.description, }; } diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 91285e2..528b064 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -758,6 +758,7 @@ const cmds = struct { pub const MiniMode = struct { event_handler: ?EventHandler = null, + name: []const u8, text: []const u8 = "", cursor: ?usize = null, }; @@ -776,7 +777,12 @@ fn context_check() void { } pub fn get_mode() []const u8 { - return if (current().input_mode) |m| m.name else "INI"; + return if (current().mini_mode) |m| + m.name + else if (current().input_mode) |m| + m.name + else + "INI"; } pub fn reset_drag_context() void {