metal: cursor and underline

This commit is contained in:
Mitchell Hashimoto
2022-10-30 19:47:15 -07:00
parent 4b5174d2c6
commit ee45d363a9
4 changed files with 264 additions and 52 deletions

View File

@@ -66,7 +66,7 @@ font_shaper: font.Shaper,
/// Whether the cursor is visible or not. This is used to control cursor
/// blinking.
cursor_visible: bool,
cursor_style: CursorStyle,
cursor_style: renderer.CursorStyle,
/// Default foreground color
foreground: terminal.color.RGB,
@@ -74,25 +74,6 @@ foreground: terminal.color.RGB,
/// Default background color
background: terminal.color.RGB,
/// Available cursor styles for drawing. The values represents the mode value
/// in the shader.
pub const CursorStyle = enum(u8) {
box = 3,
box_hollow = 4,
bar = 5,
/// Create a cursor style from the terminal style request.
pub fn fromTerminal(style: terminal.CursorStyle) ?CursorStyle {
return switch (style) {
.blinking_block, .steady_block => .box,
.blinking_bar, .steady_bar => .bar,
.blinking_underline, .steady_underline => null, // TODO
.default => .box,
else => null,
};
}
};
/// The raw structure that maps directly to the buffer sent to the vertex shader.
/// This must be "extern" so that the field order is not reordered by the
/// Zig compiler.
@@ -145,6 +126,14 @@ const GPUCellMode = enum(u8) {
// Non-exhaustive because masks change it
_,
pub fn fromCursor(cursor: renderer.CursorStyle) GPUCellMode {
return switch (cursor) {
.box => .cursor_rect,
.box_hollow => .cursor_rect_hollow,
.bar => .cursor_bar,
};
}
/// Apply a mask to the mode.
pub fn mask(self: GPUCellMode, m: GPUCellMode) GPUCellMode {
return @intToEnum(
@@ -468,7 +457,7 @@ pub fn render(
// Setup our cursor state
if (state.focused) {
self.cursor_visible = state.cursor.visible and !state.cursor.blink;
self.cursor_style = CursorStyle.fromTerminal(state.cursor.style) orelse .box;
self.cursor_style = renderer.CursorStyle.fromTerminal(state.cursor.style) orelse .box;
} else {
self.cursor_visible = true;
self.cursor_style = .box_hollow;
@@ -701,13 +690,8 @@ fn addCursor(self: *OpenGL, term: *Terminal) void {
term.screen.cursor.x,
);
var mode: GPUCellMode = @intToEnum(
GPUCellMode,
@enumToInt(self.cursor_style),
);
self.cells.appendAssumeCapacity(.{
.mode = mode,
.mode = GPUCellMode.fromCursor(self.cursor_style),
.grid_col = @intCast(u16, term.screen.cursor.x),
.grid_row = @intCast(u16, term.screen.cursor.y),
.grid_width = if (cell.attrs.wide) 2 else 1,