pub struct PtyHandle { /* private fields */ }Expand description
Handle to one pane’s PTY. The master side is held inside an
Arc<Mutex<...>> so the reader thread and the writer thread (or
send_keys caller) can share it. The child process handle is
retained so Drop can explicitly kill() it — without this,
dropping the master Arc doesn’t kill the shell (the reader
thread holds a cloned master fd that keeps the slave open),
shells accumulate as orphans, and every subsequent fork copies
a bloated address space.
Implementations§
Source§impl PtyHandle
impl PtyHandle
Sourcepub fn spawn(
shell: &str,
args: &[String],
cwd: Option<&str>,
env: &[(String, String)],
size: PtySize,
on_bytes: Box<dyn FnMut(&[u8]) + Send>,
on_exit: Box<dyn FnOnce(Option<i32>) + Send>,
) -> Result<Self>
pub fn spawn( shell: &str, args: &[String], cwd: Option<&str>, env: &[(String, String)], size: PtySize, on_bytes: Box<dyn FnMut(&[u8]) + Send>, on_exit: Box<dyn FnOnce(Option<i32>) + Send>, ) -> Result<Self>
Spawn a child process attached to a freshly minted PTY pair.
The caller provides a sink for child bytes — typically a
Box<dyn FnMut(&[u8]) + Send> that feeds into a vte parser
or appends to a scrollback grid. The reader thread loops on
master.try_clone_reader() until EOF, calling the sink on
each read.
on_exit is the typed end-of-stream notification: when the
reader loop ends (PTY EOF because the child exited, or a read
error), the reader thread reaps the child to capture its exit
code, then calls on_exit(code) exactly once. code is
None only when the child was already reaped elsewhere (the
explicit-kill path, where Drop took the child first) or
wait() failed. This is the single edge that lets the
multiplexer mark the pane exited and disconnect its byte-stream
subscribers; without it a reader thread that hit EOF would just
end silently and every subscriber would block forever.
Sourcepub fn resize(&self, size: PtySize) -> Result<()>
pub fn resize(&self, size: PtySize) -> Result<()>
Resize the PTY winsize. Causes SIGWINCH delivery to the child.
Sourcepub fn bytes_consumed(&self) -> u64
pub fn bytes_consumed(&self) -> u64
Total bytes consumed by the pane’s parser since spawn.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PtyHandle
impl !UnwindSafe for PtyHandle
impl Freeze for PtyHandle
impl Send for PtyHandle
impl Sync for PtyHandle
impl Unpin for PtyHandle
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.