pub struct StepProgram<M: Model> { /* private fields */ }Expand description
Host-driven, non-blocking program runner for WASM.
Wraps a Model and a WebBackend, providing a step-based execution
model suitable for wasm32-unknown-unknown. No threads, no blocking, no
std::time::Instant — all I/O and time are host-driven.
§Lifecycle
StepProgram::new— create with model and initial terminal size.StepProgram::init— call once to initialize the model and render the first frame.StepProgram::step— call repeatedly from the host event loop (e.g.,requestAnimationFrame).- Read outputs after each step via
StepProgram::take_outputs.
Implementations§
Source§impl<M: Model> StepProgram<M>
impl<M: Model> StepProgram<M>
Sourcepub fn new(model: M, width: u16, height: u16) -> Self
pub fn new(model: M, width: u16, height: u16) -> Self
Create a new step program with the given model and initial terminal size.
Sourcepub fn with_backend(model: M, backend: WebBackend) -> Self
pub fn with_backend(model: M, backend: WebBackend) -> Self
Create a step program with an existing WebBackend.
Sourcepub fn init(&mut self) -> Result<(), WebBackendError>
pub fn init(&mut self) -> Result<(), WebBackendError>
Initialize the model and render the first frame.
Must be called exactly once before step.
Calls Model::init(), executes returned commands, and presents
the initial frame.
Sourcepub fn step(&mut self) -> Result<StepResult, WebBackendError>
pub fn step(&mut self) -> Result<StepResult, WebBackendError>
Process one batch of pending events, handle ticks, and render if dirty.
This is the main entry point for the host event loop. Call this after pushing events and advancing time.
Returns StepResult describing what happened during the step.
Sourcepub fn push_event(&mut self, event: Event)
pub fn push_event(&mut self, event: Event)
Push a terminal event into the event queue.
Events are processed on the next step call.
Sourcepub fn advance_time(&mut self, dt: Duration)
pub fn advance_time(&mut self, dt: Duration)
Advance the deterministic clock by dt.
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resize the terminal.
Pushes a Resize event and updates the backend size. The resize
is processed on the next step call.
Sourcepub fn take_outputs(&mut self) -> WebOutputs
pub fn take_outputs(&mut self) -> WebOutputs
Take the captured outputs (rendered buffer, logs), leaving empty defaults.
Sourcepub fn outputs(&self) -> &WebOutputs
pub fn outputs(&self) -> &WebOutputs
Read the captured outputs without consuming them.
Sourcepub fn backend(&self) -> &WebBackend
pub fn backend(&self) -> &WebBackend
Access the backend.
Sourcepub fn backend_mut(&mut self) -> &mut WebBackend
pub fn backend_mut(&mut self) -> &mut WebBackend
Mutably access the backend.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the program is still running.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Whether the program has been initialized.
Sourcepub fn pool(&self) -> &GraphemePool
pub fn pool(&self) -> &GraphemePool
Access the grapheme pool (needed for deterministic checksumming).