feat: use terminal cursors for mini mode and overlay input boxes
closes: #80
This commit is contained in:
parent
ff0987c108
commit
32d67a3972
4 changed files with 35 additions and 14 deletions
|
@ -36,11 +36,17 @@ pub fn Options(context: type) type {
|
||||||
}
|
}
|
||||||
if (self.cursor) |cursor| {
|
if (self.cursor) |cursor| {
|
||||||
const pos: c_int = @intCast(cursor);
|
const pos: c_int = @intCast(cursor);
|
||||||
self.plane.cursor_move_yx(0, pos + 1) catch return false;
|
const tui_ = tui.current();
|
||||||
var cell = self.plane.cell_init();
|
if (tui_.config.enable_terminal_cursor) {
|
||||||
_ = self.plane.at_cursor_cell(&cell) catch return false;
|
const y, const x = self.plane.rel_yx_to_abs(0, pos + 1);
|
||||||
cell.set_style(theme.editor_cursor);
|
tui_.rdr.cursor_enable(y, x, .default) catch {};
|
||||||
_ = self.plane.putc(&cell) catch {};
|
} else {
|
||||||
|
self.plane.cursor_move_yx(0, pos + 1) catch return false;
|
||||||
|
var cell = self.plane.cell_init();
|
||||||
|
_ = self.plane.at_cursor_cell(&cell) catch return false;
|
||||||
|
cell.set_style(theme.editor_cursor);
|
||||||
|
_ = self.plane.putc(&cell) catch {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -843,15 +843,18 @@ pub const Editor = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_terminal_cursor(self: *const Self, cursor_: *const Cursor) !void {
|
fn render_terminal_cursor(self: *const Self, cursor_: *const Cursor) !void {
|
||||||
|
const tui_ = tui.current();
|
||||||
|
if (tui_.is_mini_or_overlay_enabled())
|
||||||
|
return;
|
||||||
if (self.screen_cursor(cursor_)) |cursor| {
|
if (self.screen_cursor(cursor_)) |cursor| {
|
||||||
const y, const x = self.plane.rel_yx_to_abs(@intCast(cursor.row), @intCast(cursor.col));
|
const y, const x = self.plane.rel_yx_to_abs(@intCast(cursor.row), @intCast(cursor.col));
|
||||||
const shape = if (tui.current().input_mode) |mode|
|
const shape = if (tui_.input_mode) |mode|
|
||||||
mode.cursor_shape
|
mode.cursor_shape
|
||||||
else
|
else
|
||||||
.block;
|
.block;
|
||||||
tui.current().rdr.cursor_enable(y, x, tui.translate_cursor_shape(shape)) catch {};
|
tui_.rdr.cursor_enable(y, x, tui.translate_cursor_shape(shape)) catch {};
|
||||||
} else {
|
} else {
|
||||||
tui.current().rdr.cursor_disable();
|
tui_.rdr.cursor_disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,15 +101,21 @@ pub fn render(self: *Self, btn: *Button.State(Self), theme: *const Widget.Theme)
|
||||||
|
|
||||||
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
fn render_mini_mode(plane: *Plane, theme: *const Widget.Theme) void {
|
||||||
plane.off_styles(style.italic);
|
plane.off_styles(style.italic);
|
||||||
const mini_mode = tui.current().mini_mode orelse return;
|
const tui_ = tui.current();
|
||||||
|
const mini_mode = tui_.mini_mode orelse return;
|
||||||
_ = plane.print(" {s}", .{mini_mode.text}) catch {};
|
_ = plane.print(" {s}", .{mini_mode.text}) catch {};
|
||||||
if (mini_mode.cursor) |cursor| {
|
if (mini_mode.cursor) |cursor| {
|
||||||
const pos: c_int = @intCast(cursor);
|
const pos: c_int = @intCast(cursor);
|
||||||
plane.cursor_move_yx(0, pos + 1) catch return;
|
if (tui_.config.enable_terminal_cursor) {
|
||||||
var cell = plane.cell_init();
|
const y, const x = plane.rel_yx_to_abs(0, pos + 1);
|
||||||
_ = plane.at_cursor_cell(&cell) catch return;
|
tui_.rdr.cursor_enable(y, x, .default) catch {};
|
||||||
cell.set_style(theme.editor_cursor);
|
} else {
|
||||||
_ = plane.putc(&cell) catch {};
|
plane.cursor_move_yx(0, pos + 1) catch return;
|
||||||
|
var cell = plane.cell_init();
|
||||||
|
_ = plane.at_cursor_cell(&cell) catch return;
|
||||||
|
cell.set_style(theme.editor_cursor);
|
||||||
|
_ = plane.putc(&cell) catch {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -585,6 +585,10 @@ pub fn save_config(self: *const Self) !void {
|
||||||
try root.write_config(self.config, self.allocator);
|
try root.write_config(self.config, self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_mini_or_overlay_enabled(self: *const Self) bool {
|
||||||
|
return !(self.mini_mode == null or self.input_mode_outer == null);
|
||||||
|
}
|
||||||
|
|
||||||
fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
||||||
command.executeName("disable_fast_scroll", .{}) catch {};
|
command.executeName("disable_fast_scroll", .{}) catch {};
|
||||||
command.executeName("disable_jump_mode", .{}) catch {};
|
command.executeName("disable_jump_mode", .{}) catch {};
|
||||||
|
@ -767,6 +771,7 @@ const cmds = struct {
|
||||||
pub const change_file_type_meta = .{ .description = "Change file type" };
|
pub const change_file_type_meta = .{ .description = "Change file type" };
|
||||||
|
|
||||||
pub fn exit_overlay_mode(self: *Self, _: Ctx) Result {
|
pub fn exit_overlay_mode(self: *Self, _: Ctx) Result {
|
||||||
|
self.rdr.cursor_disable();
|
||||||
if (self.input_mode_outer == null) return;
|
if (self.input_mode_outer == null) return;
|
||||||
if (self.input_mode) |*mode| mode.deinit();
|
if (self.input_mode) |*mode| mode.deinit();
|
||||||
self.input_mode = self.input_mode_outer;
|
self.input_mode = self.input_mode_outer;
|
||||||
|
@ -818,6 +823,7 @@ const cmds = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit_mini_mode(self: *Self, _: Ctx) Result {
|
pub fn exit_mini_mode(self: *Self, _: Ctx) Result {
|
||||||
|
self.rdr.cursor_disable();
|
||||||
if (self.mini_mode) |_| {} else return;
|
if (self.mini_mode) |_| {} else return;
|
||||||
if (self.input_mode) |*mode| mode.deinit();
|
if (self.input_mode) |*mode| mode.deinit();
|
||||||
self.input_mode = self.input_mode_outer;
|
self.input_mode = self.input_mode_outer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue