Skip to main content

TtyBackend

Struct TtyBackend 

Source
pub struct TtyBackend { /* private fields */ }
Expand description

Native Unix terminal backend.

Combines TtyClock, TtyEventSource, and TtyPresenter into a single Backend implementation that the ftui runtime can drive.

When created with TtyBackend::open, the backend enters raw mode and manages the terminal lifecycle via RAII. On drop (including panics), all features are disabled, the cursor is shown, the alt screen is exited, and raw mode is restored — in that order.

When created with TtyBackend::new (headless), no terminal I/O occurs.

Implementations§

Source§

impl TtyBackend

Source

pub fn new(width: u16, height: u16) -> Self

Create a headless backend (no terminal I/O). Useful for testing.

Source

pub fn with_capabilities( width: u16, height: u16, capabilities: TerminalCapabilities, ) -> Self

Create a headless backend with explicit capabilities.

Source

pub fn open(width: u16, height: u16, options: TtySessionOptions) -> Result<Self>

Open a live terminal session: enter raw mode, enable requested features.

The terminal is fully restored on drop (even during panics, unless panic = "abort").

Source

pub fn is_live(&self) -> bool

Whether this backend has an active terminal session (raw mode).

Trait Implementations§

Source§

impl Backend for TtyBackend

Source§

type Error = Error

Platform-specific error type shared across sub-traits.
Source§

type Clock = TtyClock

Clock implementation.
Source§

type Events = TtyEventSource

Event source implementation.
Source§

type Presenter = TtyPresenter

Presenter implementation.
Source§

fn clock(&self) -> &Self::Clock

Access the monotonic clock.
Source§

fn events(&mut self) -> &mut Self::Events

Access the event source (mutable for polling/reading).
Source§

fn presenter(&mut self) -> &mut Self::Presenter

Access the presenter (mutable for rendering).
Source§

impl BackendEventSource for TtyBackend

Allow TtyBackend to be used directly as a BackendEventSource in Program<M, TtyBackend, W>. Delegates to the inner TtyEventSource. This is the primary integration point: the runtime owns a TtyBackend as its event source, which also provides RAII terminal cleanup on drop.

Source§

type Error = Error

Platform-specific error type.
Source§

fn size(&self) -> Result<(u16, u16), Error>

Query current terminal dimensions (columns, rows).
Source§

fn set_features(&mut self, features: BackendFeatures) -> Result<(), Error>

Enable or disable terminal features (mouse, paste, focus, kitty keyboard). Read more
Source§

fn poll_event(&mut self, timeout: Duration) -> Result<bool, Error>

Poll for an available event, returning true if one is ready. Read more
Source§

fn read_event(&mut self) -> Result<Option<Event>, Error>

Read the next available event, or None if none is ready. Read more
Source§

impl Drop for TtyBackend

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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