Skip to main content

Program

Struct Program 

Source
pub struct Program<M: Model, E: BackendEventSource<Error = Error>, P: BackendPresenter<Error = Error> = TerminalPresenter<Stdout>> { /* private fields */ }
Expand description

The program runtime that manages the update/view loop.

Implementations§

Source§

impl<M: Model> Program<M, HeadlessEventSource, TerminalPresenter<Vec<u8>>>

Source

pub fn new_headless(model: M, config: ProgramConfig) -> Result<Self>

Construct a headless program backed by an in-memory TerminalPresenter<Vec<u8>>.

Source§

impl<M: Model, P: BackendPresenter<Error = Error>> Program<M, HeadlessEventSource, P>

Source

pub fn step_headless_frame(&mut self) -> Result<()>

Step a single headless frame through the full budget, conformal, render, present, and evidence pipeline.

Source

pub fn init_headless(&mut self, task_timeout: Duration) -> Result<()>

Initialize the model, execute its initial command, drain any spawned background tasks, and render the initial frame.

Source

pub fn enqueue_headless_event(&mut self, event: Event) -> Result<()>

Deliver a single event to the headless program and submit any resulting commands without waiting for background tasks to drain or rendering.

Source

pub fn step_headless_event( &mut self, event: Event, task_timeout: Duration, ) -> Result<()>

Deliver a single event to the headless program, drain all resulting background tasks up to task_timeout, and render if dirty.

Source

pub fn drain_headless_tasks(&mut self, timeout: Duration) -> Result<()>

Drain all in-flight background tasks on the active task executor up to timeout.

Source

pub fn task_backend_name(&self) -> &'static str

Return the active task executor backend label ("spawned", "queued", or "asupersync").

Source

pub fn resolved_runtime_lane(&self) -> RuntimeLane

Return the resolved runtime lane.

Source§

impl<M: Model, E: BackendEventSource<Error = Error>, P: BackendPresenter<Error = Error>> Program<M, E, P>

Source

pub fn with_event_source( model: M, events: E, backend_features: BackendFeatures, presenter: P, config: ProgramConfig, ) -> Result<Self>
where M::Message: Send + 'static,

Create a program with an externally-constructed event source and presenter.

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>, P: BackendPresenter<Error = Error>> Program<M, E, P>

Source

pub fn run(&mut self) -> Result<()>

Run the main event loop.

This is the main entry point. It handles:

  1. Initialization (terminal setup, raw mode)
  2. Event polling and message dispatch
  3. Frame rendering
  4. Shutdown (terminal cleanup)
Source

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.

Source

pub fn inject_suspend_signal(&self, signal: i32)

Request a job-control stop for this program instance, as if signal (SIGTSTP, SIGTTIN or SIGTTOU) had been delivered. The run loop hands the terminal back, stops the process and restores the terminal when it is continued. Ignored unless job control is enabled and the event source supports suspend.

Source

pub fn pending_termination_signal(&self) -> Option<i32>

The termination signal pending for this program instance, if any.

Source

pub fn last_widget_signals(&self) -> &[WidgetSignal]

Access widget scheduling signals captured on the last render.

Source

pub fn immediate_drain_stats(&self) -> ImmediateDrainStats

Snapshot immediate-drain runtime counters.

Source

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).

Source

pub fn flush_coalesced_events(&mut self) -> Result<()>

Flush any pending coalesced input events to the model.

Source

pub fn event_coalescer(&self) -> Option<&EventCoalescer>

Access the event coalescer, if enabled.

Source

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.

Source

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

Reading order (node IDs in widget push order) of the last accessibility tree; empty when accessibility is off.

Source

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.

Source

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.

Source

pub fn model(&self) -> &M

Get a reference to the model.

Source

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

Get a mutable reference to the model.

Source

pub fn is_running(&self) -> bool

Check if the program is running.

Source

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

Get the current tick rate, if one has been installed.

Source

pub const fn executed_cmd_count(&self) -> usize

Get the number of commands actually executed by the runtime.

Source

pub fn quit(&mut self)

Request a quit.

Source

pub fn state_registry(&self) -> Option<&Arc<StateRegistry>>

Get a reference to the state registry, if configured.

Source

pub fn has_persistence(&self) -> bool

Check if state persistence is enabled.

Source

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.

Source

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.

Source

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.

Source

pub fn request_redraw(&mut self)

Mark the UI as needing redraw.

Source

pub fn request_ui_height_remeasure(&mut self)

Request a re-measure of inline auto UI height on next render.

Source

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.

Source

pub fn stop_recording(&mut self) -> Option<InputMacro>

Stop recording and return the recorded macro, if any.

Returns None if not currently recording.

Source

pub fn is_recording(&self) -> bool

Check if event recording is active.

Auto Trait Implementations§

§

impl<M, E, P = TerminalPresenter> !Freeze for Program<M, E, P>

§

impl<M, E, P = TerminalPresenter> !RefUnwindSafe for Program<M, E, P>

§

impl<M, E, P = TerminalPresenter> !Send for Program<M, E, P>

§

impl<M, E, P = TerminalPresenter> !Sync for Program<M, E, P>

§

impl<M, E, P = TerminalPresenter> !UnwindSafe for Program<M, E, P>

§

impl<M, E, P> Forget for Program<M, E, P>

§

impl<M, E, P> Move for Program<M, E, P>

§

impl<M, E, P> Unpin for Program<M, E, P>
where P: Unpin, E: Unpin, M: Unpin, SubscriptionManager<<M as Model>::Message>: Unpin, Receiver<<M as Model>::Message>: Unpin, TaskExecutor<<M as Model>::Message>: Unpin,

§

impl<M, E, P> UnsafeUnpin for Program<M, E, P>
where M: UnsafeUnpin, P: UnsafeUnpin, E: UnsafeUnpin, SubscriptionManager<<M as Model>::Message>: UnsafeUnpin, Receiver<<M as Model>::Message>: UnsafeUnpin, TaskExecutor<<M as Model>::Message>: UnsafeUnpin,

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