mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
enable drawing cursor on top or bottom based on style
This commit is contained in:
@ -141,12 +141,19 @@ pub const Contents = struct {
|
||||
}
|
||||
|
||||
/// Set the cursor value. If the value is null then the cursor is hidden.
|
||||
pub fn setCursor(self: *Contents, v: ?shaderpkg.CellText) void {
|
||||
pub fn setCursor(self: *Contents, v: ?shaderpkg.CellText, cursor_style: ?renderer.CursorStyle) void {
|
||||
self.fg_rows.lists[0].clearRetainingCapacity();
|
||||
self.fg_rows.lists[self.size.rows + 1].clearRetainingCapacity();
|
||||
|
||||
if (v) |cell| {
|
||||
self.fg_rows.lists[0].appendAssumeCapacity(cell);
|
||||
if (cursor_style) |style| {
|
||||
switch (style) {
|
||||
// Block cursors should be drawn first
|
||||
.block => self.fg_rows.lists[0].appendAssumeCapacity(cell),
|
||||
// Other cursor styles should be drawn last
|
||||
.block_hollow, .bar, .underline, .lock => self.fg_rows.lists[self.size.rows + 1].appendAssumeCapacity(cell),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,17 +381,17 @@ test Contents {
|
||||
}
|
||||
}
|
||||
|
||||
// Add a cursor.
|
||||
// Add a block cursor.
|
||||
const cursor_cell: shaderpkg.CellText = .{
|
||||
.mode = .cursor,
|
||||
.grid_pos = .{ 2, 3 },
|
||||
.color = .{ 0, 0, 0, 1 },
|
||||
};
|
||||
c.setCursor(cursor_cell);
|
||||
c.setCursor(cursor_cell, .block);
|
||||
try testing.expectEqual(cursor_cell, c.fg_rows.lists[0].items[0]);
|
||||
|
||||
// And remove it.
|
||||
c.setCursor(null);
|
||||
c.setCursor(null, null);
|
||||
try testing.expectEqual(0, c.fg_rows.lists[0].items.len);
|
||||
}
|
||||
|
||||
|
@ -2791,7 +2791,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||
// Setup our cursor rendering information.
|
||||
cursor: {
|
||||
// By default, we don't handle cursor inversion on the shader.
|
||||
self.cells.setCursor(null);
|
||||
self.cells.setCursor(null, null);
|
||||
self.uniforms.cursor_pos = .{
|
||||
std.math.maxInt(u16),
|
||||
std.math.maxInt(u16),
|
||||
@ -3162,7 +3162,7 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
|
||||
@intCast(render.glyph.offset_x),
|
||||
@intCast(render.glyph.offset_y),
|
||||
},
|
||||
});
|
||||
}, cursor_style);
|
||||
}
|
||||
|
||||
fn addPreeditCell(
|
||||
|
Reference in New Issue
Block a user