pub struct TerminalHandle { /* private fields */ }Expand description
Handle to a running terminal instance.
Multiple Terminal components can share the same handle. The PTY is
closed when the last handle is dropped.
Implementations§
Source§impl TerminalHandle
impl TerminalHandle
Sourcepub fn new(
id: TerminalId,
command: CommandBuilder,
scrollback_length: Option<usize>,
) -> Result<Self, TerminalError>
pub fn new( id: TerminalId, command: CommandBuilder, scrollback_length: Option<usize>, ) -> Result<Self, TerminalError>
Spawn a PTY for command and return a handle. Defaults to 1000 lines
of scrollback when scrollback_length is None.
§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();Sourcepub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
pub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
Write data to the PTY. Drops any selection and snaps the viewport to the bottom.
Sourcepub fn last_write_elapsed(&self) -> Duration
pub fn last_write_elapsed(&self) -> Duration
Time since the user last wrote input to the PTY.
Sourcepub fn write_key(
&self,
key: &Key,
modifiers: Modifiers,
) -> Result<bool, TerminalError>
pub fn write_key( &self, key: &Key, modifiers: Modifiers, ) -> Result<bool, TerminalError>
Write a key event to the PTY as the matching escape sequence. Returns whether it was recognised.
Sourcepub fn paste(&self, text: &str) -> Result<(), TerminalError>
pub fn paste(&self, text: &str) -> Result<(), TerminalError>
Paste text into the PTY, wrapping in bracketed-paste markers if the app enabled them.
Sourcepub fn resize(&self, rows: u16, cols: u16)
pub fn resize(&self, rows: u16, cols: u16)
Resize the terminal. Lossless: the grid reflows on width, preserves scrollback on height.
Sourcepub fn scroll(&self, delta: i32)
pub fn scroll(&self, delta: i32)
Scroll by delta. Positive moves up into scrollback (vt100 convention).
Sourcepub fn scroll_to_bottom(&self)
pub fn scroll_to_bottom(&self)
Scroll to the bottom of the buffer.
Sourcepub fn clipboard_content(&self) -> Option<String>
pub fn clipboard_content(&self) -> Option<String>
Latest clipboard content set via OSC 52.
Sourcepub fn mouse_move(&self, row: f32, col: f32)
pub fn mouse_move(&self, row: f32, col: f32)
Handle a mouse move/drag. row and col are fractional cell units;
the fraction of col picks which cell half anchors the selection.
Sourcepub fn mouse_down(
&self,
row: f32,
col: f32,
button: TerminalMouseButton,
selection_type: SelectionType,
)
pub fn mouse_down( &self, row: f32, col: f32, button: TerminalMouseButton, selection_type: SelectionType, )
Handle a mouse button press. selection_type picks the selection kind when not in mouse mode:
SelectionType::Semantic for double-click (word), SelectionType::Lines for triple-click.
See Self::mouse_move for the fractional coordinates.
Sourcepub fn mouse_up(&self, row: f32, col: f32, button: TerminalMouseButton)
pub fn mouse_up(&self, row: f32, col: f32, button: TerminalMouseButton)
Handle a mouse button release.
Sourcepub fn wheel(&self, delta_y: f64, row: f32, col: f32)
pub fn wheel(&self, delta_y: f64, row: f32, col: f32)
Route a wheel event to scrollback, PTY mouse, or arrow-key sequences depending on the active mouse mode and alt-screen state (matches wezterm/kitty).
Sourcepub fn term(&self) -> Ref<'_, Term<EventProxy>>
pub fn term(&self) -> Ref<'_, Term<EventProxy>>
Borrow the underlying alacritty Term for direct read access.
Sourcepub fn output_received(&self) -> impl Future<Output = ()> + '_
pub fn output_received(&self) -> impl Future<Output = ()> + '_
Future that completes each time new output is received from the PTY.
Sourcepub fn title_changed(&self) -> impl Future<Output = ()> + '_
pub fn title_changed(&self) -> impl Future<Output = ()> + '_
Future that completes when the window title changes (OSC 0 / OSC 2).
Sourcepub fn clipboard_changed(&self) -> impl Future<Output = ()> + '_
pub fn clipboard_changed(&self) -> impl Future<Output = ()> + '_
Future that completes when clipboard content changes (OSC 52).
Sourcepub fn closed(&self) -> impl Future<Output = ()> + '_
pub fn closed(&self) -> impl Future<Output = ()> + '_
Future that completes when the PTY closes.
Sourcepub fn id(&self) -> TerminalId
pub fn id(&self) -> TerminalId
Unique identifier for this terminal instance.
Sourcepub fn shift_pressed(&self, pressed: bool)
pub fn shift_pressed(&self, pressed: bool)
Track whether shift is currently pressed.
Sourcepub fn start_selection(&self, row: f32, col: f32, selection_type: SelectionType)
pub fn start_selection(&self, row: f32, col: f32, selection_type: SelectionType)
Start a new selection of selection_type. See Self::mouse_move for the fractional coordinates.
Sourcepub fn update_selection(&self, row: f32, col: f32)
pub fn update_selection(&self, row: f32, col: f32)
Extend the in-progress selection, if any.
Sourcepub fn get_selected_text(&self) -> Option<String>
pub fn get_selected_text(&self) -> Option<String>
Currently selected text, if any.
Trait Implementations§
Source§impl Clone for TerminalHandle
impl Clone for TerminalHandle
Source§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 moreSource§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 UnsafeUnpin for TerminalHandle
impl !UnwindSafe for TerminalHandle
Blanket Implementations§
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,
§impl<T> ComponentProps for T
impl<T> ComponentProps for T
§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