1 unstable release
Uses new Rust 2024
| 0.1.0 | Jan 5, 2026 |
|---|
#1600 in Asynchronous
94 downloads per month
Used in rust-expect
105KB
2.5K
SLoC
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
rust-pty
Low-level pseudo-terminal (PTY) abstraction for Rust.
Features
- Async I/O with Tokio
- PTY allocation and configuration
- Window size management
- Child process spawning
- Signal handling
Usage
use rust_pty::{PtyConfig, UnixPtyMaster, spawn_with_pty};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = PtyConfig::default()
.window_size(80, 24);
let (master, child) = spawn_with_pty("bash", &config)?;
// Use master for I/O
// master.write_all(b"echo hello\n").await?;
Ok(())
}
Platform Support
- Unix: Linux, macOS, BSD (via rustix PTY)
- Windows: Windows 10 1809+ (via ConPTY)
License
Licensed under MIT or Apache-2.0.
Dependencies
~10–18MB
~274K SLoC