From 312fbedf4c9a2effbbd0cc9bed34d86d2a0cc993 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Thu, 2 Apr 2026 09:53:37 +0200 Subject: [PATCH] mod(renderer/direct): buffer and flush screen output accordingly --- src/render.zig | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/render.zig b/src/render.zig index 1308f0d..dc604a7 100644 --- a/src/render.zig +++ b/src/render.zig @@ -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! } }