Struct TerminalHandle
pub struct TerminalHandle { /* private fields */ }terminal only.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§
§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>
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();pub 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.
pub fn last_write_elapsed(&self) -> Duration
pub fn last_write_elapsed(&self) -> Duration
Time since the user last wrote input to the PTY.
pub 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.
pub 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.
pub 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.
pub fn scroll(&self, delta: i32)
pub fn scroll(&self, delta: i32)
Scroll by delta. Positive moves up into scrollback (vt100 convention).
pub fn scroll_to_bottom(&self)
pub fn scroll_to_bottom(&self)
Scroll to the bottom of the buffer.
pub fn clipboard_content(&self) -> Option<String>
pub fn clipboard_content(&self) -> Option<String>
Latest clipboard content set via OSC 52.
pub 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.
pub 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.
pub 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.
pub fn release(&self)
pub fn release(&self)
Handle a mouse button release from outside the terminal viewport.
pub 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).
pub fn term(&self) -> Ref<'_, Term<EventProxy>>
pub fn term(&self) -> Ref<'_, Term<EventProxy>>
Borrow the underlying alacritty Term for direct read access.
pub 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.
pub 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).
pub fn clipboard_changed(&self) -> impl Future<Output = ()>
pub fn clipboard_changed(&self) -> impl Future<Output = ()>
Future that completes when clipboard content changes (OSC 52).
pub fn id(&self) -> TerminalId
pub fn id(&self) -> TerminalId
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.
pub 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.
pub fn update_selection(&self, row: f32, col: f32)
pub fn update_selection(&self, row: f32, col: f32)
Extend the in-progress selection, if any.
pub fn get_selected_text(&self) -> Option<String>
pub fn get_selected_text(&self) -> Option<String>
Currently selected text, if any.
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 UnsafeUnpin 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,
§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