Files
tui-website/src/content.zig

60 lines
1.7 KiB
Zig

pub fn Content(App: type) type {
return struct {
pub fn init(allocator: Allocator) @This() {
_ = allocator;
return .{};
}
pub fn element(this: *@This()) App.Element {
return .{
.ptr = this,
.vtable = &.{
.handle = handle,
.content = content,
},
};
}
fn handle(ctx: *anyopaque, model: *App.Model, event: App.Event) !void {
_ = ctx;
switch (event) {
.about => model.page = .about,
.blog => model.page = .blog,
else => {},
}
}
fn content(ctx: *anyopaque, model: *const App.Model, cells: []zterm.Cell, size: zterm.Point) !void {
_ = ctx;
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
const text = switch (model.page) {
.about => @embedFile("about"),
.blog => @embedFile("blog"),
};
var index: usize = 0;
for (0..size.y) |row| {
for (0..size.x) |col| {
const cell = row * size.x + col;
assert(cell < cells.len);
if (index == text.len) return;
const cp = text[index];
index += 1;
cells[cell].cp = switch (cp) {
'\n' => break,
else => cp,
};
}
}
}
};
}
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const zterm = @import("zterm");