feat: add configuration option default_cursor

This commit is contained in:
CJ van den Berg 2024-12-20 21:44:35 +01:00
parent deaafbefa0
commit afca8a86bc
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 8 additions and 4 deletions

View file

@ -13,6 +13,7 @@ whitespace_mode: []const u8 = "none",
animation_min_lag: usize = 0, //milliseconds
animation_max_lag: usize = 150, //milliseconds
enable_format_on_save: bool = false,
default_cursor: []const u8 = "default",
indent_size: usize = 4,
tab_width: usize = 8,

View file

@ -78,7 +78,7 @@ pub const Mode = struct {
name: []const u8 = "",
line_numbers: LineNumbers = .absolute,
keybind_hints: *const KeybindHints,
cursor_shape: CursorShape = .block,
cursor_shape: ?CursorShape = null,
pub fn deinit(self: *Mode) void {
self.allocator.free(self.mode);
@ -362,7 +362,7 @@ const BindingSet = struct {
on_match_failure: OnMatchFailure = .ignore,
name: []const u8,
line_numbers: LineNumbers = .absolute,
cursor_shape: CursorShape = .block,
cursor_shape: ?CursorShape = null,
insert_command: []const u8 = "",
hints_map: KeybindHints = .{},
@ -379,7 +379,7 @@ const BindingSet = struct {
on_match_failure: OnMatchFailure = .insert,
name: ?[]const u8 = null,
line_numbers: LineNumbers = .absolute,
cursor: CursorShape = .block,
cursor: ?CursorShape = null,
};
const parsed = try std.json.parseFromValue(JsonConfig, allocator, mode_bindings, .{
.ignore_unknown_fields = true,

View file

@ -52,6 +52,7 @@ final_exit: []const u8 = "normal",
render_pending: bool = false,
keepalive_timer: ?tp.Cancellable = null,
mouse_idle_timer: ?tp.Cancellable = null,
default_cursor: keybind.CursorShape = .default,
const keepalive = std.time.us_per_day * 365; // one year
const idle_frames = 0;
@ -118,6 +119,8 @@ fn init(allocator: Allocator) !*Self {
instance_ = self;
defer instance_ = null;
self.default_cursor = std.meta.stringToEnum(keybind.CursorShape, conf.default_cursor) orelse .default;
self.config.default_cursor = @tagName(self.default_cursor);
self.rdr.handler_ctx = self;
self.rdr.dispatch_input = dispatch_input;
self.rdr.dispatch_mouse = dispatch_mouse;
@ -1097,7 +1100,7 @@ fn set_terminal_style(self: *Self) void {
}
pub fn get_cursor_shape(self: *Self) renderer.CursorShape {
const shape = if (self.input_mode) |mode| mode.cursor_shape else .block;
const shape = if (self.input_mode) |mode| mode.cursor_shape orelse self.default_cursor else self.default_cursor;
return switch (shape) {
.default => .default,
.block_blink => .block_blink,