aboutsummaryrefslogtreecommitdiffstats
path: root/src/raw_guard.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-09 03:19:05 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-09 03:19:05 -0500
commit898ca615b5d573120a62cc01b2fb43f1d707f69f (patch)
treed525e012441c2104e9a5f2e4cae87c2396162836 /src/raw_guard.rs
parent51e877d0d0fcd122d1cb0934639e43579a380f63 (diff)
downloadtextmode-898ca615b5d573120a62cc01b2fb43f1d707f69f.tar.gz
textmode-898ca615b5d573120a62cc01b2fb43f1d707f69f.zip
make raw_guard also async
i think tcsetattr etc can actually block in some cases
Diffstat (limited to 'src/raw_guard.rs')
-rw-r--r--src/raw_guard.rs49
1 files changed, 0 insertions, 49 deletions
diff --git a/src/raw_guard.rs b/src/raw_guard.rs
deleted file mode 100644
index 3835181..0000000
--- a/src/raw_guard.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-use crate::error::*;
-
-use std::os::unix::io::AsRawFd as _;
-
-pub struct RawGuard {
- termios: nix::sys::termios::Termios,
- cleaned_up: bool,
-}
-
-impl RawGuard {
- #[allow(clippy::new_without_default)]
- pub fn new() -> Result<Self> {
- let stdin = std::io::stdin().as_raw_fd();
- let termios =
- nix::sys::termios::tcgetattr(stdin).map_err(Error::SetRaw)?;
- 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,
- )
- .map_err(Error::SetRaw)?;
- Ok(Self {
- termios,
- cleaned_up: false,
- })
- }
-
- pub fn cleanup(&mut self) -> Result<()> {
- if self.cleaned_up {
- return 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)
- }
-}
-
-impl Drop for RawGuard {
- fn drop(&mut self) {
- let _ = self.cleanup();
- }
-}