shpool_pty/lib.rs
1//! # PTY
2//!
3//! [![Crate][crate-badge]][crate] [![docs-badge][]][docs] [![license-badge][]][license] [![travis-badge][]][travis]
4//!
5//! [crate-badge]: https://img.shields.io/badge/crates.io-v0.2.0-orange.svg?style=flat-square
6//! [crate]: https://crates.io/crates/pty
7//!
8//! [docs-badge]: https://img.shields.io/badge/API-docs-blue.svg?style=flat-square
9//! [docs]: http://note.hibariya.org/pty-rs/pty/index.html
10//!
11//! [license-badge]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
12//! [license]: https://github.com/hibariya/pty-rs/blob/master/LICENSE.txt
13//!
14//! [travis-badge]: https://travis-ci.org/hibariya/pty-rs.svg?branch=master&style=flat-square
15//! [travis]: https://travis-ci.org/hibariya/pty-rs
16//!
17//! The `pty` crate provides `pty::fork()`. That makes a parent process fork with new pseudo-terminal (PTY).
18//!
19//! This crate depends on followings:
20//!
21//! * `libc` library
22//! * POSIX environment
23//!
24//! ## Usage
25//!
26//! Add this to your `Cargo.toml`:
27//!
28//! ```toml
29//! [dependencies]
30//! pty = "0.2"
31//! ```
32//!
33//! and this to your crate root:
34//!
35//! ```rust
36//! extern crate shpool_pty;
37//! ```
38//!
39//! ### pty::fork()
40//!
41//! This function returns `pty::Child`. It represents the child process and its PTY.
42//!
43//! For example, the following code spawns `tty(1)` command by `pty::fork()` and outputs the result of the command.
44//!
45//! ```rust
46//! extern crate shpool_pty;
47//! extern crate libc;
48//!
49//! use std::ffi::CString;
50//! use std::io::Read;
51//! use std::process::{Command};
52//!
53//! use shpool_pty::fork::*;
54//!
55//! fn main() {
56//! let fork = Fork::from_ptmx().unwrap();
57//!
58//! if let Some(mut master) = fork.is_parent().ok() {
59//! // Read output via PTY master
60//! let mut output = String::new();
61//!
62//! match master.read_to_string(&mut output) {
63//! Ok(_nread) => println!("child tty is: {}", output.trim()),
64//! Err(e) => panic!("read error: {}", e),
65//! }
66//! }
67//! else {
68//! // Child process just exec `tty`
69//! Command::new("tty").status().expect("could not execute tty");
70//! }
71//! }
72//! ```
73
74extern crate errno;
75extern crate libc;
76extern crate log;
77
78mod descriptor;
79pub mod fork;
80pub mod prelude;
81
82const DEFAULT_PTMX: &str = "/dev/ptmx";