cursor: implement cursor shapes

This commit is contained in:
Tim Culverhouse 2024-04-15 07:14:31 -05:00
parent b5c2d80f57
commit 18609912d3
6 changed files with 28 additions and 2 deletions

View file

@ -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"

View file

@ -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 {

View file

@ -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;

View file

@ -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

View file

@ -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";

View file

@ -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 {