mod: example shows how dynamic sizing is achived that can be independent form the reported terminal size

Setting the cursor with the `Direct` handler will cause the rendering
to halt at that point and leave the cursor at point.

Due to not enabling *raw mode* with the newly introduced `App.start`
configuration options corresponding inputs are only visible to `zterm`
once the input has been completed with a newline. With this it is not
necessary for the renderer to know nothing more than the width of the
terminal (which is implied through the `Container` sizes). Making it
very trivial to implement.
This commit is contained in:
2026-01-20 13:57:55 +01:00
parent c29c60bd89
commit 97a240c54d
4 changed files with 143 additions and 38 deletions

View File

@@ -144,8 +144,6 @@ pub const Direct = struct {
}
pub fn resize(this: *@This()) !Point {
// TODO the size in the y-axis is *not fixed* and *not limited*
// how can I achive this?
this.size = .{};
if (!this.resized) {
this.gpa.free(this.screen);
@@ -160,17 +158,17 @@ pub const Direct = struct {
try terminal.clearScreen();
}
/// Render provided cells at size (anchor and dimension) into the *virtual screen*.
/// Render provided cells at size (anchor and dimension) into the *screen*.
pub fn render(this: *@This(), comptime Container: type, container: *Container, comptime Model: type, model: *const Model) !void {
const size: Point = container.size;
const origin: Point = container.origin;
if (this.resized) {
this.size = size;
const n = @as(usize, this.size.x) * @as(usize, this.size.y);
this.screen = try this.gpa.alloc(Cell, n);
@memset(this.screen, .{});
this.resized = false;
this.size = size;
const n = @as(usize, this.size.x) * @as(usize, this.size.y);
this.screen = try this.gpa.alloc(Cell, n);
@memset(this.screen, .{});
this.resized = false;
}
const cells: []const Cell = try container.content(model);
@@ -179,7 +177,6 @@ pub const Direct = struct {
var vs = this.screen;
const anchor: usize = (@as(usize, origin.y) * @as(usize, this.size.x)) + @as(usize, origin.x);
blk: for (0..size.y) |row| {
for (0..size.x) |col| {
vs[anchor + (row * this.size.x) + col] = cells[idx];
@@ -200,6 +197,7 @@ pub const Direct = struct {
const idx = (row * this.size.x) + col;
const cvs = this.screen[idx];
try cvs.value(&writer);
if (cvs.style.cursor) return; // that's where the cursor should be left!
}
}
}