aboutsummaryrefslogtreecommitdiffstats
path: root/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs12
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?;