feat: add gutter_width_mode and gutter_width_minimum/maximum config options
This commit is contained in:
parent
0df97f5ad5
commit
9d6fa68c97
2 changed files with 26 additions and 3 deletions
|
|
@ -7,6 +7,9 @@ input_mode: []const u8 = "flow",
|
||||||
gutter_line_numbers_mode: ?LineNumberMode = null,
|
gutter_line_numbers_mode: ?LineNumberMode = null,
|
||||||
gutter_line_numbers_style: DigitStyle = .ascii,
|
gutter_line_numbers_style: DigitStyle = .ascii,
|
||||||
gutter_symbols: bool = true,
|
gutter_symbols: bool = true,
|
||||||
|
gutter_width_mode: GutterWidthMode = .local,
|
||||||
|
gutter_width_minimum: usize = 4,
|
||||||
|
gutter_width_maximum: usize = 8,
|
||||||
enable_terminal_cursor: bool = true,
|
enable_terminal_cursor: bool = true,
|
||||||
enable_terminal_color_scheme: bool = false,
|
enable_terminal_color_scheme: bool = false,
|
||||||
enable_sgr_pixel_mode_support: bool = true,
|
enable_sgr_pixel_mode_support: bool = true,
|
||||||
|
|
@ -115,6 +118,11 @@ pub const LineNumberMode = enum {
|
||||||
absolute,
|
absolute,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const GutterWidthMode = enum {
|
||||||
|
local,
|
||||||
|
global,
|
||||||
|
};
|
||||||
|
|
||||||
pub const IndentMode = enum {
|
pub const IndentMode = enum {
|
||||||
auto,
|
auto,
|
||||||
spaces,
|
spaces,
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ const ed = @import("editor.zig");
|
||||||
const DigitStyle = @import("config").DigitStyle;
|
const DigitStyle = @import("config").DigitStyle;
|
||||||
const LineNumberMode = @import("config").LineNumberMode;
|
const LineNumberMode = @import("config").LineNumberMode;
|
||||||
|
|
||||||
|
var width_global: usize = 0;
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
plane: Plane,
|
plane: Plane,
|
||||||
parent: Widget,
|
parent: Widget,
|
||||||
|
|
@ -34,7 +36,7 @@ line_number_mode: ?LineNumberMode = null,
|
||||||
line_number_style: DigitStyle,
|
line_number_style: DigitStyle,
|
||||||
highlight: bool,
|
highlight: bool,
|
||||||
symbols: bool,
|
symbols: bool,
|
||||||
width: usize = 4,
|
width: usize,
|
||||||
editor: *ed.Editor,
|
editor: *ed.Editor,
|
||||||
editor_widget: ?*const Widget = null,
|
editor_widget: ?*const Widget = null,
|
||||||
differ: diffz.AsyncDiffer,
|
differ: diffz.AsyncDiffer,
|
||||||
|
|
@ -52,9 +54,11 @@ pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor
|
||||||
.line_number_style = tui.config().gutter_line_numbers_style,
|
.line_number_style = tui.config().gutter_line_numbers_style,
|
||||||
.highlight = tui.config().highlight_current_line_gutter,
|
.highlight = tui.config().highlight_current_line_gutter,
|
||||||
.symbols = tui.config().gutter_symbols,
|
.symbols = tui.config().gutter_symbols,
|
||||||
|
.width = undefined,
|
||||||
.editor = editor,
|
.editor = editor,
|
||||||
.differ = try diffz.create(),
|
.differ = try diffz.create(),
|
||||||
};
|
};
|
||||||
|
self.update_width();
|
||||||
try tui.message_filters().add(MessageFilter.bind(self, filter_receive));
|
try tui.message_filters().add(MessageFilter.bind(self, filter_receive));
|
||||||
try event_source.subscribe(EventHandler.bind(self, handle_event));
|
try event_source.subscribe(EventHandler.bind(self, handle_event));
|
||||||
return self.widget();
|
return self.widget();
|
||||||
|
|
@ -122,8 +126,19 @@ pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||||
|
|
||||||
fn update_width(self: *Self) void {
|
fn update_width(self: *Self) void {
|
||||||
if (self.line_number_mode == .none) return;
|
if (self.line_number_mode == .none) return;
|
||||||
const width = int_width(self.lines);
|
const minimum = tui.config().gutter_width_minimum;
|
||||||
self.width = if (self.line_number_mode == .relative and width > 4) 4 else @max(width, 2);
|
const maximum = tui.config().gutter_width_maximum;
|
||||||
|
const local = @max(int_width(self.lines), minimum);
|
||||||
|
const width =
|
||||||
|
switch (tui.config().gutter_width_mode) {
|
||||||
|
.local => local,
|
||||||
|
.global => blk: {
|
||||||
|
const width = @max(width_global, local);
|
||||||
|
width_global = @min(width, maximum);
|
||||||
|
break :blk width;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
self.width = if (self.line_number_mode == .relative and width > minimum) minimum else @max(width, 2);
|
||||||
self.width += if (self.symbols) 3 else 1;
|
self.width += if (self.symbols) 3 else 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue