diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-03-12 11:46:14 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-03-12 11:46:14 -0500 |
commit | f3498d0afe3bd36cf3e9f553776518fd458a39af (patch) | |
tree | d6c7f15805eaa3c7813310b0e96797013338b5b7 /src/blocking | |
parent | 4ead14a3153b34941570e87d67064e4aa93fa01a (diff) | |
download | textmode-f3498d0afe3bd36cf3e9f553776518fd458a39af.tar.gz textmode-f3498d0afe3bd36cf3e9f553776518fd458a39af.zip |
simplify
Diffstat (limited to 'src/blocking')
-rw-r--r-- | src/blocking/input.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/blocking/input.rs b/src/blocking/input.rs index ea34536..1381776 100644 --- a/src/blocking/input.rs +++ b/src/blocking/input.rs @@ -6,8 +6,7 @@ use std::os::unix::io::AsRawFd as _; use crate::private::Input as _; pub struct RawGuard { - termios: nix::sys::termios::Termios, - cleaned_up: bool, + termios: Option<nix::sys::termios::Termios>, } impl RawGuard { @@ -25,23 +24,22 @@ impl RawGuard { ) .map_err(Error::SetRaw)?; Ok(Self { - termios, - cleaned_up: false, + termios: Some(termios), }) } pub fn cleanup(&mut self) -> Result<()> { - if self.cleaned_up { - return Ok(()); + if let Some(termios) = self.termios.take() { + let stdin = std::io::stdin().as_raw_fd(); + nix::sys::termios::tcsetattr( + stdin, + nix::sys::termios::SetArg::TCSANOW, + &termios, + ) + .map_err(Error::UnsetRaw) + } else { + Ok(()) } - self.cleaned_up = true; - let stdin = std::io::stdin().as_raw_fd(); - nix::sys::termios::tcsetattr( - stdin, - nix::sys::termios::SetArg::TCSANOW, - &self.termios, - ) - .map_err(Error::UnsetRaw) } } |