add(style): cursor style to indicate a cursor position
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 25s

This commit is contained in:
2025-04-20 20:54:30 +02:00
parent a4293ff243
commit 50adf32f14
3 changed files with 13 additions and 2 deletions

View File

@@ -88,7 +88,9 @@ pub const Buffered = struct {
/// Write *virtual screen* to alternate screen (should be called once and last during each render loop iteration in the main loop).
pub fn flush(this: *@This()) !void {
try terminal.hideCursor();
// TODO measure timings of rendered frames?
var cursor_position: ?Point = null;
const writer = terminal.writer();
const s = this.screen;
const vs = this.virtual_screen;
@@ -99,12 +101,20 @@ pub const Buffered = struct {
const cvs = vs[idx];
if (cs.eql(cvs)) continue;
if (cvs.style.cursor) cursor_position = .{
.x = @truncate(col),
.y = @truncate(row),
};
// render differences found in virtual screen
try terminal.setCursorPosition(.{ .y = @truncate(row + 1), .x = @truncate(col + 1) });
try terminal.setCursorPosition(.{ .y = @truncate(row), .x = @truncate(col) });
try cvs.value(writer);
// update screen to be the virtual screen for the next frame
s[idx] = vs[idx];
}
}
if (cursor_position) |point| {
try terminal.showCursor();
try terminal.setCursorPosition(point);
}
}
};