pub struct PtySession { /* private fields */ }Expand description
A spawned PTY session with captured output.
Implementations§
Source§impl PtySession
impl PtySession
Sourcepub fn read_output(&mut self) -> Vec<u8> ⓘ
pub fn read_output(&mut self) -> Vec<u8> ⓘ
Read any available output without blocking.
Sourcepub fn read_output_result(&mut self) -> Result<Vec<u8>>
pub fn read_output_result(&mut self) -> Result<Vec<u8>>
Read any available output without blocking (fallible).
Sourcepub fn read_until(
&mut self,
pattern: &[u8],
timeout: Duration,
) -> Result<Vec<u8>>
pub fn read_until( &mut self, pattern: &[u8], timeout: Duration, ) -> Result<Vec<u8>>
Read output until a pattern is found or a timeout elapses. Uses bounded retries for transient read errors.
Sourcepub fn read_until_with_options(
&mut self,
pattern: &[u8],
options: ReadUntilOptions,
) -> Result<Vec<u8>>
pub fn read_until_with_options( &mut self, pattern: &[u8], options: ReadUntilOptions, ) -> Result<Vec<u8>>
Read output until a pattern is found, with configurable retry behavior.
This variant supports:
- Bounded retries on transient errors (e.g.,
WouldBlock,Interrupted) - Minimum bytes threshold before pattern matching
- Configurable retry delay
§Example
let options = ReadUntilOptions::with_timeout(Duration::from_secs(5))
.retries(3)
.retry_delay(Duration::from_millis(50))
.min_bytes(10);
let output = session.read_until_with_options(b"ready", options)?;Sourcepub fn send_input(&mut self, bytes: &[u8]) -> Result<()>
pub fn send_input(&mut self, bytes: &[u8]) -> Result<()>
Send input bytes to the child process.
Sourcepub fn wait(&mut self) -> Result<ExitStatus>
pub fn wait(&mut self) -> Result<ExitStatus>
Wait for the child to exit and return its status.
Sourcepub fn drain_remaining(&mut self, timeout: Duration) -> Result<usize>
pub fn drain_remaining(&mut self, timeout: Duration) -> Result<usize>
Drain all remaining output until EOF or timeout.
Call this after wait() to ensure all output from the child process
has been captured. This is important because output may still be in
transit through the PTY after the process exits.
Returns the total number of bytes drained.
Sourcepub fn wait_and_drain(&mut self, drain_timeout: Duration) -> Result<ExitStatus>
pub fn wait_and_drain(&mut self, drain_timeout: Duration) -> Result<ExitStatus>
Wait for the child and drain all remaining output.
This is a convenience method that combines wait() with drain_remaining().
It ensures deterministic capture by waiting for both the child to exit
AND all output to be received.
Trait Implementations§
Source§impl Debug for PtySession
impl Debug for PtySession
Auto Trait Implementations§
impl Freeze for PtySession
impl !RefUnwindSafe for PtySession
impl Send for PtySession
impl !Sync for PtySession
impl Unpin for PtySession
impl UnsafeUnpin for PtySession
impl !UnwindSafe for PtySession
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> 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.