diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-03-12 12:20:06 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-03-12 12:20:06 -0500 |
commit | 7c06da9c0f3402efbc3954e9f14b1d039fd38929 (patch) | |
tree | 57d06edf5b1dd15b51c3bb771845ce215b698a53 /src/input.rs | |
parent | f3498d0afe3bd36cf3e9f553776518fd458a39af (diff) | |
download | textmode-7c06da9c0f3402efbc3954e9f14b1d039fd38929.tar.gz textmode-7c06da9c0f3402efbc3954e9f14b1d039fd38929.zip |
move the guards back onto the main objects
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/input.rs b/src/input.rs index c881e44..e34187e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -61,6 +61,7 @@ impl Drop for RawGuard { pub struct Input { stdin: blocking::Unblock<std::io::Stdin>, + raw: Option<RawGuard>, buf: Vec<u8>, pos: usize, @@ -124,13 +125,16 @@ impl crate::private::Input for Input { #[allow(clippy::new_without_default)] impl Input { - pub async fn new() -> Result<(Self, RawGuard)> { - Ok((Self::new_without_raw(), RawGuard::new().await?)) + pub async fn new() -> Result<Self> { + let mut self_ = Self::new_without_raw(); + self_.raw = Some(RawGuard::new().await?); + Ok(self_) } pub fn new_without_raw() -> Self { Self { stdin: blocking::Unblock::new(std::io::stdin()), + raw: None, buf: Vec::with_capacity(4096), pos: 0, parse_utf8: true, @@ -161,6 +165,10 @@ impl Input { self.parse_single = parse; } + pub fn take_raw_guard(&mut self) -> Option<RawGuard> { + self.raw.take() + } + pub async fn read_key(&mut self) -> Result<Option<crate::Key>> { self.fill_buf().await?; |