Skip to main content

StepProgram

Struct StepProgram 

Source
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

  1. StepProgram::new — create with model and initial terminal size.
  2. StepProgram::init — call once to initialize the model and render the first frame.
  3. StepProgram::step — call repeatedly from the host event loop (e.g., requestAnimationFrame).
  4. Read outputs after each step via StepProgram::take_outputs.

Implementations§

Source§

impl<M: Model> StepProgram<M>

Source

pub fn new(model: M, width: u16, height: u16) -> Self

Create a new step program with the given model and initial terminal size.

Source

pub fn with_backend(model: M, backend: WebBackend) -> Self

Create a step program with an existing WebBackend.

Source

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.

Source

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.

Source

pub fn push_event(&mut self, event: Event)

Push a terminal event into the event queue.

Events are processed on the next step call.

Source

pub fn advance_time(&mut self, dt: Duration)

Advance the deterministic clock by dt.

Source

pub fn set_time(&mut self, now: Duration)

Set the deterministic clock to an absolute time.

Source

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.

Source

pub fn take_outputs(&mut self) -> WebOutputs

Take the captured outputs (rendered buffer, logs), leaving empty defaults.

Source

pub fn outputs(&self) -> &WebOutputs

Read the captured outputs without consuming them.

Source

pub fn model(&self) -> &M

Access the model.

Source

pub fn model_mut(&mut self) -> &mut M

Mutably access the model.

Source

pub fn backend(&self) -> &WebBackend

Access the backend.

Source

pub fn backend_mut(&mut self) -> &mut WebBackend

Mutably access the backend.

Source

pub fn is_running(&self) -> bool

Whether the program is still running.

Source

pub fn is_initialized(&self) -> bool

Whether the program has been initialized.

Source

pub fn frame_idx(&self) -> u64

Current frame index.

Source

pub fn size(&self) -> (u16, u16)

Current terminal dimensions.

Source

pub fn tick_rate(&self) -> Option<Duration>

Current tick rate, if any.

Source

pub fn pool(&self) -> &GraphemePool

Access the grapheme pool (needed for deterministic checksumming).

Auto Trait Implementations§

§

impl<M> Freeze for StepProgram<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for StepProgram<M>
where M: RefUnwindSafe,

§

impl<M> Send for StepProgram<M>
where M: Send,

§

impl<M> Sync for StepProgram<M>
where M: Sync,

§

impl<M> Unpin for StepProgram<M>
where M: Unpin,

§

impl<M> UnwindSafe for StepProgram<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more