diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-03-03 01:26:18 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-03-03 01:26:18 -0500 |
commit | c78084caca2563c52e563901a94e4d094e88cd1c (patch) | |
tree | 7a7e5ebb51857005307be5d7069fe6bb9421064c /examples/basic.rs | |
parent | f7531c298e90252507c6224b78219a560c8a629f (diff) | |
download | pty-process-c78084caca2563c52e563901a94e4d094e88cd1c.tar.gz pty-process-c78084caca2563c52e563901a94e4d094e88cd1c.zip |
refactor examples
Diffstat (limited to 'examples/basic.rs')
-rw-r--r-- | examples/basic.rs | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/examples/basic.rs b/examples/basic.rs index bc9389c..97bdd46 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -4,39 +4,10 @@ use std::os::unix::process::ExitStatusExt as _; use pty_process::Command as _; -struct RawGuard { - termios: nix::sys::termios::Termios, -} - -impl RawGuard { - fn new() -> Self { - let stdin = std::io::stdin().as_raw_fd(); - let termios = nix::sys::termios::tcgetattr(stdin).unwrap(); - let mut termios_raw = termios.clone(); - nix::sys::termios::cfmakeraw(&mut termios_raw); - nix::sys::termios::tcsetattr( - stdin, - nix::sys::termios::SetArg::TCSANOW, - &termios_raw, - ) - .unwrap(); - Self { termios } - } -} - -impl Drop for RawGuard { - fn drop(&mut self) { - let stdin = std::io::stdin().as_raw_fd(); - let _ = nix::sys::termios::tcsetattr( - stdin, - nix::sys::termios::SetArg::TCSANOW, - &self.termios, - ); - } -} +mod raw_guard; fn run(child: &pty_process::std::Child) { - let _raw = RawGuard::new(); + let _raw = 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(); |