Skip to main content

TerminalHandle

Struct TerminalHandle 

Source
pub struct TerminalHandle { /* private fields */ }
Available on crate feature 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

Source

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();
Source

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.

Source

pub fn last_write_elapsed(&self) -> Duration

Time since the user last wrote input to the PTY.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn scroll_to_bottom(&self)

Scroll the terminal to the bottom of the buffer.

Source

pub fn cwd(&self) -> Option<PathBuf>

Get the current working directory reported by the shell via OSC 7.

Source

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

Get the window title reported by the shell via OSC 0 or OSC 2.

Source

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

Get the latest clipboard content set by the terminal app via OSC 52.

Source

pub fn mouse_move(&self, row: usize, col: usize)

Handle a mouse move/drag event based on the active mouse mode.

Source

pub fn mouse_down(&self, row: usize, col: usize, button: TerminalMouseButton)

Handle a mouse button press event.

Source

pub fn mouse_up(&self, row: usize, col: usize, button: TerminalMouseButton)

Handle a mouse button release event.

Source

pub fn release(&self)

Handle a mouse button release from outside the terminal viewport.

Source

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).

Source

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.

Source

pub fn output_received(&self) -> impl Future<Output = ()>

Future that completes each time new output is received from the PTY.

Source

pub fn title_changed(&self) -> impl Future<Output = ()>

Future that completes when the window title changes (OSC 0 / OSC 2).

Source

pub fn clipboard_changed(&self) -> impl Future<Output = ()>

Future that completes when clipboard content changes (OSC 52).

Source

pub fn closed(&self) -> impl Future<Output = ()>

Future that completes when the PTY closes.

Source

pub fn id(&self) -> TerminalId

Returns the unique identifier for this terminal instance.

Source

pub fn shift_pressed(&self, pressed: bool)

Track whether shift is currently pressed.

Source

pub fn start_selection(&self, row: usize, col: usize)

Source

pub fn update_selection(&self, row: usize, col: usize)

Extend the in-progress selection, if any.

Source

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

Source§

fn clone(&self) -> TerminalHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl PartialEq for TerminalHandle

Source§

fn eq(&self, other: &TerminalHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ComponentProps for T
where T: Any + PartialEq,

Source§

fn changed(&self, other: &(dyn ComponentProps + 'static)) -> bool

§

impl<T> Downcast for T
where T: Any,

§

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

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

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

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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<T> IntoReadable<T> for T
where T: 'static,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,