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§
Source§impl TerminalHandle
impl TerminalHandle
Sourcepub 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();Sourcepub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
pub fn write(&self, data: &[u8]) -> Result<(), TerminalError>
Write data to the PTY, dropping any selection and snapping the viewport back to the bottom so the user sees fresh output.
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>
Translate a key event into the matching terminal escape sequence and write it to the PTY. Returns whether the key 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 running app has enabled them.
Sourcepub fn resize(&self, rows: u16, cols: u16)
pub fn resize(&self, rows: u16, cols: u16)
Resize the terminal. alacritty’s grid reflows on width changes and preserves scrollback on height changes, so this is lossless.
Sourcepub fn scroll(&self, delta: i32)
pub fn scroll(&self, delta: i32)
Scroll the terminal by the specified delta. Positive delta moves the viewport up into scrollback history, matching the vt100 convention.
Sourcepub fn scroll_to_bottom(&self)
pub fn scroll_to_bottom(&self)
Scroll the terminal to the bottom of the buffer.
Sourcepub fn cwd(&self) -> Option<PathBuf>
pub fn cwd(&self) -> Option<PathBuf>
Get the current working directory reported by the shell via OSC 7.
Sourcepub fn title(&self) -> Option<String>
pub fn title(&self) -> Option<String>
Get the window title reported by the shell via OSC 0 or OSC 2.
Sourcepub fn clipboard_content(&self) -> Option<String>
pub fn clipboard_content(&self) -> Option<String>
Get the latest clipboard content set by the terminal app via OSC 52.
Sourcepub fn mouse_move(&self, row: usize, col: usize)
pub fn mouse_move(&self, row: usize, col: usize)
Handle a mouse move/drag event based on the active mouse mode.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn wheel(&self, delta_y: f64, row: usize, col: usize)
pub fn wheel(&self, delta_y: f64, row: usize, col: usize)
Route a wheel event to scrollback, PTY mouse events, or arrow-key sequences depending on whether an app is tracking the mouse and whether we’re on the alternate screen (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. Used
by the renderer and accessibility code to inspect the grid without
holding a separate snapshot.
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 id(&self) -> TerminalId
pub fn id(&self) -> TerminalId
Returns the 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.
pub fn start_selection(&self, row: usize, col: usize)
Sourcepub fn update_selection(&self, row: usize, col: usize)
pub fn update_selection(&self, row: usize, col: usize)
Extend the in-progress selection, if any.
Sourcepub fn get_selected_text(&self) -> Option<String>
pub fn get_selected_text(&self) -> Option<String>
Returns the currently selected text as a string, 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§
§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