11 releases (breaking)

0.9.0 Feb 11, 2025
0.8.1 Mar 13, 2023
0.8.0 Feb 17, 2023
0.7.0 Dec 12, 2021
0.1.0 May 20, 2019

#90 in Hardware support

Download history 4735/week @ 2024-10-30 3314/week @ 2024-11-06 3070/week @ 2024-11-13 3991/week @ 2024-11-20 4246/week @ 2024-11-27 4493/week @ 2024-12-04 4315/week @ 2024-12-11 4090/week @ 2024-12-18 2520/week @ 2024-12-25 3773/week @ 2025-01-01 4280/week @ 2025-01-08 4109/week @ 2025-01-15 5135/week @ 2025-01-22 4813/week @ 2025-01-29 5025/week @ 2025-02-05 4784/week @ 2025-02-12

20,458 downloads per month
Used in 44 crates (22 directly)

MIT license

135KB
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.1–3MB
~61K SLoC