Expand description
Cross-platform async-ready PTY interface.
This crate provides a cross platform API for working with the pseudo terminal (pty) interfaces provided by the system. Unlike other crates in this space, this crate provides a set of traits that allow selecting from different implementations at runtime.
Forked from portable-pty (part of wezterm).
use xpty::{CommandBuilder, PtySize, native_pty_system, PtySystem};
// Use the native pty implementation for the system
let pty_system = native_pty_system();
// Create a new pty
let mut pair = pty_system.openpty(PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0,
})?;
// Spawn a shell into the pty
let cmd = CommandBuilder::new("bash");
let child = pair.slave.spawn_command(cmd)?;
// Read and parse output from the pty with reader
let mut reader = pair.master.try_clone_reader()?;
// Send data to the pty by writing to the master
writeln!(pair.master.take_writer()?, "ls -l\r\n")?;Re-exports§
pub use error::Error;pub use error::Result;pub use cmdbuilder::CommandBuilder;
Modules§
- cmdbuilder
- error
- unix
- Working with pseudo-terminals on Unix
Structs§
- Exit
Status - Represents the exit status of a child process.
- PtyPair
- A pair of master and slave PTY handles.
- PtySize
- Represents the size of the visible display area in the pty.
Traits§
- Child
- Represents a child process spawned into the pty.
- Child
Killer - Represents the ability to signal a Child to terminate.
- Master
Pty - Represents the master/control end of the pty.
- Master
PtyExt - Unix-specific extensions for
MasterPty. - PtySystem
- The
PtySystemtrait allows an application to work with multiple possible Pty implementations at runtime. - Slave
Pty - Represents the slave side of a pty. Can be used to spawn processes into the pty.
Functions§
- native_
pty_ system - Returns a
NativePtySystemfor the current platform. - native_
pty_ system_ boxed - Returns the native PTY system as a boxed trait object.