Skip to main content

Module program

Module program 

Source
Expand description

Bubbletea/Elm-style runtime for terminal applications.

The program runtime manages the update/view loop, handling events and rendering frames. It separates state (Model) from rendering (View) and provides a command pattern for side effects.

§Example

use ftui_runtime::program::{Model, Cmd};
use ftui_core::event::Event;
use ftui_render::frame::Frame;

struct Counter {
    count: i32,
}

enum Msg {
    Increment,
    Decrement,
    Quit,
}

impl From<Event> for Msg {
    fn from(event: Event) -> Self {
        match event {
            Event::Key(k) if k.is_char('q') => Msg::Quit,
            Event::Key(k) if k.is_char('+') => Msg::Increment,
            Event::Key(k) if k.is_char('-') => Msg::Decrement,
            _ => Msg::Increment, // Default
        }
    }
}

impl Model for Counter {
    type Message = Msg;

    fn update(&mut self, msg: Self::Message) -> Cmd<Self::Message> {
        match msg {
            Msg::Increment => { self.count += 1; Cmd::none() }
            Msg::Decrement => { self.count -= 1; Cmd::none() }
            Msg::Quit => Cmd::quit(),
        }
    }

    fn view(&self, frame: &mut Frame) {
        // Render counter value to frame
    }
}

Structs§

App
Builder for creating and running programs.
AppBuilder
Builder for configuring and running programs.
BatchController
Adaptive batch window controller based on M/G/1 queueing model.
EffectQueueConfig
Configuration for effect queue scheduling.
FrameTiming
Per-frame timing data for profiling.
FrameTimingConfig
Configuration for frame timing capture.
InlineAutoRemeasureConfig
Policy for remeasuring inline auto UI height.
PersistenceConfig
Configuration for state persistence in the program runtime.
Program
The program runtime that manages the update/view loop.
ProgramConfig
Configuration for the program runtime.
TaskSpec
Scheduling metadata for background tasks.
WidgetRefreshConfig
Configuration for widget refresh selection under render budget.

Enums§

Cmd
Commands represent side effects to be executed by the runtime.
ResizeBehavior
Resize handling behavior for the runtime.

Traits§

FrameTimingSink
Sink for frame timing events.
Model
The Model trait defines application state and behavior.