mod(renderer/direct): buffer and flush screen output accordingly
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 2m31s

This commit is contained in:
2026-04-02 09:53:37 +02:00
parent b39d4326be
commit 312fbedf4c

View File

@@ -201,12 +201,33 @@ pub const Direct = struct {
}
pub fn flush(this: *@This()) !void {
var writer = terminal.writer();
for (0..this.size.y) |row| {
const stdout_file = std.fs.File.stdout();
var buffer: [4096]u8 = undefined;
var stdout_writer = stdout_file.writer(&buffer);
var writer = &stdout_writer.interface;
defer writer.flush() catch {};
row: for (0..this.size.y) |row| {
for (0..this.size.x) |col| {
const idx = (row * this.size.x) + col;
const cvs = this.screen[idx];
try cvs.value(&writer);
// are we done for this row already?
if (col + 1 < this.size.x and meta.eql(cvs, .{})) {
// check the remaining line
var last_cell = true;
for (col..this.size.x) |x| {
if (!meta.eql(cvs, this.screen[(row * this.size.x) + x])) {
last_cell = false;
break;
}
}
if (last_cell) {
//std.log.debug("Found the last cell in row: {d} at column: {d}", .{row, col});
_ = try writer.write("\n");
continue :row;
}
}
try cvs.value(writer);
if (cvs.style.cursor) return; // that's where the cursor should be left!
}
}