pub struct Program<M: Model, E: BackendEventSource<Error = Error>, W: Write + Send = Stdout> { /* private fields */ }Expand description
The program runtime that manages the update/view loop.
Implementations§
Source§impl<M: Model, E: BackendEventSource<Error = Error>, W: Write + Send> Program<M, E, W>
impl<M: Model, E: BackendEventSource<Error = Error>, W: Write + Send> Program<M, E, W>
Sourcepub fn with_event_source(
model: M,
events: E,
backend_features: BackendFeatures,
writer: TerminalWriter<W>,
config: ProgramConfig,
) -> Result<Self>
pub fn with_event_source( model: M, events: E, backend_features: BackendFeatures, writer: TerminalWriter<W>, config: ProgramConfig, ) -> Result<Self>
Create a program with an externally-constructed event source and writer.
This is the generic entry point for alternative backends (native tty,
WASM, headless testing). The caller is responsible for terminal
lifecycle (raw mode, cleanup) — the event source should handle that
via its Drop impl or an external RAII guard.
Source§impl<M: Model, E: BackendEventSource<Error = Error>, W: Write + Send> Program<M, E, W>
impl<M: Model, E: BackendEventSource<Error = Error>, W: Write + Send> Program<M, E, W>
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Run the main event loop.
This is the main entry point. It handles:
- Initialization (terminal setup, raw mode)
- Event polling and message dispatch
- Frame rendering
- Shutdown (terminal cleanup)
Sourcepub fn inject_termination_signal(&self, signal: i32)
pub fn inject_termination_signal(&self, signal: i32)
Record a termination signal for this program instance, as if the OS signal handler had delivered it. The first pending signal wins until the run loop consumes it. Intended for harnesses and tests; interactive programs receive real signals through the installed handler.
Sourcepub fn pending_termination_signal(&self) -> Option<i32>
pub fn pending_termination_signal(&self) -> Option<i32>
The termination signal pending for this program instance, if any.
Sourcepub fn last_widget_signals(&self) -> &[WidgetSignal]
pub fn last_widget_signals(&self) -> &[WidgetSignal]
Access widget scheduling signals captured on the last render.
Sourcepub fn immediate_drain_stats(&self) -> ImmediateDrainStats
pub fn immediate_drain_stats(&self) -> ImmediateDrainStats
Snapshot immediate-drain runtime counters.
Sourcepub fn queue_startup_input(&mut self, bytes: &[u8])
pub fn queue_startup_input(&mut self, bytes: &[u8])
The inner event loop, separated for proper cleanup handling.
Parse raw input bytes (as the tty would have delivered them) into
events that the main loop delivers before it starts polling. Used for
the bytes the startup capability probes read off the tty while
waiting for terminal replies (caps_probe::take_probe_leftover_input).
Sourcepub fn accessibility_tree(&self) -> Option<&A11yTree>
pub fn accessibility_tree(&self) -> Option<&A11yTree>
The accessibility tree built from the last rendered frame, or None
when ProgramConfig::accessibility is unset or nothing has been
rendered yet.
Sourcepub fn accessibility_order(&self) -> &[u64]
pub fn accessibility_order(&self) -> &[u64]
Reading order (node IDs in widget push order) of the last accessibility tree; empty when accessibility is off.
Sourcepub fn accessibility_announcements(&self) -> &[ScreenReaderAnnouncement]
pub fn accessibility_announcements(&self) -> &[ScreenReaderAnnouncement]
Screen-reader announcements derived from the last frame’s tree diff
(bounded by the configured ScreenReaderPolicy); empty when the
tree did not change in an announceable way.
Sourcepub fn accessibility_dump(&self) -> Option<String>
pub fn accessibility_dump(&self) -> Option<String>
Indented, one-node-per-line dump of the last accessibility tree in
reading order (see A11yTree::dump_text); None when off.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the program is running.
Sourcepub const fn tick_rate(&self) -> Option<Duration>
pub const fn tick_rate(&self) -> Option<Duration>
Get the current tick rate, if one has been installed.
Sourcepub const fn executed_cmd_count(&self) -> usize
pub const fn executed_cmd_count(&self) -> usize
Get the number of commands actually executed by the runtime.
Sourcepub fn state_registry(&self) -> Option<&Arc<StateRegistry>>
pub fn state_registry(&self) -> Option<&Arc<StateRegistry>>
Get a reference to the state registry, if configured.
Sourcepub fn has_persistence(&self) -> bool
pub fn has_persistence(&self) -> bool
Check if state persistence is enabled.
Sourcepub fn tick_strategy_stats(&self) -> Vec<(String, String)>
pub fn tick_strategy_stats(&self) -> Vec<(String, String)>
Query the current tick strategy’s debug statistics.
Returns key-value pairs describing the strategy’s internal state (e.g. strategy name, divisors, confidence, transition counts). Returns an empty vec if no tick strategy is configured.
Sourcepub fn trigger_save(&mut self) -> StorageResult<bool>
pub fn trigger_save(&mut self) -> StorageResult<bool>
Trigger a manual save of widget state.
Returns the result of the flush operation, or Ok(false) if
persistence is not configured.
Sourcepub fn trigger_load(&mut self) -> StorageResult<usize>
pub fn trigger_load(&mut self) -> StorageResult<usize>
Trigger a manual load of widget state.
Returns the number of entries loaded, or Ok(0) if persistence
is not configured.
Sourcepub fn request_redraw(&mut self)
pub fn request_redraw(&mut self)
Mark the UI as needing redraw.
Sourcepub fn request_ui_height_remeasure(&mut self)
pub fn request_ui_height_remeasure(&mut self)
Request a re-measure of inline auto UI height on next render.
Sourcepub fn start_recording(&mut self, name: impl Into<String>)
pub fn start_recording(&mut self, name: impl Into<String>)
Start recording events into a macro.
If already recording, the current recording is discarded and a new one starts. The current terminal size is captured as metadata.
Sourcepub fn stop_recording(&mut self) -> Option<InputMacro>
pub fn stop_recording(&mut self) -> Option<InputMacro>
Stop recording and return the recorded macro, if any.
Returns None if not currently recording.
Sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Check if event recording is active.