pub struct WasmRunner<M: Model> { /* private fields */ }Expand description
Step-based program runner for WASM (no threads, no blocking).
Accepts an ftui Model and drives it through explicit step / render
calls controlled by the JavaScript host.
Implementations§
Source§impl<M: Model> WasmRunner<M>
impl<M: Model> WasmRunner<M>
Sourcepub fn new(model: M, width: u16, height: u16) -> Self
pub fn new(model: M, width: u16, height: u16) -> Self
Create a new runner with the given model and initial grid size.
The model is not initialized until init is called.
Sourcepub fn init(&mut self) -> StepResult
pub fn init(&mut self) -> StepResult
Initialize the model by calling Model::init().
Must be called exactly once before step / render. Returns the
result of executing the init command.
Sourcepub fn push_event(&mut self, event: Event)
pub fn push_event(&mut self, event: Event)
Buffer a single event for processing on the next step.
Sourcepub fn push_events(&mut self, events: impl IntoIterator<Item = Event>)
pub fn push_events(&mut self, events: impl IntoIterator<Item = Event>)
Buffer multiple events for processing on the next step.
Sourcepub fn step(&mut self, now: Duration) -> StepResult
pub fn step(&mut self, now: Duration) -> StepResult
Process all buffered events and fire a tick if due.
now is the monotonic timestamp from the host clock (e.g.
performance.now() converted to Duration).
Returns a StepResult summarizing what happened.
Sourcepub fn step_event(&mut self, event: Event) -> StepResult
pub fn step_event(&mut self, event: Event) -> StepResult
Process a single event immediately (without buffering).
Sourcepub fn render(&mut self) -> Option<RenderedFrame<'_>>
pub fn render(&mut self) -> Option<RenderedFrame<'_>>
Render the current frame if dirty.
Returns Some(RenderedFrame) with the buffer and optional diff, or
None if the view is clean (no events since last render).
Sourcepub fn force_render(&mut self) -> RenderedFrame<'_>
pub fn force_render(&mut self) -> RenderedFrame<'_>
Render the current frame unconditionally.
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resize the grid. Marks the view dirty and invalidates the diff baseline.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the program is still running (no Cmd::Quit received).
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Whether init() has been called.
Sourcepub fn pending_events(&self) -> usize
pub fn pending_events(&self) -> usize
Number of buffered events awaiting processing.
Sourcepub fn drain_logs(&mut self) -> Vec<String>
pub fn drain_logs(&mut self) -> Vec<String>
Drain and return accumulated log messages.
Sourcepub fn current_buffer(&self) -> &Buffer
pub fn current_buffer(&self) -> &Buffer
Reference to the most recently rendered buffer.