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
impl PtyHandle
Sourcepub fn write(&self, bytes: &[u8]) -> Result<(), PtyError>
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()]);Sourcepub fn resize(&self, size: PtySize) -> Result<(), PtyError>
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);Sourcepub fn drain_events(&self) -> Vec<PtyEvent>
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());Sourcepub fn shutdown(&self) -> Result<(), PtyError>
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());Sourcepub fn is_shutdown(&self) -> bool
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§
Auto Trait Implementations§
impl Freeze for PtyHandle
impl !RefUnwindSafe for PtyHandle
impl Send for PtyHandle
impl Sync for PtyHandle
impl Unpin for PtyHandle
impl !UnwindSafe for PtyHandle
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> 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.