diff --git a/src/config.zig b/src/config.zig index 9f0425c..af5da11 100644 --- a/src/config.zig +++ b/src/config.zig @@ -10,8 +10,8 @@ enable_terminal_cursor: bool = true, enable_terminal_color_scheme: bool = builtin.os.tag != .windows, highlight_current_line: bool = true, highlight_current_line_gutter: bool = true, -highlight_columns: []const u8 = "", -highlight_columns_alpha: u8 = 224, +highlight_columns: []const u8 = "80 100 120", +highlight_columns_alpha: u8 = 240, whitespace_mode: []const u8 = "none", inline_diagnostics: bool = true, animation_min_lag: usize = 0, //milliseconds diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ceb6c1d..f1ff62b 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -1137,7 +1137,11 @@ pub const Editor = struct { defer frame.deinit(); const hl_cols: []const u16 = tui.highlight_columns(); const alpha: u8 = tui.config().highlight_columns_alpha; - for (hl_cols) |hl_col| { + const offset = self.view.col; + for (hl_cols) |hl_col_| { + if (hl_col_ < offset) continue; + const hl_col = hl_col_ - offset; + if (hl_col > self.view.cols) continue; for (0..self.view.rows) |row| for (0..self.view.cols) |col| if (hl_col > 0 and hl_col <= col) { self.plane.cursor_move_yx(@intCast(row), @intCast(col)) catch return; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 26324f7..f42401d 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -23,7 +23,7 @@ const Allocator = std.mem.Allocator; allocator: Allocator, rdr_: renderer, config_: @import("config"), -highlight_columns_: [3]u16, +highlight_columns_: []u16, frame_time: usize, // in microseconds frame_clock: tp.metronome, frame_clock_running: bool = false, @@ -120,11 +120,19 @@ fn init(allocator: Allocator) InitError!*Self { const frame_time = std.time.us_per_s / conf.frame_rate; const frame_clock = try tp.metronome.init(frame_time); + const hl_cols: usize = blk: { + var it = std.mem.splitScalar(u8, conf.highlight_columns, ' '); + var idx: usize = 0; + while (it.next()) |_| + idx += 1; + break :blk idx; + }; + var self = try allocator.create(Self); self.* = .{ .allocator = allocator, .config_ = conf, - .highlight_columns_ = @splat(0), + .highlight_columns_ = try allocator.alloc(u16, hl_cols), .rdr_ = try renderer.init(allocator, self, tp.env.get().is("no-alternate"), dispatch_initialized), .frame_time = frame_time, .frame_clock = frame_clock, @@ -144,14 +152,11 @@ fn init(allocator: Allocator) InitError!*Self { instance_ = self; defer instance_ = null; - if (conf.highlight_columns.len > 0) { - var it = std.mem.splitScalar(u8, conf.highlight_columns, ' '); - var idx: usize = 0; - while (it.next()) |arg| { - if (idx >= self.highlight_columns_.len) break; - self.highlight_columns_[idx] = std.fmt.parseInt(u16, arg, 10) catch 0; - idx += 1; - } + var it = std.mem.splitScalar(u8, conf.highlight_columns, ' '); + var idx: usize = 0; + while (it.next()) |arg| { + self.highlight_columns_[idx] = std.fmt.parseInt(u16, arg, 10) catch 0; + idx += 1; } self.default_cursor = std.meta.stringToEnum(keybind.CursorShape, conf.default_cursor) orelse .default; @@ -1104,7 +1109,7 @@ pub fn config() *const @import("config") { } pub fn highlight_columns() []const u16 { - return ¤t().highlight_columns_; + return current().highlight_columns_; } pub fn config_mut() *@import("config") {