Expand description
rust-pty: Cross-platform async PTY library
This crate provides a unified async interface for pseudo-terminal (PTY) operations
across Unix (Linux, macOS) and Windows (ConPTY) platforms.
§Platform Support
- Unix: Uses
rustixfor PTY allocation and process management - Windows: Uses
ConPTYviawindows-sys(Windows 10 1809+)
§Quick Start
ⓘ
use rust_pty::{NativePtySystem, PtySystem, PtyConfig};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = PtyConfig::default();
let (mut master, mut child) = NativePtySystem::spawn_shell(&config).await?;
// Write a command
master.write_all(b"echo hello\n").await?;
// Read output
let mut buf = [0u8; 1024];
let n = master.read(&mut buf).await?;
println!("{}", String::from_utf8_lossy(&buf[..n]));
// Clean up
child.kill()?;
Ok(())
}§Features
- Async I/O: First-class async support with Tokio
- Cross-platform: Single API for Unix and Windows
- Type-safe: Strong typing with proper error handling
- Zero-copy: Efficient buffer management for high-throughput scenarios
Re-exports§
pub use config::PtyConfig;pub use config::PtyConfigBuilder;pub use config::PtySignal;pub use config::WindowSize;pub use error::PtyError;pub use error::Result;pub use traits::ExitStatus;pub use traits::PtyChild;pub use traits::PtyMaster;pub use traits::PtySystem;pub use unix::NativePtySystem;pub use unix::UnixPtyChild;pub use unix::UnixPtyMaster;pub use unix::UnixPtySystem;
Modules§
- config
- Configuration types for PTY creation and management.
- error
- Error types for the rust-pty crate.
- traits
- Core traits for PTY abstraction.
- unix
- Unix platform implementation for PTY operations.
Functions§
- spawn_
shell - Create a PTY with the default configuration and spawn a shell.