pub struct PtyProcess { /* private fields */ }Expand description
A managed PTY process for shell interaction.
§Example
use ftui_pty::pty_process::{PtyProcess, ShellConfig};
use std::time::Duration;
let config = ShellConfig::default()
.inherit_env()
.size(80, 24);
let mut proc = PtyProcess::spawn(config)?;
// Send a command
proc.write_all(b"echo hello\n")?;
// Read output
let output = proc.read_until(b"hello", Duration::from_secs(5))?;
// Check if still alive
assert!(proc.is_alive());
// Clean termination
proc.kill()?;Implementations§
Source§impl PtyProcess
impl PtyProcess
Sourcepub fn spawn(config: ShellConfig) -> Result<Self>
pub fn spawn(config: ShellConfig) -> Result<Self>
Spawn a new shell process with the given configuration.
§Errors
Returns an error if:
- The PTY system cannot be initialized
- The shell executable cannot be found
- The shell fails to start
Sourcepub fn is_alive(&mut self) -> bool
pub fn is_alive(&mut self) -> bool
Check if the process is still alive.
This method polls the process state and updates internal tracking.
Sourcepub fn state(&mut self) -> ProcessState
pub fn state(&mut self) -> ProcessState
Get the current process state.
Sourcepub fn kill(&mut self) -> Result<()>
pub fn kill(&mut self) -> Result<()>
Kill the process.
This method is idempotent - calling it on an already-dead process succeeds.
§Errors
Returns an error if the kill signal cannot be sent.
Sourcepub fn wait(&mut self) -> Result<ExitStatus>
pub fn wait(&mut self) -> Result<ExitStatus>
Wait for the process to exit.
This blocks until the process terminates or the timeout is reached.
§Errors
Returns an error if the wait fails or times out.
Sourcepub fn wait_timeout(&mut self, timeout: Duration) -> Result<ExitStatus>
pub fn wait_timeout(&mut self, timeout: Duration) -> Result<ExitStatus>
Wait for the process to exit with a timeout.
§Errors
Returns TimedOut if the timeout is reached before the process exits.
Sourcepub fn read_available(&mut self) -> Result<Vec<u8>>
pub fn read_available(&mut self) -> Result<Vec<u8>>
Read any available output without blocking.
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 timeout.
§Errors
Returns TimedOut if the pattern is not found within the timeout.
Sourcepub fn drain(&mut self, timeout: Duration) -> Result<usize>
pub fn drain(&mut self, timeout: Duration) -> Result<usize>
Drain all remaining output until EOF or timeout.
Sourcepub fn clear_output(&mut self)
pub fn clear_output(&mut self)
Clear the captured output buffer.
Trait Implementations§
Source§impl Debug for PtyProcess
impl Debug for PtyProcess
Auto Trait Implementations§
impl Freeze for PtyProcess
impl !RefUnwindSafe for PtyProcess
impl Send for PtyProcess
impl !Sync for PtyProcess
impl Unpin for PtyProcess
impl !UnwindSafe for PtyProcess
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.