aboutsummaryrefslogtreecommitdiffstats
path: root/examples/smol.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/smol.rs')
-rw-r--r--examples/smol.rs34
1 files changed, 2 insertions, 32 deletions
diff --git a/examples/smol.rs b/examples/smol.rs
index 5512c2d..d7b816f 100644
--- a/examples/smol.rs
+++ b/examples/smol.rs
@@ -1,43 +1,13 @@
use pty_process::Command as _;
use smol::io::{AsyncReadExt as _, AsyncWriteExt 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::smol::Child,
) -> std::result::Result<(), Box<dyn std::error::Error>> {
- let _raw = RawGuard::new();
+ let _raw = raw_guard::RawGuard::new();
let ex = smol::Executor::new();