aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: a4bb412b62c78efd956bb03f9e2cb3f63b1b6273 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! This crate is a wrapper around [`std::process::Command`] or
//! [`async_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:
//!
//! ```no_run
//! 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).unwrap();
//! ```
//!
//! The returned `child` is a normal instance of [`async_process::Child`] (or
//! [`std::process::Child`] for the [`blocking`](crate::blocking) variant),
//! with its `stdin`/`stdout`/`stderr` file descriptors pointing at the given
//! pty. The `pty` instance implements [`std::io::Read`] and
//! [`std::io::Write`] (or [`futures_io::AsyncRead`] and
//! [`futures_io::AsyncWrite`] 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`](crate::blocking) APIs are available. To
//! include the asynchronous APIs, you must enable the `async` feature. See
//! the `examples` directory in the repository for examples of how to use this
//! crate with the various different asynchronous frameworks.

#![warn(clippy::cargo)]
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![warn(clippy::as_conversions)]
#![warn(clippy::get_unwrap)]
#![allow(clippy::cognitive_complexity)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::similar_names)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::type_complexity)]

mod error;
pub use error::{Error, Result};
mod types;
pub use types::Size;

mod sys;

pub mod blocking;

#[cfg(feature = "async")]
mod command;
#[cfg(feature = "async")]
pub use command::Command;
#[cfg(feature = "async")]
mod pty;
#[cfg(feature = "async")]
pub use pty::Pty;