2 unstable releases

0.7.0 Jun 26, 2024
0.1.0 Aug 19, 2022

#581 in Command-line interface

Download history 58/week @ 2024-07-14 100/week @ 2024-07-21 86/week @ 2024-07-28 58/week @ 2024-08-04 91/week @ 2024-08-11 117/week @ 2024-08-18 61/week @ 2024-08-25 55/week @ 2024-09-01 85/week @ 2024-09-08 79/week @ 2024-09-15 97/week @ 2024-09-22 133/week @ 2024-09-29 104/week @ 2024-10-06 94/week @ 2024-10-13 119/week @ 2024-10-20 103/week @ 2024-10-27

445 downloads per month
Used in 2 crates

MIT license

78KB
2K SLoC

This crate provides a cross platform API for working with the psuedo 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. This crate is part of wezterm.

use portable_pty::{CommandBuilder, PtySize, native_pty_system, PtySystem};
use anyhow::Error;

// 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,
    // Not all systems support pixel_width, pixel_height,
    // but it is good practice to set it to something
    // that matches the size of the selected font.  That
    // is more complex than can be shown here in this
    // brief example though!
    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, "ls -l\r\n")?;

ssh2

If the ssh feature is enabled, this crate exposes an ssh::SshSession type that can wrap an established ssh session with an implementation of PtySystem, allowing you to use the same pty interface with remote ptys.

Dependencies

~2.2–3.5MB
~76K SLoC