diff --git a/src/Cell.zig b/src/Cell.zig index 5e21db7..18bd3dd 100644 --- a/src/Cell.zig +++ b/src/Cell.zig @@ -21,6 +21,16 @@ pub const Character = struct { width: usize = 1, }; +pub const CursorShape = enum { + default, + block_blink, + block, + underline_blink, + underline, + beam_blink, + beam, +}; + pub const Hyperlink = struct { uri: []const u8 = "", /// ie "id=app-1234" diff --git a/src/InternalScreen.zig b/src/InternalScreen.zig index 194d44e..1a57dc0 100644 --- a/src/InternalScreen.zig +++ b/src/InternalScreen.zig @@ -2,7 +2,8 @@ const std = @import("std"); const assert = std.debug.assert; const Style = @import("Cell.zig").Style; const Cell = @import("Cell.zig"); -const Shape = @import("Mouse.zig").Shape; +const MouseShape = @import("Mouse.zig").Shape; +const CursorShape = Cell.CursorShape; const log = std.log.scoped(.internal_screen); @@ -32,8 +33,9 @@ buf: []InternalCell = undefined, cursor_row: usize = 0, cursor_col: usize = 0, cursor_vis: bool = false, +cursor_shape: CursorShape = .default, -mouse_shape: Shape = .default, +mouse_shape: MouseShape = .default, /// sets each cell to the default cell pub fn init(alloc: std.mem.Allocator, w: usize, h: usize) !InternalScreen { diff --git a/src/Screen.zig b/src/Screen.zig index fe118f7..ceea4bb 100644 --- a/src/Screen.zig +++ b/src/Screen.zig @@ -26,6 +26,7 @@ cursor_vis: bool = false, unicode: bool = false, mouse_shape: Shape = .default, +cursor_shape: Cell.CursorShape = .default, pub fn init(alloc: std.mem.Allocator, winsize: Winsize) !Screen { const w = winsize.cols; diff --git a/src/Window.zig b/src/Window.zig index 284a35a..1f4d962 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -230,6 +230,10 @@ pub fn showCursor(self: Window, col: usize, row: usize) void { self.screen.cursor_col = col + self.x_off; } +pub fn setCursorShape(self: Window, shape: Cell.CursorShape) void { + self.screen.cursor_shape = shape; +} + /// Options to use when printing Segments to a window pub const PrintOptions = struct { /// vertical offset to start printing at diff --git a/src/ctlseqs.zig b/src/ctlseqs.zig index 7e4f3d8..b496d44 100644 --- a/src/ctlseqs.zig +++ b/src/ctlseqs.zig @@ -36,6 +36,7 @@ pub const home = "\x1b[H"; pub const cup = "\x1b[{d};{d}H"; pub const hide_cursor = "\x1b[?25l"; pub const show_cursor = "\x1b[?25h"; +pub const cursor_shape = "\x1b[{d} q"; // alt screen pub const smcup = "\x1b[?1049h"; diff --git a/src/vaxis.zig b/src/vaxis.zig index e33bd3c..c1e1cd2 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -531,6 +531,14 @@ pub fn Vaxis(comptime T: type) type { ); self.screen_last.mouse_shape = self.screen.mouse_shape; } + if (self.screen.cursor_shape != self.screen_last.cursor_shape) { + try std.fmt.format( + tty.buffered_writer.writer(), + ctlseqs.cursor_shape, + .{@intFromEnum(self.screen.cursor_shape)}, + ); + self.screen_last.cursor_shape = self.screen.cursor_shape; + } } fn enableKittyKeyboard(self: *Self, flags: Key.KittyFlags) !void {