cursor: implement cursor shapes
This commit is contained in:
parent
b5c2d80f57
commit
18609912d3
6 changed files with 28 additions and 2 deletions
10
src/Cell.zig
10
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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue