TerminalManager

Struct TerminalManager 

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

Terminal manager that wraps the PTY session

Implementations§

Source§

impl TerminalManager

Source

pub fn new(cols: usize, rows: usize) -> Result<Self>

Create a new terminal manager with the specified dimensions

Source

pub fn new_with_scrollback( cols: usize, rows: usize, scrollback_size: usize, ) -> Result<Self>

Create a new terminal manager with specified dimensions and scrollback size

Source

pub fn set_theme(&mut self, theme: Theme)

Set the color theme

Source

pub fn set_cell_dimensions(&self, width: u32, height: u32)

Set cell dimensions in pixels for sixel graphics scroll calculations

This should be called when the renderer is initialized or cell size changes. Default is (1, 2) for TUI half-block rendering.

Source

pub fn spawn_shell(&mut self) -> Result<()>

Spawn a shell in the terminal

Source

pub fn spawn_custom_shell(&mut self, command: &str) -> Result<()>

Spawn a custom shell command in the terminal

§Arguments
  • command - The shell command to execute (e.g., “/bin/zsh”, “fish”)
Source

pub fn spawn_custom_shell_with_args( &mut self, command: &str, args: &[String], ) -> Result<()>

Spawn a custom shell with arguments

§Arguments
  • command - The shell command to execute
  • args - Arguments to pass to the shell
Source

pub fn spawn_shell_with_dir( &mut self, working_dir: Option<&str>, env_vars: Option<&HashMap<String, String>>, ) -> Result<()>

Spawn shell with optional working directory and environment variables

§Arguments
  • working_dir - Optional working directory path
  • env_vars - Optional environment variables to set
Source

pub fn spawn_custom_shell_with_dir( &mut self, command: &str, args: Option<&[String]>, working_dir: Option<&str>, env_vars: Option<&HashMap<String, String>>, ) -> Result<()>

Spawn custom shell with args, optional working directory, and environment variables

§Arguments
  • command - The shell command to execute
  • args - Arguments to pass to the shell
  • working_dir - Optional working directory path
  • env_vars - Optional environment variables to set
Source

pub fn write(&self, data: &[u8]) -> Result<()>

Write data to the PTY (send user input to shell)

Source

pub fn write_str(&self, data: &str) -> Result<()>

Write string to the PTY

Source

pub fn content(&self) -> Result<String>

Get the terminal content as a string

Source

pub fn resize(&mut self, cols: usize, rows: usize) -> Result<()>

Resize the terminal

Source

pub fn resize_with_pixels( &mut self, cols: usize, rows: usize, width_px: usize, height_px: usize, ) -> Result<()>

Resize the terminal with pixel dimensions This sets both the character dimensions AND pixel dimensions in the PTY winsize struct, which is required for applications like kitty icat that query pixel dimensions via TIOCGWINSZ

Source

pub fn set_pixel_size( &mut self, width_px: usize, height_px: usize, ) -> Result<()>

Set pixel dimensions for XTWINOPS CSI 14 t query support

Source

pub fn dimensions(&self) -> (usize, usize)

Get the current terminal dimensions

Source

pub fn terminal(&self) -> Arc<Mutex<Terminal>>

Get a clone of the underlying terminal for direct access

Source

pub fn has_updates(&self) -> bool

Check if there have been updates since last check

Source

pub fn is_running(&self) -> bool

Check if the PTY is still running

Source

pub fn kill(&mut self) -> Result<()>

Kill the PTY process

Source

pub fn bell_count(&self) -> u64

Get the current bell event count

Source

pub fn scrollback(&self) -> Vec<String>

Get scrollback lines

Source

pub fn scrollback_len(&self) -> usize

Get scrollback length

Source

pub fn clear_scrollback(&self)

Clear scrollback buffer

Removes all scrollback history while preserving the current screen content. Uses CSI 3 J (ED 3) escape sequence which is the standard way to clear scrollback.

Source

pub fn take_notifications(&self) -> Vec<Notification>

Take all pending OSC 9/777 notifications

Source

pub fn has_notifications(&self) -> bool

Check if there are pending OSC 9/777 notifications

Source

pub fn screenshot_to_file( &self, path: &Path, format: &str, scrollback_lines: usize, ) -> Result<()>

Take a screenshot of the terminal and save to file

§Arguments
  • path - Path to save the screenshot
  • format - Screenshot format (“png”, “jpeg”, “svg”, “html”)
  • scrollback_lines - Number of scrollback lines to include (0 for none)
Source

pub fn shell_integration_cwd(&self) -> Option<String>

Get current working directory from shell integration (OSC 7)

Source

pub fn shell_integration_exit_code(&self) -> Option<i32>

Get last command exit code from shell integration (OSC 133)

Source

pub fn shell_integration_command(&self) -> Option<String>

Get current command from shell integration

Source

pub fn get_graphics(&self) -> Vec<TerminalGraphic>

Get all graphics (Sixel, iTerm2, Kitty) Returns a vector of cloned TerminalGraphic objects for rendering

Source

pub fn get_graphics_at_row(&self, row: usize) -> Vec<TerminalGraphic>

Get graphics at a specific row

Source

pub fn graphics_count(&self) -> usize

Get total graphics count

Get all OSC 8 hyperlinks from the terminal

Get the URL for a specific hyperlink ID

Source

pub fn get_scrollback_graphics(&self) -> Vec<TerminalGraphic>

Get all scrollback graphics

Source

pub fn update_animations(&self) -> bool

Update animations and return true if any frames changed

This should be called periodically (e.g., in the redraw loop) to advance animation frames based on timing. Returns true if any animation advanced to a new frame, indicating that a redraw is needed.

Source

pub fn get_graphics_with_animations(&self) -> Vec<TerminalGraphic>

Get all graphics with current animation frames

For animated graphics, returns the current frame based on animation state. For static graphics, returns the original graphic unchanged.

Source

pub fn cursor_position(&self) -> (usize, usize)

Get cursor position

Source

pub fn cursor_style(&self) -> CursorStyle

Get cursor style from terminal for rendering

Source

pub fn is_cursor_visible(&self) -> bool

Check if cursor is visible (controlled by DECTCEM escape sequence)

TUI applications typically hide the cursor when entering alternate screen mode. Returns false when the terminal has received CSI ?25l (hide cursor).

Source

pub fn is_mouse_tracking_enabled(&self) -> bool

Check if mouse tracking is enabled

Source

pub fn is_alt_screen_active(&self) -> bool

Check if alternate screen is active (used by TUI applications)

When the alternate screen is active, text selection should typically be disabled as the content is controlled by an application (vim, htop, etc.) rather than being scrollback history.

Source

pub fn get_title(&self) -> String

Get the terminal title set by OSC 0, 1, or 2 sequences

Returns the title string that applications have set via escape sequences. Returns empty string if no title has been set.

Source

pub fn should_report_mouse_motion(&self, button_pressed: bool) -> bool

Check if mouse motion events should be reported Returns true if mode is ButtonEvent or AnyEvent

Source

pub fn encode_mouse_event( &self, button: u8, col: usize, row: usize, pressed: bool, modifiers: u8, ) -> Vec<u8>

Send a mouse event to the terminal and get the encoded bytes

§Arguments
  • button - Mouse button (0 = left, 1 = middle, 2 = right)
  • col - Column position (0-indexed)
  • row - Row position (0-indexed)
  • pressed - true for press, false for release
  • modifiers - Modifier keys bit mask
§Returns

Encoded mouse event bytes to send to PTY, or empty vec if tracking is disabled

Source

pub fn get_styled_segments(&self) -> Vec<StyledSegment>

Get styled segments from the terminal for rendering

Source

pub fn update_generation(&self) -> u64

Get the current generation number for dirty tracking

The generation number increments whenever the terminal content changes. This can be used to detect when a cached representation needs to be updated.

Source

pub fn get_cells_with_scrollback( &self, scroll_offset: usize, selection: Option<((usize, usize), (usize, usize))>, rectangular: bool, _cursor: Option<((usize, usize), f32)>, ) -> Vec<Cell>

Get terminal grid with scrollback offset as Cell array for CellRenderer

§Arguments
  • scroll_offset - Number of lines to scroll back (0 = current view at bottom)
  • selection - Optional selection range (start_col, start_row, end_col, end_row) in screen coordinates
  • rectangular - Whether the selection is rectangular/block mode (default: false)
  • cursor - Optional cursor (position, opacity) for smooth fade animations
Source§

impl TerminalManager

Source

pub fn get_clipboard_history(&self, slot: ClipboardSlot) -> Vec<ClipboardEntry>

Get clipboard history for a specific slot

Source

pub fn get_latest_clipboard( &self, slot: ClipboardSlot, ) -> Option<ClipboardEntry>

Get the most recent clipboard entry for a slot

Source

pub fn search_clipboard_history( &self, query: &str, slot: Option<ClipboardSlot>, ) -> Vec<ClipboardEntry>

Search clipboard history across all slots or a specific slot

Source

pub fn add_to_clipboard_history( &self, slot: ClipboardSlot, content: String, label: Option<String>, )

Add content to clipboard history

Source

pub fn clear_clipboard_history(&self, slot: ClipboardSlot)

Clear clipboard history for a specific slot

Source

pub fn clear_all_clipboard_history(&self)

Clear all clipboard history

Source

pub fn set_max_clipboard_sync_events(&self, max: usize)

Set maximum clipboard sync events retained

Source

pub fn set_max_clipboard_event_bytes(&self, max_bytes: usize)

Set maximum bytes cached per clipboard event

Source

pub fn set_max_clipboard_sync_history(&self, max: usize)

Set maximum clipboard history entries per slot

Trait Implementations§

Source§

impl Drop for TerminalManager

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> 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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,