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 with_registry(self, registry: Arc<StateRegistry>) -> Self
pub fn with_registry(self, registry: Arc<StateRegistry>) -> Self
Attach a StateRegistry for Cmd::SaveState and Cmd::RestoreState commands.
Sourcepub fn set_state_registry(&mut self, registry: Option<Arc<StateRegistry>>)
pub fn set_state_registry(&mut self, registry: Option<Arc<StateRegistry>>)
Set or clear the StateRegistry used by Cmd::SaveState and Cmd::RestoreState.
Sourcepub fn state_registry(&self) -> Option<&Arc<StateRegistry>>
pub fn state_registry(&self) -> Option<&Arc<StateRegistry>>
Access the configured StateRegistry, if any.
Sourcepub fn with_tick_strategy(self, strategy: impl TickStrategy + 'static) -> Self
pub fn with_tick_strategy(self, strategy: impl TickStrategy + 'static) -> Self
Attach a TickStrategy for selective background screen ticking.
Sourcepub fn tick_strategy_name(&self) -> Option<&str>
pub fn tick_strategy_name(&self) -> Option<&str>
Name of the active TickStrategy, if any.
Sourcepub fn with_accessibility(self, policy: ScreenReaderPolicy) -> Self
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.
Sourcepub fn set_accessibility_policy(&mut self, policy: Option<ScreenReaderPolicy>)
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.
Sourcepub fn request_redraw(&mut self)
pub fn request_redraw(&mut self)
Sourcepub fn accessibility_policy(&self) -> Option<ScreenReaderPolicy>
pub fn accessibility_policy(&self) -> Option<ScreenReaderPolicy>
The active accessibility policy, or None when collection is disabled.
Sourcepub fn accessibility_tree(&self) -> Option<&A11yTree>
pub fn accessibility_tree(&self) -> Option<&A11yTree>
Latest finalized tree (empty until rendering), absent when disabled.
Sourcepub fn accessibility_order(&self) -> &[u64]
pub fn accessibility_order(&self) -> &[u64]
Reading order from the latest render, independent of hash-map order.
Sourcepub fn accessibility_announcements(&self) -> &[ScreenReaderAnnouncement]
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.
Sourcepub fn take_accessibility_announcements(&mut self) -> ScreenReaderAnnouncements
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.
Sourcepub fn accessibility_mirror(&self) -> Option<ScreenReaderMirror>
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.
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) -> Result<(), WebBackendError>
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.
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) -> Result<(), WebBackendError>
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.
Sourcepub fn pending_events(&self) -> u32
pub fn pending_events(&self) -> u32
Number of accepted events awaiting processing or explicit recovery.
Sourcepub fn take_pending_events(&mut self) -> Vec<Event>
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.
Sourcepub fn time(&self) -> Duration
pub fn time(&self) -> Duration
Current deterministic clock value, independently of recording timestamps.
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 take_clipboard_requests(&mut self) -> Vec<ClipboardRequest>
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(...)).
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).