feat: add basic POC support for kitty multi cursor protocol
This commit is contained in:
parent
8454ebc9f4
commit
5caab36297
3 changed files with 27 additions and 5 deletions
|
@ -30,8 +30,8 @@
|
||||||
.hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX",
|
.hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX",
|
||||||
},
|
},
|
||||||
.vaxis = .{
|
.vaxis = .{
|
||||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#beb82aa0a9d77f63462f8ca8250c2b9eecf057a2",
|
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#b3c4a114dad73dcec94ffef2b0d3373a078c263c",
|
||||||
.hash = "vaxis-0.5.1-BWNV_FMWCQDGtkYFKz_85wSkBRO1kynUZaPO1-RCSrQM",
|
.hash = "vaxis-0.5.1-BWNV_JkcCQDV7RK7e_lzY4EyrQY5XfBod_C0nQi_q615",
|
||||||
},
|
},
|
||||||
.zeit = .{
|
.zeit = .{
|
||||||
.url = "https://github.com/rockorager/zeit/archive/8fd203f85f597f16e0a525c1f1ca1e0bffded809.tar.gz",
|
.url = "https://github.com/rockorager/zeit/archive/8fd203f85f597f16e0a525c1f1ca1e0bffded809.tar.gz",
|
||||||
|
|
|
@ -382,6 +382,11 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void {
|
||||||
self.vx.caps.rgb = true;
|
self.vx.caps.rgb = true;
|
||||||
},
|
},
|
||||||
.cap_color_scheme_updates => {},
|
.cap_color_scheme_updates => {},
|
||||||
|
|
||||||
|
.cap_multi_cursor => {
|
||||||
|
self.logger.print("multi cursor capability detected", .{});
|
||||||
|
self.vx.caps.multi_cursor = true;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,6 +540,14 @@ pub fn cursor_disable(self: *Self) void {
|
||||||
self.vx.screen.cursor_vis = false;
|
self.vx.screen.cursor_vis = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear_all_multi_cursors(self: *Self) !void {
|
||||||
|
try self.tty.anyWriter().print("\x1b[>0;4 q", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_multi_cursor_yx(self: *Self, y: c_int, x: c_int) !void {
|
||||||
|
try self.tty.anyWriter().print("\x1b[>-1;2:{d}:{d} q", .{ y + 1, x + 1 });
|
||||||
|
}
|
||||||
|
|
||||||
fn sync_mod_state(self: *Self, keypress: u32, modifiers: vaxis.Key.Modifiers) !void {
|
fn sync_mod_state(self: *Self, keypress: u32, modifiers: vaxis.Key.Modifiers) !void {
|
||||||
if (modifiers.ctrl and !self.mods.ctrl and !(keypress == input.key.left_control or keypress == input.key.right_control))
|
if (modifiers.ctrl and !self.mods.ctrl and !(keypress == input.key.left_control or keypress == input.key.right_control))
|
||||||
try self.send_sync_key(input.event.press, input.key.left_control, "", modifiers);
|
try self.send_sync_key(input.event.press, input.key.left_control, "", modifiers);
|
||||||
|
|
|
@ -1179,6 +1179,8 @@ pub const Editor = struct {
|
||||||
const style = tui.get_selection_style();
|
const style = tui.get_selection_style();
|
||||||
const frame = tracy.initZone(@src(), .{ .name = "editor render cursors" });
|
const frame = tracy.initZone(@src(), .{ .name = "editor render cursors" });
|
||||||
defer frame.deinit();
|
defer frame.deinit();
|
||||||
|
if (tui.config().enable_terminal_cursor and tui.rdr().vx.caps.multi_cursor)
|
||||||
|
tui.rdr().clear_all_multi_cursors() catch {};
|
||||||
for (self.cursels.items[0 .. self.cursels.items.len - 1]) |*cursel_| if (cursel_.*) |*cursel| {
|
for (self.cursels.items[0 .. self.cursels.items.len - 1]) |*cursel_| if (cursel_.*) |*cursel| {
|
||||||
const cursor = try self.get_rendered_cursor(style, cursel);
|
const cursor = try self.get_rendered_cursor(style, cursel);
|
||||||
try self.render_cursor_secondary(&cursor, theme, cell_map);
|
try self.render_cursor_secondary(&cursor, theme, cell_map);
|
||||||
|
@ -1207,7 +1209,9 @@ pub const Editor = struct {
|
||||||
set_cell_map_cursor(cell_map, pos.row, pos.col);
|
set_cell_map_cursor(cell_map, pos.row, pos.col);
|
||||||
const y, const x = self.plane.rel_yx_to_abs(@intCast(pos.row), @intCast(pos.col));
|
const y, const x = self.plane.rel_yx_to_abs(@intCast(pos.row), @intCast(pos.col));
|
||||||
const configured_shape = tui.get_cursor_shape();
|
const configured_shape = tui.get_cursor_shape();
|
||||||
const cursor_shape = if (self.cursels.items.len > 1) switch (configured_shape) {
|
const cursor_shape = if (tui.rdr().vx.caps.multi_cursor)
|
||||||
|
configured_shape
|
||||||
|
else if (self.cursels.items.len > 1) switch (configured_shape) {
|
||||||
.beam => .block,
|
.beam => .block,
|
||||||
.beam_blink => .block_blink,
|
.beam_blink => .block_blink,
|
||||||
.underline => .block,
|
.underline => .block,
|
||||||
|
@ -1224,8 +1228,13 @@ pub const Editor = struct {
|
||||||
fn render_cursor_secondary(self: *Self, cursor: *const Cursor, theme: *const Widget.Theme, cell_map: CellMap) !void {
|
fn render_cursor_secondary(self: *Self, cursor: *const Cursor, theme: *const Widget.Theme, cell_map: CellMap) !void {
|
||||||
if (self.screen_cursor(cursor)) |pos| {
|
if (self.screen_cursor(cursor)) |pos| {
|
||||||
set_cell_map_cursor(cell_map, pos.row, pos.col);
|
set_cell_map_cursor(cell_map, pos.row, pos.col);
|
||||||
self.plane.cursor_move_yx(@intCast(pos.row), @intCast(pos.col)) catch return;
|
if (tui.config().enable_terminal_cursor and tui.rdr().vx.caps.multi_cursor) {
|
||||||
self.render_cursor_cell(theme.editor_cursor_secondary);
|
const y, const x = self.plane.rel_yx_to_abs(@intCast(pos.row), @intCast(pos.col));
|
||||||
|
tui.rdr().show_multi_cursor_yx(y, x) catch return;
|
||||||
|
} else {
|
||||||
|
self.plane.cursor_move_yx(@intCast(pos.row), @intCast(pos.col)) catch return;
|
||||||
|
self.render_cursor_cell(theme.editor_cursor_secondary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue