mod: remove min_size argument from App.start

This commit is contained in:
2025-02-06 22:19:27 +01:00
parent 8586a05508
commit 11531e9d4a
4 changed files with 80 additions and 128 deletions

View File

@@ -1,12 +1,3 @@
//! Renderer which holds the screen to compare with the previous screen for efficient rendering.
//! Each renderer should at least implement these functions:
//! - resize(this: *@This(), size: Size) void {}
//! - clear(this: *@This(), size: Size) !void {}
//! - render(this: *@This(), size: Size, contents: []u8) !void {}
//!
//! Each `Renderer` should be able to be used interchangeable without having to
//! change any code of any `Layout` or `Widget`. The only change should be the
//! passed type to `zterm.App` _R_ parameter.
const std = @import("std");
const terminal = @import("terminal.zig");
@@ -45,14 +36,12 @@ pub const Buffered = struct {
log.debug("renderer::resize", .{});
defer this.size = size;
if (this.size.cols >= size.cols or this.size.rows >= size.rows) {
if (!this.created) {
this.screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
@memset(this.screen, .{});
this.virtual_screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
@memset(this.virtual_screen, .{});
this.created = true;
}
if (!this.created) {
this.screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
@memset(this.screen, .{});
this.virtual_screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
@memset(this.virtual_screen, .{});
this.created = true;
} else {
this.allocator.free(this.screen);
this.screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
@@ -72,9 +61,9 @@ pub const Buffered = struct {
}
/// Render provided cells at size (anchor and dimension) into the *virtual screen*.
pub fn render(this: *@This(), comptime T: type, container: *T) void {
pub fn render(this: *@This(), comptime T: type, container: *T) !void {
const size: Size = container.size;
const cells: []const Cell = container.contents();
const cells: []const Cell = try container.contents();
if (cells.len == 0) return;
@@ -93,10 +82,11 @@ pub const Buffered = struct {
if (cells.len == idx) break :blk;
}
}
// free immediately
container.allocator.free(cells);
for (container.elements.items) |*element| {
this.render(T, element);
try this.render(T, element);
}
}
@@ -112,10 +102,9 @@ pub const Buffered = struct {
const idx = (row * this.size.cols) + col;
const cs = s[idx];
const cvs = vs[idx];
if (cs.eql(cvs))
continue;
if (cs.eql(cvs)) continue;
// render differences found in virtual screen
// TODO: improve the writing speed (many unnecessary writes (i.e. the style for every character..))
try terminal.setCursorPosition(.{ .row = @truncate(row + 1), .col = @truncate(col + 1) });
try cvs.value(writer);
// update screen to be the virtual screen for the next frame