From c78084caca2563c52e563901a94e4d094e88cd1c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 3 Mar 2021 01:26:18 -0500 Subject: refactor examples --- examples/basic.rs | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'examples/basic.rs') 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(); -- cgit v1.2.3-54-g00ecf