Skip to main content

Program

Struct Program 

Source
pub struct Program<M: Model> { /* private fields */ }
Expand description

The main program runner.

Program manages the entire lifecycle of a TUI application:

  • Terminal setup and teardown
  • Event polling and message dispatching
  • Frame-rate limited rendering

§Example

use bubbletea::Program;

let model = MyModel::new();
let final_model = Program::new(model)
    .with_alt_screen()
    .run()?;

Implementations§

Source§

impl<M: Model> Program<M>

Source

pub fn new(model: M) -> Self

Create a new program with the given model.

Source

pub fn with_input_receiver(self, rx: Receiver<Message>) -> Self

Provide an external message receiver.

Messages received on this channel will be forwarded to the program’s event loop. This is useful for injecting events from external sources (e.g. SSH).

Source

pub fn with_input<R: Read + Send + 'static>(self, input: R) -> Self

Provide a custom input reader.

This enables custom I/O mode and reads raw bytes from the given reader, translating them into Bubbletea messages.

Source

pub fn with_output<W: Write + Send + 'static>(self, output: W) -> Self

Provide a custom output writer.

This enables custom I/O mode and writes render output to the given writer.

Source

pub fn with_alt_screen(self) -> Self

Use alternate screen buffer (full-screen mode).

Source

pub fn with_mouse_cell_motion(self) -> Self

Enable mouse cell motion tracking.

Reports mouse clicks and drags.

Source

pub fn with_mouse_all_motion(self) -> Self

Enable mouse all motion tracking.

Reports all mouse movement, even without button presses.

Source

pub fn with_fps(self, fps: u32) -> Self

Set the target frames per second.

Default is 60 FPS. Valid range is 1-120 FPS.

Source

pub fn with_report_focus(self) -> Self

Enable focus reporting.

Sends FocusMsg and BlurMsg when terminal gains/loses focus.

Source

pub fn without_bracketed_paste(self) -> Self

Disable bracketed paste mode.

Source

pub fn without_signal_handler(self) -> Self

Disable signal handling.

Source

pub fn without_catch_panics(self) -> Self

Don’t catch panics.

Source

pub fn with_custom_io(self) -> Self

Enable custom I/O mode (skip terminal setup and crossterm polling).

This is useful when embedding bubbletea in environments that manage terminal state externally or when events are injected manually.

Source

pub fn run_with_writer<W: Write + Send + 'static>(self, writer: W) -> Result<M>

Run the program with a custom writer.

Source

pub fn run(self) -> Result<M>

Run the program and return the final model state.

Source

pub fn start(self) -> ProgramHandle<M>

Start the program in a background thread and return a handle for interaction.

This is useful for SSH applications and other scenarios where you need to inject events from external sources after the program has started.

§Example
use bubbletea::{Program, Message};

let handle = Program::new(MyModel::default())
    .with_custom_io()
    .start();

// Inject a key event
handle.send(KeyMsg::from_char('a'));

// Later, quit the program
handle.quit();

// Wait for completion
let final_model = handle.wait()?;

Auto Trait Implementations§

§

impl<M> Freeze for Program<M>
where M: Freeze,

§

impl<M> !RefUnwindSafe for Program<M>

§

impl<M> Send for Program<M>

§

impl<M> !Sync for Program<M>

§

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

§

impl<M> !UnwindSafe for Program<M>

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<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, 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<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