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 with_accessibility(self, policy: ScreenReaderPolicy) -> Self

Enable the local accessibility channel, normally before init.

A host should choose either its model callback or the drain accessor for speech delivery, not forward both copies of the same transition.

Source

pub fn set_accessibility_policy(&mut self, policy: Option<ScreenReaderPolicy>)

Enable, update, or disable accessibility collection at runtime.

Disabling immediately releases the previous tree, reading order and undrained announcements. Re-enabling builds a fresh baseline on the next rendered step. Changing limits while enabled preserves the tree baseline so it does not fabricate another focus arrival. Passing the unchanged policy is a no-op, including for undrained announcements.

Source

pub fn request_redraw(&mut self)

Schedule a repaint for the next step.

Only an event, a tick or an accessibility-policy change marks the frame stale. A host that reaches the model another way — model_mut to select a screen, say — leaves nothing to render, and step reports rendered: false until something else happens to arrive.

Source

pub fn accessibility_policy(&self) -> Option<ScreenReaderPolicy>

The active accessibility policy, or None when collection is disabled.

Source

pub fn accessibility_tree(&self) -> Option<&A11yTree>

Latest finalized tree (empty until rendering), absent when disabled.

Source

pub fn accessibility_order(&self) -> &[u64]

Reading order from the latest render, independent of hash-map order.

Source

pub fn accessibility_announcements(&self) -> &[ScreenReaderAnnouncement]

Announcements from the latest rendered frame, unless already drained.

Rendering an unchanged tree clears this batch. An idle step that does not render leaves it alone. Use the drain accessor for at-most-once forwarding rather than replaying this slice on every animation tick.

Source

pub fn take_accessibility_announcements(&mut self) -> ScreenReaderAnnouncements

Drain the latest frame’s bounded batch without consuming visual output.

Call after init and after each rendered step. This is a per-frame channel, not an unbounded queue of old speech: a subsequent render replaces any undrained batch. dropped_count reports the current frame’s policy-cap drops, not missed host reads. A second drain returns an empty batch with zero drops. The model callback sees the batch before the host can drain it; hosts must avoid forwarding both channels.

Source

pub fn accessibility_mirror(&self) -> Option<ScreenReaderMirror>

A bounded, deterministic mirror of the latest tree for a host bridge.

Mirror text is not a live-region announcement. Hosts should expose it for navigation without automatically speaking the entire tree on every update. Native semantic bridges should not replay equivalent text too.

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) -> Result<(), WebBackendError>

Push a terminal event into the event queue.

Accepted events are processed on the next step call. Rejection leaves the queue and backend size unchanged. Capacity errors return the event; a stopped program rejects further input as unsupported.

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) -> Result<(), WebBackendError>

Resize the terminal.

Pushes a Resize event and updates the backend size. The resize is processed on the next step call.

Source

pub fn pending_events(&self) -> u32

Number of accepted events awaiting processing or explicit recovery.

Source

pub fn take_pending_events(&mut self) -> Vec<Event>

Recover queued events in FIFO order without executing their effects.

After quit, the host can retain this tail for inspection or another session. Taking pending input cancels any queued resize request and restores the backend’s requested size to the last processed geometry.

Source

pub fn time(&self) -> Duration

Current deterministic clock value, independently of recording timestamps.

Source

pub fn take_outputs(&mut self) -> WebOutputs

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

Source

pub fn take_clipboard_requests(&mut self) -> Vec<ClipboardRequest>

Drain clipboard effects for the host’s clipboard API. Successful reads should be returned through push_event(Event::Clipboard(...)).

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> UnsafeUnpin for StepProgram<M>
where M: UnsafeUnpin,

§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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