Skip to main content

PtyProcess

Struct PtyProcess 

Source
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

Source

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
Source

pub fn is_alive(&mut self) -> bool

Check if the process is still alive.

This method polls the process state and updates internal tracking.

Source

pub fn state(&mut self) -> ProcessState

Get the current process state.

Source

pub fn pid(&self) -> Option<u32>

Get the process ID, if available.

Source

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.

Source

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.

Source

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.

Source

pub fn write_all(&mut self, data: &[u8]) -> Result<()>

Send input to the process.

§Errors

Returns an error if the write fails.

Source

pub fn read_available(&mut self) -> Result<Vec<u8>>

Read any available output without blocking.

Source

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.

Source

pub fn drain(&mut self, timeout: Duration) -> Result<usize>

Drain all remaining output until EOF or timeout.

Source

pub fn output(&self) -> &[u8]

Get all captured output.

Source

pub fn clear_output(&mut self)

Clear the captured output buffer.

Source

pub fn resize(&mut self, cols: u16, rows: u16) -> Result<()>

Resize the PTY.

This sends SIGWINCH to the child process.

Trait Implementations§

Source§

impl Debug for PtyProcess

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for PtyProcess

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Downcast for T
where T: Any,

Source§

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

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

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

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