Something went wrong. Try again.
A charm-like tui library
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657const std = @import("std");const tea = @import("root.zig");
const Cmd = tea.Cmd;const Msg = tea.Msg;const View = tea.View;const Io = std.Io;const Init = std.process.Init;const Allocator = std.mem.Allocator;const Writer = std.Io.Writer;
const Model = @This();
vtable: *const VTable,/// Long-lived program allocator. Set by Program before any callback runs./// Use for state that lives across updates (ArrayLists, HashMaps, etc.)./// Equivalent to `process.gpa` — published flat for ergonomics.gpa: Allocator = undefined,/// Per-callback scratch arena. Reset by Program before every callback/// (init/update/view) — allocations are valid only until the callback/// returns. Never store an arena-backed pointer on the model.arena: Allocator = undefined,/// `std.Io` handle, useful for blocking file/process work driven from/// `init`/`update`. Set by Program before any callback runs./// Equivalent to `process.io` — published flat for ergonomics.io: Io = undefined,/// Full process bundle (env vars, argv, preopens, process-permanent arena)./// Set by Program before any callback runs. Use `process.environ_map.get(...)`/// for env lookups, `process.minimal.args` for argv, etc.process: Init = undefined,
pub const VTable = struct { /// Called once at program start. May return an initial Cmd. init: *const fn (model: *Model) ?Cmd,
/// Called for every Msg. May return a follow-up Cmd. update: *const fn (model: *Model, msg: Msg) ?Cmd,
/// Render the current frame. Bytes are written to `w` (a program-owned /// buffer that's reset before each call); the returned `View` carries /// the rest of the frame's metadata. The writer is only valid for the /// duration of this call. view: *const fn (model: *Model, writer: *Writer) anyerror!View,};
pub fn init(self: *Model) ?Cmd { return self.vtable.init(self);}
pub fn update(self: *Model, msg: Msg) ?Cmd { return self.vtable.update(self, msg);}
pub fn view(self: *Model, writer: *Writer) !View { return self.vtable.view(self, writer);}