10 releases (breaking)

0.8.1 Mar 13, 2023
0.7.0 Dec 12, 2021
0.6.0 Nov 23, 2021
0.4.0 Apr 30, 2021
0.1.0 May 20, 2019

#52 in Hardware support

Download history 3027/week @ 2024-06-11 2616/week @ 2024-06-18 2146/week @ 2024-06-25 1799/week @ 2024-07-02 2372/week @ 2024-07-09 2832/week @ 2024-07-16 2858/week @ 2024-07-23 3447/week @ 2024-07-30 2665/week @ 2024-08-06 2149/week @ 2024-08-13 2184/week @ 2024-08-20 7803/week @ 2024-08-27 20578/week @ 2024-09-03 24517/week @ 2024-09-10 28859/week @ 2024-09-17 27327/week @ 2024-09-24

102,871 downloads per month
Used in 38 crates (17 directly)

MIT license

130KB
3K 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.take_writer()?, "ls -l\r\n")?;

Dependencies

~2.2–3MB
~63K SLoC