5 releases (3 breaking)

0.4.0 Aug 7, 2023
0.3.0 Mar 8, 2023
0.2.0 Dec 15, 2021
0.1.1 Nov 10, 2021
0.1.0 Mar 6, 2021

#162 in Asynchronous

Download history 126/week @ 2024-01-07 179/week @ 2024-01-14 189/week @ 2024-01-21 95/week @ 2024-01-28 65/week @ 2024-02-04 122/week @ 2024-02-11 279/week @ 2024-02-18 1005/week @ 2024-02-25 466/week @ 2024-03-03 605/week @ 2024-03-10 488/week @ 2024-03-17 471/week @ 2024-03-24 617/week @ 2024-03-31 797/week @ 2024-04-07 1235/week @ 2024-04-14 1102/week @ 2024-04-21

3,780 downloads per month
Used in 8 crates

MIT license

39KB
854 lines

pty-process

This crate is a wrapper around tokio::process::Command or std::process::Command which provides the ability to allocate a pty and spawn new processes attached to that pty, with the pty as their controlling terminal. This allows for manipulation of interactive programs.

The basic functionality looks like this:

let mut pty = pty_process::Pty::new().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut cmd = pty_process::Command::new("nethack");
let child = cmd.spawn(&pty.pts().unwrap()).unwrap();

The returned child is a normal instance of tokio::process::Child (or std::process::Child for the blocking variant), with its stdin/stdout/stderr file descriptors pointing at the given pty. The pty instance implements tokio::io::AsyncRead and tokio::io::AsyncWrite (or std::io::Read and std::io::Write for the blocking variant), and can be used to communicate with the child process. The child process will also be made a session leader of a new session, and the controlling terminal of that session will be set to the given pty.

Features

By default, only the blocking APIs are available. To include the asynchronous APIs, you must enable the async feature.

Dependencies

~1–14MB
~145K SLoC