Struct PtyHandle

Source
pub struct PtyHandle { /* private fields */ }
Expand description

Clonable, thread-safe capability for one erased PTY session.

Clones share the same session, event queue, locks, and shutdown state. Dropping a handle is not specified to terminate the child; call Self::shutdown when deterministic termination is required. Method blocking and event ordering are backend-specific.

§Examples

use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyError, PtySpawnConfig};
let handle = MockPtyBackend::default().spawn(PtySpawnConfig::default()).unwrap();
let clone = handle.clone(); handle.shutdown().unwrap();
assert_eq!(clone.write(b"closed"), Err(PtyError::Closed));

Implementations§

Source§

impl PtyHandle

Source

pub fn write(&self, bytes: &[u8]) -> Result<(), PtyError>

Writes raw input bytes through the backend.

Bytes are not decoded or normalized; an empty slice is passed through. Closed sessions return PtyError::Closed in the included backends. The portable backend serializes writes and flushes after each call.

§Errors

Propagates PtyError::Closed and the backend’s categorized write, flush, locking, I/O, or unsupported-operation failures.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let backend = MockPtyBackend::default();
let handle = backend.spawn(PtySpawnConfig::default()).unwrap();
handle.write(b"ls\r").unwrap();
assert_eq!(backend.writes(), vec![b"ls\r".to_vec()]);
Source

pub fn resize(&self, size: PtySize) -> Result<(), PtyError>

Requests a backend resize using the supplied dimensions.

The mock records fields verbatim, including public zero rows/columns; the portable adapter clamps those two dimensions to one before OS I/O.

§Errors

Propagates PtyError::Closed and the backend’s categorized resize, locking, I/O, or unsupported-operation failures.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySize, PtySpawnConfig};
let backend = MockPtyBackend::default();
backend.spawn(PtySpawnConfig::default()).unwrap().resize(PtySize::new(40, 120, 0, 0)).unwrap();
assert_eq!(backend.resizes()[0].cols, 120);
Source

pub fn drain_events(&self) -> Vec<PtyEvent>

Atomically removes and returns all events currently queued by the backend.

A later producer may enqueue events immediately after the drain. Included implementations preserve mutex-enqueue order, but the portable reader, batcher, and waiter threads can race. Draining remains allowed after shutdown.

§Panics

Included backends panic if their shared event/mock mutex is poisoned.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtyEvent, PtySpawnConfig};
let backend = MockPtyBackend::default(); backend.push_event(PtyEvent::Output(b"x".to_vec()));
let handle = backend.spawn(PtySpawnConfig::default()).unwrap();
assert_eq!(handle.drain_events().len(), 1);
assert!(handle.drain_events().is_empty());
Source

pub fn shutdown(&self) -> Result<(), PtyError>

Requests idempotent backend termination.

In the portable backend the shutdown flag is set before acquiring the killer or calling kill; a returned failure therefore still leaves the handle closed, and later calls return success without retrying the kill. This does not join detached reader/batcher/wait threads.

§Errors

Propagates a backend termination, killer-lock, I/O, or unsupported-operation failure. An error does not reopen the handle.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let handle = MockPtyBackend::default().spawn(PtySpawnConfig::default()).unwrap();
handle.shutdown().unwrap(); handle.shutdown().unwrap();
assert!(handle.is_shutdown());
Source

pub fn is_shutdown(&self) -> bool

Returns the backend’s shutdown observation.

For the portable backend, true means shutdown was requested or the wait thread completed; it does not mean all detached threads were joined or all final events were drained.

§Examples
use ailloli_ui_terminal_pty::{MockPtyBackend, PtyBackend, PtySpawnConfig};
let handle = MockPtyBackend::default().spawn(PtySpawnConfig::default()).unwrap();
assert!(!handle.is_shutdown());

Trait Implementations§

Source§

impl Clone for PtyHandle

Source§

fn clone(&self) -> PtyHandle

Returns a copy 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 Debug for PtyHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats only the shutdown observation and marks future fields non-exhaustive.

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

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

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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