Skip to main content

Crate xpty

Crate xpty 

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

ExitStatus
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.
ChildKiller
Represents the ability to signal a Child to terminate.
MasterPty
Represents the master/control end of the pty.
MasterPtyExt
Unix-specific extensions for MasterPty.
PtySystem
The PtySystem trait allows an application to work with multiple possible Pty implementations at runtime.
SlavePty
Represents the slave side of a pty. Can be used to spawn processes into the pty.

Functions§

native_pty_system
Returns a NativePtySystem for the current platform.
native_pty_system_boxed
Returns the native PTY system as a boxed trait object.

Type Aliases§

NativePtySystem