Compare commits

..

No commits in common. "21b56527525f355419631983f6aacd3835b669ab" and "c7cca545b9ceaf0a66885544caf020ecb63e66c5" have entirely different histories.

6 changed files with 36 additions and 53 deletions

View file

@ -3,7 +3,8 @@ const builtin = @import("builtin");
frame_rate: usize = 60, frame_rate: usize = 60,
theme: []const u8 = "default", theme: []const u8 = "default",
input_mode: []const u8 = "flow", input_mode: []const u8 = "flow",
gutter_line_numbers_mode: ?LineNumberMode = null, gutter_line_numbers: bool = true,
gutter_line_numbers_relative: bool = false,
gutter_line_numbers_style: DigitStyle = .ascii, gutter_line_numbers_style: DigitStyle = .ascii,
gutter_symbols: bool = true, gutter_symbols: bool = true,
enable_terminal_cursor: bool = true, enable_terminal_cursor: bool = true,
@ -33,9 +34,3 @@ pub const DigitStyle = enum {
subscript, subscript,
superscript, superscript,
}; };
pub const LineNumberMode = enum {
none,
relative,
absolute,
};

View file

@ -40,7 +40,6 @@
["V", ["enter_mode", "visual line"], ["select_line_vim"]], ["V", ["enter_mode", "visual line"], ["select_line_vim"]],
["n", "goto_next_match"], ["n", "goto_next_match"],
["N", "goto_prev_match"],
["0", "move_begin"], ["0", "move_begin"],
["^", "smart_move_begin"], ["^", "smart_move_begin"],
["$", "move_end"], ["$", "move_end"],

View file

@ -78,7 +78,7 @@ pub const Mode = struct {
mode: []const u8, mode: []const u8,
name: []const u8 = "", name: []const u8 = "",
line_numbers: LineNumbers = .inherit, line_numbers: LineNumbers = .absolute,
keybind_hints: *const KeybindHints, keybind_hints: *const KeybindHints,
cursor_shape: ?CursorShape = null, cursor_shape: ?CursorShape = null,
selection_style: SelectionStyle, selection_style: SelectionStyle,
@ -365,7 +365,7 @@ const BindingSet = struct {
syntax: KeySyntax = .flow, syntax: KeySyntax = .flow,
on_match_failure: OnMatchFailure = .ignore, on_match_failure: OnMatchFailure = .ignore,
name: []const u8, name: []const u8,
line_numbers: LineNumbers = .inherit, line_numbers: LineNumbers = .absolute,
cursor_shape: ?CursorShape = null, cursor_shape: ?CursorShape = null,
selection_style: SelectionStyle, selection_style: SelectionStyle,
insert_command: []const u8 = "", insert_command: []const u8 = "",
@ -383,7 +383,7 @@ const BindingSet = struct {
syntax: KeySyntax = .flow, syntax: KeySyntax = .flow,
on_match_failure: OnMatchFailure = .insert, on_match_failure: OnMatchFailure = .insert,
name: ?[]const u8 = null, name: ?[]const u8 = null,
line_numbers: LineNumbers = .inherit, line_numbers: LineNumbers = .absolute,
cursor: ?CursorShape = null, cursor: ?CursorShape = null,
inherit: ?[]const u8 = null, inherit: ?[]const u8 = null,
selection: ?SelectionStyle = null, selection: ?SelectionStyle = null,
@ -663,7 +663,6 @@ const BindingSet = struct {
}; };
pub const LineNumbers = enum { pub const LineNumbers = enum {
inherit,
absolute, absolute,
relative, relative,
}; };

View file

@ -619,13 +619,6 @@ fn config_eql(comptime T: type, a: T, b: T) bool {
} }
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
.Bool, .Int, .Float, .Enum => return a == b, .Bool, .Int, .Float, .Enum => return a == b,
.Optional => |info| {
if (a == null and b == null)
return true;
if (a == null or b == null)
return false;
return config_eql(info.child, a.?, b.?);
},
else => {}, else => {},
} }
@compileError("unsupported config type " ++ @typeName(T)); @compileError("unsupported config type " ++ @typeName(T));

View file

@ -17,7 +17,6 @@ const MessageFilter = @import("MessageFilter.zig");
const tui = @import("tui.zig"); const tui = @import("tui.zig");
const ed = @import("editor.zig"); const ed = @import("editor.zig");
const DigitStyle = @import("config").DigitStyle; const DigitStyle = @import("config").DigitStyle;
const LineNumberMode = @import("config").LineNumberMode;
allocator: Allocator, allocator: Allocator,
plane: Plane, plane: Plane,
@ -27,7 +26,8 @@ lines: u32 = 0,
view_rows: u32 = 1, view_rows: u32 = 1,
view_top: u32 = 1, view_top: u32 = 1,
line: usize = 0, line: usize = 0,
mode: ?LineNumberMode = null, linenum: bool,
relative: bool,
render_style: DigitStyle, render_style: DigitStyle,
highlight: bool, highlight: bool,
symbols: bool, symbols: bool,
@ -47,7 +47,8 @@ pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor
.allocator = allocator, .allocator = allocator,
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*), .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*),
.parent = parent, .parent = parent,
.mode = tui.config().gutter_line_numbers_mode, .linenum = tui.config().gutter_line_numbers,
.relative = tui.config().gutter_line_numbers_relative,
.render_style = tui.config().gutter_line_numbers_style, .render_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,
@ -110,9 +111,9 @@ 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.mode == .none) return; if (!self.linenum) return;
const width = int_width(self.lines); const width = int_width(self.lines);
self.width = if (self.mode == .relative and width > 4) 4 else @max(width, 2); self.width = if (self.relative and width > 4) 4 else @max(width, 2);
self.width += if (self.symbols) 3 else 1; self.width += if (self.symbols) 3 else 1;
} }
@ -121,23 +122,7 @@ pub fn layout(self: *Self) Widget.Layout {
} }
inline fn get_width(self: *Self) usize { inline fn get_width(self: *Self) usize {
return if (self.mode != .none) self.width else if (self.symbols) 3 else 1; return if (self.linenum) self.width else if (self.symbols) 3 else 1;
}
fn get_numbering_mode(self: *const Self) LineNumberMode {
return self.mode orelse switch (if (tui.input_mode()) |mode| mode.line_numbers else .absolute) {
.relative => .relative,
.inherit => if (tui.input_mode_outer()) |mode| from_mode_enum(mode.line_numbers) else .absolute,
.absolute => .absolute,
};
}
fn from_mode_enum(mode: anytype) LineNumberMode {
return switch (mode) {
.relative => .relative,
.inherit => .absolute,
.absolute => .absolute,
};
} }
pub fn render(self: *Self, theme: *const Widget.Theme) bool { pub fn render(self: *Self, theme: *const Widget.Theme) bool {
@ -148,10 +133,14 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
self.plane.home(); self.plane.home();
self.plane.set_style(theme.editor_gutter); self.plane.set_style(theme.editor_gutter);
_ = self.plane.fill(" "); _ = self.plane.fill(" ");
switch (self.get_numbering_mode()) { if (self.linenum) {
.none => self.render_none(theme), const relative = self.relative or if (tui.input_mode()) |mode| mode.line_numbers == .relative else false;
.relative => self.render_relative(theme), if (relative)
.absolute => self.render_linear(theme), self.render_relative(theme)
else
self.render_linear(theme);
} else {
self.render_none(theme);
} }
if (self.symbols) if (self.symbols)
self.render_diagnostics(theme); self.render_diagnostics(theme);

View file

@ -572,17 +572,25 @@ const cmds = struct {
pub fn gutter_mode_next(self: *Self, _: Ctx) Result { pub fn gutter_mode_next(self: *Self, _: Ctx) Result {
const config = tui.config_mut(); const config = tui.config_mut();
const mode: ?@import("config").LineNumberMode = if (config.gutter_line_numbers_mode) |mode| switch(mode) { var ln = config.gutter_line_numbers;
.absolute => .relative, var lnr = config.gutter_line_numbers_relative;
.relative => .none, if (ln and !lnr) {
.none => null, ln = true;
} else .relative; lnr = true;
} else if (ln and lnr) {
config.gutter_line_numbers_mode = mode; ln = false;
lnr = false;
} else {
ln = true;
lnr = false;
}
config.gutter_line_numbers = ln;
config.gutter_line_numbers_relative = lnr;
try tui.save_config(); try tui.save_config();
if (self.widgets.get("editor_gutter")) |gutter_widget| { if (self.widgets.get("editor_gutter")) |gutter_widget| {
const gutter = gutter_widget.dynamic_cast(@import("editor_gutter.zig")) orelse return; const gutter = gutter_widget.dynamic_cast(@import("editor_gutter.zig")) orelse return;
gutter.mode = mode; gutter.linenum = ln;
gutter.relative = lnr;
} }
} }
pub const gutter_mode_next_meta = .{ .description = "Next gutter mode" }; pub const gutter_mode_next_meta = .{ .description = "Next gutter mode" };