Terminal

Struct Terminal 

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

Terminal state manager using crossterm for actual terminal control.

This is the primary terminal implementation that provides full terminal control capabilities through the crossterm library. It maintains state to ensure operations are idempotent and efficient.

§State Tracking

The terminal tracks various state flags to avoid unnecessary operations:

  • Raw mode status
  • Alternate screen status
  • Mouse capture status
  • Focus reporting status
  • Cursor visibility

§Performance

  • Uses a pre-allocated render buffer to minimize allocations
  • Tracks state to avoid redundant terminal operations
  • Efficiently handles newline conversion for cross-platform compatibility

§Example

use bubbletea_rs::terminal::{Terminal, TerminalInterface};
use bubbletea_rs::Error;

let mut terminal = Terminal::new(None)?;

// Set up terminal for TUI mode
terminal.enter_raw_mode().await?;
terminal.enter_alt_screen().await?;
terminal.hide_cursor().await?;

// Render some content
terminal.render("Hello, TUI world!").await?;

// Clean up (or rely on Drop)
terminal.show_cursor().await?;
terminal.exit_alt_screen().await?;
terminal.exit_raw_mode().await?;

Implementations§

Source§

impl Terminal

Source

pub fn new( output_writer: Option<Arc<Mutex<dyn AsyncWrite + Send + Unpin>>>, ) -> Result<Self, Error>

Create a new Terminal instance.

If an output_writer is provided, rendering is performed by writing to that asynchronous writer instead of directly to stdout.

Trait Implementations§

Source§

impl Drop for Terminal

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl TerminalInterface for Terminal

Source§

fn new( output_writer: Option<Arc<Mutex<dyn AsyncWrite + Send + Unpin>>>, ) -> Result<Self, Error>
where Self: Sized,

Construct a new terminal implementation. Read more
Source§

fn enter_raw_mode<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable raw mode (disables canonical input processing). Read more
Source§

fn exit_raw_mode<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disable raw mode and restore canonical input processing. Read more
Source§

fn enter_alt_screen<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enter the alternate screen buffer. Read more
Source§

fn exit_alt_screen<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Leave the alternate screen buffer. Read more
Source§

fn enable_mouse<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable basic mouse capture. Read more
Source§

fn enable_mouse_cell_motion<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable cell-motion mouse reporting. Read more
Source§

fn enable_mouse_all_motion<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable high-resolution mouse reporting. Read more
Source§

fn disable_mouse<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disable all mouse capture modes. Read more
Source§

fn enable_focus_reporting<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable terminal focus change reporting. Read more
Source§

fn disable_focus_reporting<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disable terminal focus change reporting. Read more
Source§

fn enable_bracketed_paste<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enable bracketed paste mode. Read more
Source§

fn disable_bracketed_paste<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disable bracketed paste mode. Read more
Source§

fn show_cursor<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Show the cursor if hidden. Read more
Source§

fn hide_cursor<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Hide the cursor if visible. Read more
Source§

fn clear<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear the visible screen contents. Read more
Source§

fn render<'life0, 'life1, 'async_trait>( &'life0 mut self, content: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Render the provided content to the terminal. Read more
Source§

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

Get the current terminal size as (columns, rows). 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.