aboutsummaryrefslogtreecommitdiffstats
path: root/examples/basic.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/basic.rs')
-rw-r--r--examples/basic.rs25
1 files changed, 14 insertions, 11 deletions
diff --git a/examples/basic.rs b/examples/basic.rs
index c9b5f6c..4f996b9 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -4,16 +4,19 @@ mod main {
use std::io::{Read as _, Write as _};
use std::os::unix::io::AsRawFd as _;
- pub fn run(child: &mut pty_process::blocking::Child) {
+ pub fn run(
+ child: &mut std::process::Child,
+ mut pty: &pty_process::blocking::Pty,
+ ) {
let _raw = super::raw_guard::RawGuard::new();
let mut buf = [0_u8; 4096];
- let pty = child.pty().as_raw_fd();
- let stdin = std::io::stdin().as_raw_fd();
+ let pty_fd = pty.as_raw_fd();
+ let stdin_fd = std::io::stdin().as_raw_fd();
loop {
let mut set = nix::sys::select::FdSet::new();
- set.insert(pty);
- set.insert(stdin);
+ set.insert(pty_fd);
+ set.insert(stdin_fd);
match nix::sys::select::select(
None,
Some(&mut set),
@@ -23,8 +26,8 @@ mod main {
) {
Ok(n) => {
if n > 0 {
- if set.contains(pty) {
- match child.pty().read(&mut buf) {
+ if set.contains(pty_fd) {
+ match pty.read(&mut buf) {
Ok(bytes) => {
let buf = &buf[..bytes];
let stdout = std::io::stdout();
@@ -38,11 +41,11 @@ mod main {
}
};
}
- if set.contains(stdin) {
+ if set.contains(stdin_fd) {
match std::io::stdin().read(&mut buf) {
Ok(bytes) => {
let buf = &buf[..bytes];
- child.pty().write_all(buf).unwrap();
+ pty.write_all(buf).unwrap();
}
Err(e) => {
eprintln!("stdin read failed: {:?}", e);
@@ -76,10 +79,10 @@ fn main() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("tac")
// .args(&["500"])
- .spawn(pty)
+ .spawn(&pty)
.unwrap();
- main::run(&mut child);
+ main::run(&mut child, &pty);
let status = child.wait().unwrap();
std::process::exit(