vaxis: implement mouse shapes
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
4c84faddfa
commit
85060b001f
7 changed files with 36 additions and 2 deletions
|
@ -22,7 +22,7 @@ Contributions are welcome.
|
||||||
| Bracketed Paste | ✅ | ✅ | ❌ |
|
| Bracketed Paste | ✅ | ✅ | ❌ |
|
||||||
| Kitty Keyboard | ✅ | ✅ | ✅ |
|
| Kitty Keyboard | ✅ | ✅ | ✅ |
|
||||||
| Styled Underlines | ✅ | ✅ | ✅ |
|
| Styled Underlines | ✅ | ✅ | ✅ |
|
||||||
| Mouse Shapes (OSC 22) | ✅ | planned | ❌ |
|
| Mouse Shapes (OSC 22) | ✅ | ✅ | ❌ |
|
||||||
| System Clipboard (OSC 52) | ✅ | planned | ❌ |
|
| System Clipboard (OSC 52) | ✅ | planned | ❌ |
|
||||||
| System Notifications (OSC 9) | ✅ | ✅ | ❌ |
|
| System Notifications (OSC 9) | ✅ | ✅ | ❌ |
|
||||||
| System Notifications (OSC 777) | ✅ | ✅ | ❌ |
|
| System Notifications (OSC 777) | ✅ | ✅ | ❌ |
|
||||||
|
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Style = @import("cell.zig").Style;
|
const Style = @import("cell.zig").Style;
|
||||||
const Cell = @import("cell.zig").Cell;
|
const Cell = @import("cell.zig").Cell;
|
||||||
|
const Shape = @import("Mouse.zig").Shape;
|
||||||
|
|
||||||
const log = std.log.scoped(.internal_screen);
|
const log = std.log.scoped(.internal_screen);
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@ cursor_row: usize = 0,
|
||||||
cursor_col: usize = 0,
|
cursor_col: usize = 0,
|
||||||
cursor_vis: bool = false,
|
cursor_vis: bool = false,
|
||||||
|
|
||||||
|
mouse_shape: Shape = .default,
|
||||||
|
|
||||||
/// sets each cell to the default cell
|
/// sets each cell to the default cell
|
||||||
pub fn init(alloc: std.mem.Allocator, w: usize, h: usize) !InternalScreen {
|
pub fn init(alloc: std.mem.Allocator, w: usize, h: usize) !InternalScreen {
|
||||||
var screen = InternalScreen{};
|
var screen = InternalScreen{};
|
||||||
|
|
14
src/Mouse.zig
Normal file
14
src/Mouse.zig
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/// A mouse event
|
||||||
|
pub const Mouse = @This();
|
||||||
|
|
||||||
|
pub const Shape = enum {
|
||||||
|
default,
|
||||||
|
text,
|
||||||
|
pointer,
|
||||||
|
help,
|
||||||
|
progress,
|
||||||
|
wait,
|
||||||
|
@"ew-resize",
|
||||||
|
@"ns-resize",
|
||||||
|
cell,
|
||||||
|
};
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
const Cell = @import("cell.zig").Cell;
|
const Cell = @import("cell.zig").Cell;
|
||||||
|
const Shape = @import("Mouse.zig").Shape;
|
||||||
|
|
||||||
const log = std.log.scoped(.screen);
|
const log = std.log.scoped(.screen);
|
||||||
|
|
||||||
|
@ -18,6 +19,8 @@ cursor_vis: bool = false,
|
||||||
|
|
||||||
unicode: bool = false,
|
unicode: bool = false,
|
||||||
|
|
||||||
|
mouse_shape: Shape = .default,
|
||||||
|
|
||||||
pub fn init(alloc: std.mem.Allocator, w: usize, h: usize) !Screen {
|
pub fn init(alloc: std.mem.Allocator, w: usize, h: usize) !Screen {
|
||||||
var self = Screen{
|
var self = Screen{
|
||||||
.buf = try alloc.alloc(Cell, w * h),
|
.buf = try alloc.alloc(Cell, w * h),
|
||||||
|
|
|
@ -84,3 +84,4 @@ pub const osc8 = "\x1b]8;{s};{s}\x1b\\";
|
||||||
pub const osc8_clear = "\x1b]8;;\x1b\\";
|
pub const osc8_clear = "\x1b]8;;\x1b\\";
|
||||||
pub const osc9_notify = "\x1b]9;{s}\x1b\\";
|
pub const osc9_notify = "\x1b]9;{s}\x1b\\";
|
||||||
pub const osc777_notify = "\x1b]777;notify;{s};{s}\x1b\\";
|
pub const osc777_notify = "\x1b]777;notify;{s};{s}\x1b\\";
|
||||||
|
pub const osc22_mouse_shape = "\x1b]22;{s}\x1b\\";
|
||||||
|
|
|
@ -18,6 +18,7 @@ pub fn init(comptime EventType: type, opts: Options) !Vaxis(EventType) {
|
||||||
test {
|
test {
|
||||||
_ = @import("GraphemeCache.zig");
|
_ = @import("GraphemeCache.zig");
|
||||||
_ = @import("Key.zig");
|
_ = @import("Key.zig");
|
||||||
|
_ = @import("Mouse.zig");
|
||||||
_ = @import("Options.zig");
|
_ = @import("Options.zig");
|
||||||
_ = @import("Parser.zig");
|
_ = @import("Parser.zig");
|
||||||
_ = @import("Screen.zig");
|
_ = @import("Screen.zig");
|
||||||
|
|
|
@ -11,8 +11,8 @@ const InternalScreen = @import("InternalScreen.zig");
|
||||||
const Window = @import("Window.zig");
|
const Window = @import("Window.zig");
|
||||||
const Options = @import("Options.zig");
|
const Options = @import("Options.zig");
|
||||||
const Style = @import("cell.zig").Style;
|
const Style = @import("cell.zig").Style;
|
||||||
const strWidth = @import("ziglyph").display_width.strWidth;
|
|
||||||
const gwidth = @import("gwidth.zig");
|
const gwidth = @import("gwidth.zig");
|
||||||
|
const Shape = @import("Mouse.zig").Shape;
|
||||||
|
|
||||||
/// Vaxis is the entrypoint for a Vaxis application. The provided type T should
|
/// Vaxis is the entrypoint for a Vaxis application. The provided type T should
|
||||||
/// be a tagged union which contains all of the events the application will
|
/// be a tagged union which contains all of the events the application will
|
||||||
|
@ -458,6 +458,13 @@ pub fn Vaxis(comptime T: type) type {
|
||||||
);
|
);
|
||||||
_ = try tty.write(ctlseqs.show_cursor);
|
_ = try tty.write(ctlseqs.show_cursor);
|
||||||
}
|
}
|
||||||
|
if (self.screen.mouse_shape != self.screen_last.mouse_shape) {
|
||||||
|
try std.fmt.format(
|
||||||
|
tty.buffered_writer.writer(),
|
||||||
|
ctlseqs.osc22_mouse_shape,
|
||||||
|
.{@tagName(self.screen.mouse_shape)},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enableKittyKeyboard(self: *Self, flags: Key.KittyFlags) !void {
|
fn enableKittyKeyboard(self: *Self, flags: Key.KittyFlags) !void {
|
||||||
|
@ -510,6 +517,11 @@ pub fn Vaxis(comptime T: type) type {
|
||||||
_ = try self.tty.?.write(seq);
|
_ = try self.tty.?.write(seq);
|
||||||
try self.tty.?.flush();
|
try self.tty.?.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// set the mouse shape
|
||||||
|
pub fn setMouseShape(self: *Self, shape: Shape) void {
|
||||||
|
self.screen.mouse_shape = shape;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue