Struct TerminalHandle
pub struct TerminalHandle { /* private fields */ }terminal only.Expand description
Handle to a running terminal instance.
The handle allows you to write input to the terminal and resize it. Multiple Terminal components can share the same handle.
The PTY is automatically closed when the handle is dropped.
Implementations§
§impl TerminalHandle
impl TerminalHandle
pub fn new(
id: TerminalId,
command: CommandBuilder,
scrollback_length: Option<usize>,
) -> Result<TerminalHandle, TerminalError>
pub fn new( id: TerminalId, command: CommandBuilder, scrollback_length: Option<usize>, ) -> Result<TerminalHandle, TerminalError>
Create a new terminal with the specified command and default scrollback size (1000 lines).
§Example
use freya_terminal::prelude::*;
use portable_pty::CommandBuilder;
let mut cmd = CommandBuilder::new("bash");
cmd.env("TERM", "xterm-256color");
let handle = TerminalHandle::new(TerminalId::new(), cmd, None).unwrap();pub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
pub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
pub fn scroll(&self, delta: i32)
pub fn scroll(&self, delta: i32)
Scroll the terminal by the specified delta.
§Example
handle.scroll(-3); // Scroll up 3 lines
handle.scroll(3); // Scroll down 3 linespub fn scroll_to_bottom(&self)
pub fn scroll_to_bottom(&self)
pub fn scrollback_position(&self) -> usize
pub fn scrollback_position(&self) -> usize
Get the current scrollback position (scroll offset from buffer).
§Example
let position = handle.scrollback_position();pub fn send_wheel_to_pty(&self, row: usize, col: usize, delta_y: f64)
pub fn send_wheel_to_pty(&self, row: usize, col: usize, delta_y: f64)
Send a wheel event to the PTY.
This sends mouse wheel events as escape sequences to the running process. Uses the currently active mouse protocol encoding based on what the application has requested via DECSET sequences.
pub fn mouse_move(&self, row: usize, col: usize)
pub fn mouse_move(&self, row: usize, col: usize)
Send a mouse move/drag event to the PTY based on the active mouse mode.
AnyMotion(DECSET 1003): sends motion events regardless of button state.ButtonMotion(DECSET 1002): sends motion events only while a button is held.
When dragging, the held button is encoded in the motion event so TUI apps can implement their own text selection.
If shift is held and a button is pressed, updates the text selection instead of sending events to the PTY.
pub fn mouse_down(&self, row: usize, col: usize, button: TerminalMouseButton)
pub fn mouse_down(&self, row: usize, col: usize, button: TerminalMouseButton)
Handle a mouse button press event.
When the running application has enabled mouse tracking (e.g. vim, helix, htop), this sends the press escape sequence to the PTY. Otherwise it starts a text selection.
If shift is held, text selection is always performed regardless of the application’s mouse tracking state.
pub fn mouse_up(&self, row: usize, col: usize, button: TerminalMouseButton)
pub fn mouse_up(&self, row: usize, col: usize, button: TerminalMouseButton)
Handle a mouse button release event.
When the running application has enabled mouse tracking, this sends the
release escape sequence to the PTY. Only PressRelease, ButtonMotion,
and AnyMotion modes receive release events — Press mode does not.
Otherwise it ends the current text selection.
If shift is held, always ends the text selection instead of sending events to the PTY.
pub fn wheel(&self, delta_y: f64, row: usize, col: usize)
pub fn wheel(&self, delta_y: f64, row: usize, col: usize)
Handle a wheel event intelligently.
The behavior depends on the terminal state:
- If viewing scrollback history: scrolls the scrollback buffer.
- If mouse tracking is enabled (e.g., vim, helix): sends wheel escape sequences to the PTY.
- If on the alternate screen without mouse tracking (e.g., gitui, less): sends arrow key sequences to the PTY (alternate scroll mode, like wezterm/kitty/alacritty).
- Otherwise (normal shell): scrolls the scrollback buffer.
pub fn read_buffer(&self) -> Ref<'_, TerminalBuffer>
pub fn read_buffer(&self) -> Ref<'_, TerminalBuffer>
Read the current terminal buffer.
pub fn output_received(&self) -> impl Future<Output = ()>
pub fn output_received(&self) -> impl Future<Output = ()>
Returns a future that completes when new output is received from the PTY.
Can be called repeatedly in a loop to detect ongoing output activity.
pub fn last_write_elapsed(&self) -> Duration
pub fn id(&self) -> TerminalId
pub fn id(&self) -> TerminalId
Returns the unique identifier for this terminal instance.
pub fn shift_pressed(&self, pressed: bool)
pub fn shift_pressed(&self, pressed: bool)
Track whether shift is currently pressed.
This should be called from your key event handlers to track shift state for shift+drag text selection.
pub fn get_selection(&self) -> Option<TerminalSelection>
pub fn get_selection(&self) -> Option<TerminalSelection>
Get the current text selection.
pub fn set_selection(&self, selection: Option<TerminalSelection>)
pub fn set_selection(&self, selection: Option<TerminalSelection>)
Set the text selection.
pub fn start_selection(&self, row: usize, col: usize)
pub fn update_selection(&self, row: usize, col: usize)
pub fn end_selection(&self)
pub fn clear_selection(&self)
pub fn clear_selection(&self)
Clear the current selection.
pub fn get_selected_text(&self) -> Option<String>
Trait Implementations§
§impl Clone for TerminalHandle
impl Clone for TerminalHandle
§fn clone(&self) -> TerminalHandle
fn clone(&self) -> TerminalHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl PartialEq for TerminalHandle
impl PartialEq for TerminalHandle
Auto Trait Implementations§
impl Freeze for TerminalHandle
impl !RefUnwindSafe for TerminalHandle
impl !Send for TerminalHandle
impl !Sync for TerminalHandle
impl Unpin for TerminalHandle
impl !UnwindSafe for TerminalHandle
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ComponentProps for T
impl<T> ComponentProps for T
fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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