1 unstable release

0.1.0 Aug 19, 2022

#740 in Operating systems

Download history 131/week @ 2024-01-01 155/week @ 2024-01-08 120/week @ 2024-01-15 145/week @ 2024-01-22 130/week @ 2024-01-29 82/week @ 2024-02-05 162/week @ 2024-02-12 133/week @ 2024-02-19 140/week @ 2024-02-26 78/week @ 2024-03-04 172/week @ 2024-03-11 156/week @ 2024-03-18 92/week @ 2024-03-25 161/week @ 2024-04-01 137/week @ 2024-04-08 142/week @ 2024-04-15

539 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–4MB
~82K SLoC