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/async-std.rs | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'examples/async-std.rs') diff --git a/examples/async-std.rs b/examples/async-std.rs index c65b1ac..b521549 100644 --- a/examples/async-std.rs +++ b/examples/async-std.rs @@ -2,44 +2,14 @@ use async_std::io::prelude::WriteExt as _; use async_std::io::ReadExt as _; use async_std::prelude::FutureExt as _; use pty_process::Command as _; -use std::os::unix::io::AsRawFd as _; use std::os::unix::process::ExitStatusExt 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; async fn run( child: &pty_process::async_std::Child, ) -> std::result::Result<(), Box> { - let _raw = RawGuard::new(); + let _raw = raw_guard::RawGuard::new(); let ex = async_executor::Executor::new(); -- cgit v1.2.3-54-g00ecf