diff --git a/src/config.zig b/src/config.zig index 9cbb98c..bb12d9a 100644 --- a/src/config.zig +++ b/src/config.zig @@ -2,7 +2,6 @@ const builtin = @import("builtin"); frame_rate: usize = 60, theme: []const u8 = "default", -light_theme: []const u8 = "default-light", input_mode: []const u8 = "flow", gutter_line_numbers_mode: ?LineNumberMode = null, gutter_line_numbers_style: DigitStyle = .ascii, diff --git a/src/keybind/builtin/helix.json b/src/keybind/builtin/helix.json index fd35500..c9226cd 100644 --- a/src/keybind/builtin/helix.json +++ b/src/keybind/builtin/helix.json @@ -14,7 +14,6 @@ ["ctrl+f", "move_scroll_page_down"], ["ctrl+u", "move_scroll_half_page_up"], ["ctrl+d", "move_scroll_half_page_down"], - ["z z", "scroll_view_center"], ["ctrl+c", "toggle_comment"], ["ctrl+i", "jump_forward"], ["ctrl+o", "jump_back"], @@ -192,7 +191,6 @@ ["u", "undo"], ["y", ["enable_selection"], ["copy_helix"], ["enter_mode", "normal"]], - ["%", "select_all"], ["p", "paste_after"], ["q", "record_macro"], @@ -215,7 +213,7 @@ ["space R", "replace_selections_with_clipboard"], ["space ?", "open_command_palette"], ["space f", "find_file"], - ["space b", "switch_buffers"], + ["space b", "buffer_picker"], ["space j", "jumplist_picker"], ["space s", "symbol_picker"], ["space d", "diagnostics_picker"], @@ -223,7 +221,7 @@ ["space '", "last_picker"], ["space y", "copy"], ["space p", "system_paste_after"], - ["space /", "find_in_files"], + ["space /", "find_in_file"], ["space k", "hover"], ["space r", "rename_symbol"], ["space h", "select_references_to_symbol_under_cursor"], @@ -267,7 +265,6 @@ ["ctrl+f", "select_page_down"], ["ctrl+u", "select_half_page_up"], ["ctrl+d", "select_half_page_down"], - ["z z", "scroll_view_center"], ["ctrl+c", "toggle_comment"], @@ -393,7 +390,6 @@ ["kp_down", "select_down"], ["kp_up", "select_up"], ["kp_right", "select_right"], - ["%", "select_all"], ["t", "extend_till_char"], ["f", "move_to_char", "select_to_char_right_helix"], @@ -501,8 +497,8 @@ ["space R", "replace_selections_with_clipboard"], ["space ?", "open_command_palette"], - ["space f", "find_file"], - ["space b", "switch_buffers"], + ["space f", "file_picker"], + ["space b", "buffer_picker"], ["space j", "jumplist_picker"], ["space s", "symbol_picker"], ["space d", "diagnostics_picker"], @@ -510,7 +506,7 @@ ["space '", "last_picker"], ["space y", "copy"], ["space p", "system_paste_after"], - ["space /", "find_in_files"], + ["space /", "find_in_file"], ["space k", "hover"], ["space r", "rename_symbol"], ["space h", "select_references_to_symbol_under_cursor"], diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 5c583bc..21a7901 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -353,9 +353,7 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void { if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{ "system_clipboard", text })); }, .color_report => {}, - .color_scheme => |scheme| { - if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{ "color_scheme", scheme })); - }, + .color_scheme => {}, .winsize => |ws| { if (!self.vx.state.in_band_resize) { self.vx.state.in_band_resize = true; @@ -391,11 +389,8 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void { self.logger.print("rgb capability detected", .{}); self.vx.caps.rgb = true; }, - .cap_color_scheme_updates => { - self.logger.print("color scheme updates capability detected", .{}); - self.vx.caps.color_scheme_updates = true; - self.vx.subscribeToColorSchemeUpdates(self.tty.writer()) catch return error.TtyWriteError; - }, + .cap_color_scheme_updates => {}, + .cap_multi_cursor => { self.logger.print("multi cursor capability detected", .{}); self.vx.caps.multi_cursor = true; diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index 3eb23d9..cef4cf4 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -45,26 +45,11 @@ const cmds_ = struct { } pub const @"q!_meta": Meta = .{ .description = "q! (quit without saving)" }; - pub fn @"qa!"(_: *void, _: Ctx) Result { - try cmd("quit_without_saving", .{}); - } - pub const @"qa!_meta": Meta = .{ .description = "qa! (quit without saving)" }; - pub fn wq(_: *void, _: Ctx) Result { try cmd("save_file", command.fmt(.{ "then", .{ "quit", .{} } })); } pub const wq_meta: Meta = .{ .description = "wq (write/save file and quit)" }; - pub fn x(_: *void, _: Ctx) Result { - try cmd("save_file", command.fmt(.{ "then", .{ "quit", .{} } })); - } - pub const x_meta: Meta = .{ .description = "x (write/save file and quit)" }; - - pub fn rl(_: *void, _: Ctx) Result { - try cmd("reload_file", .{}); - } - pub const rl_meta: Meta = .{ .description = "rl (force reload current file)" }; - pub fn o(_: *void, _: Ctx) Result { try cmd("open_file", .{}); } @@ -76,26 +61,6 @@ const cmds_ = struct { } pub const @"wq!_meta": Meta = .{ .description = "wq! (write/save file and quit without saving)" }; - pub fn n(_: *void, _: Ctx) Result { - try cmd("create_new_file", .{}); - } - pub const n_meta: Meta = .{ .description = "n (Create new buffer/tab)" }; - - pub fn bn(_: *void, _: Ctx) Result { - try cmd("next_tab", .{}); - } - pub const bn_meta: Meta = .{ .description = "bn (Next buffer/tab)" }; - - pub fn bp(_: *void, _: Ctx) Result { - try cmd("previous_tab", .{}); - } - pub const bp_meta: Meta = .{ .description = "bp (Previous buffer/tab)" }; - - pub fn bc(_: *void, _: Ctx) Result { - try cmd("delete_buffer", .{}); - } - pub const bc_meta: Meta = .{ .description = "bc (Close buffer/tab)" }; - pub fn save_selection(_: *void, _: Ctx) Result { const logger = log.logger("helix-mode"); defer logger.deinit(); diff --git a/src/tui/tui.zig b/src/tui/tui.zig index ecf3d3e..297014f 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -47,10 +47,8 @@ last_hover_y: c_int = -1, commands: Commands = undefined, logger: log.Logger, drag_source: ?*Widget = null, -dark_theme: Widget.Theme, -dark_parsed_theme: ?std.json.Parsed(Widget.Theme), -light_theme: Widget.Theme, -light_parsed_theme: ?std.json.Parsed(Widget.Theme), +theme_: Widget.Theme, +parsed_theme: ?std.json.Parsed(Widget.Theme), idle_frame_count: usize = 0, unrendered_input_events_count: usize = 0, init_timer: ?tp.timeout, @@ -67,7 +65,6 @@ enable_mouse_idle_timer: bool = false, query_cache_: *syntax.QueryCache, frames_rendered_: usize = 0, clipboard: ?[]const u8 = null, -color_scheme: enum { dark, light } = .dark, const keepalive = std.time.us_per_day * 365; // one year const idle_frames = 0; @@ -115,10 +112,8 @@ fn init(allocator: Allocator) InitError!*Self { if (@hasDecl(renderer, "install_crash_handler") and conf.start_debugger_on_crash) renderer.jit_debugger_enabled = true; - const dark_theme, const dark_parsed_theme = get_theme_by_name(allocator, conf.theme) orelse get_theme_by_name(allocator, "dark_modern") orelse return error.UnknownTheme; - conf.theme = dark_theme.name; - const light_theme, const light_parsed_theme = get_theme_by_name(allocator, conf.light_theme) orelse get_theme_by_name(allocator, "default-light") orelse return error.UnknownTheme; - conf.light_theme = light_theme.name; + const theme_, const parsed_theme = get_theme_by_name(allocator, conf.theme) orelse get_theme_by_name(allocator, "dark_modern") orelse return error.UnknownTheme; + conf.theme = theme_.name; if (build_options.gui) conf.enable_terminal_cursor = false; const frame_rate: usize = @intCast(tp.env.get().num("frame-rate")); @@ -151,12 +146,10 @@ fn init(allocator: Allocator) InitError!*Self { .init_timer = if (build_options.gui) null else try tp.timeout.init_ms(init_delay, tp.message.fmt( .{"init"}, )), + .theme_ = theme_, .no_sleep = tp.env.get().is("no-sleep"), .query_cache_ = try syntax.QueryCache.create(allocator, .{}), - .dark_theme = dark_theme, - .light_theme = light_theme, - .dark_parsed_theme = dark_parsed_theme, - .light_parsed_theme = light_parsed_theme, + .parsed_theme = parsed_theme, }; instance_ = self; defer instance_ = null; @@ -457,16 +450,6 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void { return; } - if (try m.match(.{ "color_scheme", "dark" })) { - self.color_scheme = .dark; - return; - } - - if (try m.match(.{ "color_scheme", "light" })) { - self.color_scheme = .light; - return; - } - return tp.unexpected(m); } @@ -494,7 +477,7 @@ fn render(self: *Self) void { const frame = tracy.initZone(@src(), .{ .name = "tui render" }); defer frame.deinit(); self.rdr_.stdplane().erase(); - break :ret if (self.mainview_) |mv| mv.render(self.current_theme()) else false; + break :ret if (self.mainview_) |mv| mv.render(&self.theme_) else false; }; { @@ -753,46 +736,23 @@ fn refresh_input_mode(self: *Self) command.Result { } fn set_theme_by_name(self: *Self, name: []const u8, action: enum { none, store }) !void { - const old = switch (self.color_scheme) { - .dark => self.dark_parsed_theme, - .light => self.light_parsed_theme, - }; + const old = self.parsed_theme; defer if (old) |p| p.deinit(); - const theme_, const parsed_theme = get_theme_by_name(self.allocator, name) orelse { + self.theme_, self.parsed_theme = get_theme_by_name(self.allocator, name) orelse { self.logger.print("theme not found: {s}", .{name}); return; }; - switch (self.color_scheme) { - .dark => { - self.dark_theme = theme_; - self.dark_parsed_theme = parsed_theme; - }, - .light => { - self.light_theme = theme_; - self.light_parsed_theme = parsed_theme; - }, - } self.set_terminal_style(); - self.logger.print("theme: {s}", .{theme_.description}); + self.logger.print("theme: {s}", .{self.theme_.description}); switch (action) { .none => {}, .store => { - switch (self.color_scheme) { - .dark => self.config_.theme = self.dark_theme.name, - .light => self.config_.light_theme = self.light_theme.name, - } + self.config_.theme = self.theme_.name; try save_config(); }, } } -fn current_theme(self: *const Self) *const Widget.Theme { - return switch (self.color_scheme) { - .dark => &self.dark_theme, - .light => &self.light_theme, - }; -} - const cmds = struct { pub const Target = Self; const Ctx = command.Context; @@ -866,13 +826,13 @@ const cmds = struct { pub const set_theme_meta: Meta = .{ .arguments = &.{.string} }; pub fn theme_next(self: *Self, _: Ctx) Result { - const name = get_next_theme_by_name(self.current_theme().name); + const name = get_next_theme_by_name(self.theme_.name); return self.set_theme_by_name(name, .store); } pub const theme_next_meta: Meta = .{ .description = "Next color theme" }; pub fn theme_prev(self: *Self, _: Ctx) Result { - const name = get_prev_theme_by_name(self.current_theme().name); + const name = get_prev_theme_by_name(self.theme_.name); return self.set_theme_by_name(name, .store); } pub const theme_prev_meta: Meta = .{ .description = "Previous color theme" }; @@ -1384,7 +1344,7 @@ pub fn fontfaces(allocator: std.mem.Allocator) error{OutOfMemory}![][]const u8 { } pub fn theme() *const Widget.Theme { - return current().current_theme(); + return ¤t().theme_; } pub fn get_theme_by_name(allocator: std.mem.Allocator, name: []const u8) ?struct { Widget.Theme, ?std.json.Parsed(Widget.Theme) } { @@ -1508,10 +1468,10 @@ pub const fallbacks: []const FallBack = &[_]FallBack{ fn set_terminal_style(self: *Self) void { if (build_options.gui or self.config_.enable_terminal_color_scheme) { - self.rdr_.set_terminal_style(self.current_theme().editor); - self.rdr_.set_terminal_cursor_color(self.current_theme().editor_cursor.bg.?); + self.rdr_.set_terminal_style(self.theme_.editor); + self.rdr_.set_terminal_cursor_color(self.theme_.editor_cursor.bg.?); if (self.rdr_.vx.caps.multi_cursor) - self.rdr_.set_terminal_secondary_cursor_color(self.current_theme().editor_cursor_secondary.bg orelse self.current_theme().editor_cursor.bg.?); + self.rdr_.set_terminal_secondary_cursor_color(self.theme_.editor_cursor_secondary.bg orelse self.theme_.editor_cursor.bg.?); } } @@ -1648,14 +1608,14 @@ pub fn render_file_item_cbor(self: *renderer.Plane, file_item_cbor: []const u8, } fn get_or_create_theme_file(self: *Self, allocator: std.mem.Allocator) ![]const u8 { - const theme_name = self.current_theme().name; + const theme_name = self.theme_.name; if (root.read_theme(allocator, theme_name)) |content| { allocator.free(content); } else { var buf: std.Io.Writer.Allocating = .init(self.allocator); defer buf.deinit(); var s: std.json.Stringify = .{ .writer = &buf.writer, .options = .{ .whitespace = .indent_2 } }; - try s.write(self.current_theme().*); + try s.write(self.theme_); try root.write_theme( theme_name, buf.written(),