Skip to main content

Program

Struct Program 

Source
pub struct Program<M, E, W = Stdout>
where M: Model, E: BackendEventSource<Error = Error>, W: Write + Send,
{ /* private fields */ }
Expand description

The program runtime that manages the update/view loop.

Implementations§

Source§

impl<M> Program<M, CrosstermEventSource>
where M: Model,

Source

pub fn new(model: M) -> Result<Program<M, CrosstermEventSource>, Error>
where <M as Model>::Message: Send + 'static,

Create a new program with default configuration.

Source

pub fn with_config( model: M, config: ProgramConfig, ) -> Result<Program<M, CrosstermEventSource>, Error>
where <M as Model>::Message: Send + 'static,

Create a new program with the specified configuration.

Source§

impl<M, E, W> Program<M, E, W>
where M: Model, E: BackendEventSource<Error = Error>, W: Write + Send,

Source

pub fn with_event_source( model: M, events: E, backend_features: BackendFeatures, writer: TerminalWriter<W>, config: ProgramConfig, ) -> Result<Program<M, E, W>, Error>
where <M as Model>::Message: Send + 'static,

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> Program<M, TtyBackend>
where M: Model,

Source

pub fn with_native_backend( model: M, config: ProgramConfig, ) -> Result<Program<M, TtyBackend>, Error>
where <M as Model>::Message: Send + 'static,

Create a program backed by the native TTY backend (no Crossterm).

This opens a live terminal session via ftui-tty, entering raw mode and enabling the requested features. When the program exits (or panics), TtyBackend::drop() restores the terminal to its original state.

Source§

impl<M, E, W> Program<M, E, W>
where M: Model, E: BackendEventSource<Error = Error>, W: Write + Send,

Source

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

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 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 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) -> Result<bool, StorageError>

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) -> Result<usize, StorageError>

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, W = Stdout> !Freeze for Program<M, E, W>

§

impl<M, E, W = Stdout> !RefUnwindSafe for Program<M, E, W>

§

impl<M, E, W = Stdout> !Send for Program<M, E, W>

§

impl<M, E, W = Stdout> !Sync for Program<M, E, W>

§

impl<M, E, W> Unpin for Program<M, E, W>
where M: Unpin, E: Unpin, W: Unpin,

§

impl<M, E, W> UnsafeUnpin for Program<M, E, W>

§

impl<M, E, W = Stdout> !UnwindSafe for Program<M, E, W>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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