Merge branch 'master' into zig-0.14
This commit is contained in:
commit
c41cd07085
7 changed files with 54 additions and 36 deletions
|
@ -3,8 +3,7 @@ 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: bool = true,
|
gutter_line_numbers_mode: ?LineNumberMode = null,
|
||||||
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,
|
||||||
|
@ -34,3 +33,9 @@ pub const DigitStyle = enum {
|
||||||
subscript,
|
subscript,
|
||||||
superscript,
|
superscript,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const LineNumberMode = enum {
|
||||||
|
none,
|
||||||
|
relative,
|
||||||
|
absolute,
|
||||||
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
["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"],
|
||||||
|
|
|
@ -78,7 +78,7 @@ pub const Mode = struct {
|
||||||
|
|
||||||
mode: []const u8,
|
mode: []const u8,
|
||||||
name: []const u8 = "",
|
name: []const u8 = "",
|
||||||
line_numbers: LineNumbers = .absolute,
|
line_numbers: LineNumbers = .inherit,
|
||||||
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 = .absolute,
|
line_numbers: LineNumbers = .inherit,
|
||||||
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 = .absolute,
|
line_numbers: LineNumbers = .inherit,
|
||||||
cursor: ?CursorShape = null,
|
cursor: ?CursorShape = null,
|
||||||
inherit: ?[]const u8 = null,
|
inherit: ?[]const u8 = null,
|
||||||
selection: ?SelectionStyle = null,
|
selection: ?SelectionStyle = null,
|
||||||
|
@ -663,6 +663,7 @@ const BindingSet = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LineNumbers = enum {
|
pub const LineNumbers = enum {
|
||||||
|
inherit,
|
||||||
absolute,
|
absolute,
|
||||||
relative,
|
relative,
|
||||||
};
|
};
|
||||||
|
|
|
@ -623,6 +623,13 @@ 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));
|
||||||
|
|
|
@ -392,6 +392,7 @@ pub const php = .{
|
||||||
.extensions = .{"php"},
|
.extensions = .{"php"},
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.injections = "tree-sitter-php/queries/injections.scm",
|
.injections = "tree-sitter-php/queries/injections.scm",
|
||||||
|
.language_server = .{"intelephense", "--stdio"},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const purescript = .{
|
pub const purescript = .{
|
||||||
|
|
|
@ -18,6 +18,7 @@ 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,8 +28,7 @@ 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,
|
||||||
linenum: bool,
|
mode: ?LineNumberMode = null,
|
||||||
relative: bool,
|
|
||||||
render_style: DigitStyle,
|
render_style: DigitStyle,
|
||||||
highlight: bool,
|
highlight: bool,
|
||||||
symbols: bool,
|
symbols: bool,
|
||||||
|
@ -48,8 +48,7 @@ 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,
|
||||||
.linenum = tui.config().gutter_line_numbers,
|
.mode = tui.config().gutter_line_numbers_mode,
|
||||||
.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,
|
||||||
|
@ -112,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.linenum) return;
|
if (self.mode == .none) return;
|
||||||
const width = int_width(self.lines);
|
const width = int_width(self.lines);
|
||||||
self.width = if (self.relative and width > 4) 4 else @max(width, 2);
|
self.width = if (self.mode == .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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +122,23 @@ pub fn layout(self: *Self) Widget.Layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fn get_width(self: *Self) usize {
|
inline fn get_width(self: *Self) usize {
|
||||||
return if (self.linenum) self.width else if (self.symbols) 3 else 1;
|
return if (self.mode != .none) 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 {
|
||||||
|
@ -134,14 +149,10 @@ 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(" ");
|
||||||
if (self.linenum) {
|
switch (self.get_numbering_mode()) {
|
||||||
const relative = self.relative or if (tui.input_mode()) |mode| mode.line_numbers == .relative else false;
|
.none => self.render_none(theme),
|
||||||
if (relative)
|
.relative => self.render_relative(theme),
|
||||||
self.render_relative(theme)
|
.absolute => self.render_linear(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);
|
||||||
|
|
|
@ -572,25 +572,17 @@ 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();
|
||||||
var ln = config.gutter_line_numbers;
|
const mode: ?@import("config").LineNumberMode = if (config.gutter_line_numbers_mode) |mode| switch(mode) {
|
||||||
var lnr = config.gutter_line_numbers_relative;
|
.absolute => .relative,
|
||||||
if (ln and !lnr) {
|
.relative => .none,
|
||||||
ln = true;
|
.none => null,
|
||||||
lnr = true;
|
} else .relative;
|
||||||
} else if (ln and lnr) {
|
|
||||||
ln = false;
|
config.gutter_line_numbers_mode = mode;
|
||||||
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.linenum = ln;
|
gutter.mode = mode;
|
||||||
gutter.relative = lnr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const gutter_mode_next_meta: Meta = .{ .description = "Next gutter mode" };
|
pub const gutter_mode_next_meta: Meta = .{ .description = "Next gutter mode" };
|
||||||
|
|
Loading…
Add table
Reference in a new issue