feat: add config option enable_terminal_color_scheme

This option defaults to off on windows because windows does not support
resetting the terminal colors on exit.

closes #26
This commit is contained in:
CJ van den Berg 2024-08-21 22:07:36 +02:00
parent 08e06bc8dd
commit c627a49518
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,5 @@
const builtin = @import("builtin");
frame_rate: usize = 60,
theme: []const u8 = "default",
input_mode: []const u8 = "flow",
@ -11,6 +13,7 @@ vim_normal_gutter_line_numbers_relative: bool = true,
vim_visual_gutter_line_numbers_relative: bool = true,
vim_insert_gutter_line_numbers_relative: bool = false,
enable_terminal_cursor: bool = false,
enable_terminal_color_scheme: bool = builtin.os.tag != .windows,
highlight_current_line: bool = true,
highlight_current_line_gutter: bool = true,
show_whitespace: bool = false,

View file

@ -137,7 +137,7 @@ fn init(a: Allocator) !*Self {
}
self.mainview = try mainview.create(a);
self.resize();
self.rdr.set_terminal_style(self.theme.editor);
self.set_terminal_style();
try self.rdr.render();
try self.save_config();
if (tp.env.get().is("restore-session")) {
@ -569,7 +569,7 @@ const cmds = struct {
return;
};
self.config.theme = self.theme.name;
self.rdr.set_terminal_style(self.theme.editor);
self.set_terminal_style();
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
@ -577,7 +577,7 @@ const cmds = struct {
pub fn theme_next(self: *Self, _: Ctx) Result {
self.theme = get_next_theme_by_name(self.theme.name);
self.config.theme = self.theme.name;
self.rdr.set_terminal_style(self.theme.editor);
self.set_terminal_style();
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
@ -585,7 +585,7 @@ const cmds = struct {
pub fn theme_prev(self: *Self, _: Ctx) Result {
self.theme = get_prev_theme_by_name(self.theme.name);
self.config.theme = self.theme.name;
self.rdr.set_terminal_style(self.theme.editor);
self.set_terminal_style();
self.logger.print("theme: {s}", .{self.theme.description});
try self.save_config();
}
@ -859,3 +859,8 @@ pub const fallbacks: []const FallBack = &[_]FallBack{
.{ .ts = "repeat", .tm = "keyword.control.flow" },
.{ .ts = "field", .tm = "variable" },
};
fn set_terminal_style(self: *Self) void {
if (self.config.enable_terminal_color_scheme)
self.rdr.set_terminal_style(self.theme.editor);
}