aboutsummaryrefslogtreecommitdiffstats
path: root/src/blocking
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-12 12:20:06 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-12 12:20:06 -0500
commit7c06da9c0f3402efbc3954e9f14b1d039fd38929 (patch)
tree57d06edf5b1dd15b51c3bb771845ce215b698a53 /src/blocking
parentf3498d0afe3bd36cf3e9f553776518fd458a39af (diff)
downloadtextmode-7c06da9c0f3402efbc3954e9f14b1d039fd38929.tar.gz
textmode-7c06da9c0f3402efbc3954e9f14b1d039fd38929.zip
move the guards back onto the main objects
Diffstat (limited to 'src/blocking')
-rw-r--r--src/blocking/input.rs13
-rw-r--r--src/blocking/output.rs18
2 files changed, 26 insertions, 5 deletions
diff --git a/src/blocking/input.rs b/src/blocking/input.rs
index 1381776..b133e7f 100644
--- a/src/blocking/input.rs
+++ b/src/blocking/input.rs
@@ -50,6 +50,8 @@ impl Drop for RawGuard {
}
pub struct Input {
+ raw: Option<RawGuard>,
+
buf: Vec<u8>,
pos: usize,
@@ -112,12 +114,15 @@ impl crate::private::Input for Input {
#[allow(clippy::new_without_default)]
impl Input {
- pub fn new() -> Result<(Self, RawGuard)> {
- Ok((Self::new_without_raw(), RawGuard::new()?))
+ pub fn new() -> Result<Self> {
+ let mut self_ = Self::new_without_raw();
+ self_.raw = Some(RawGuard::new()?);
+ Ok(self_)
}
pub fn new_without_raw() -> Self {
Self {
+ raw: None,
buf: Vec::with_capacity(4096),
pos: 0,
parse_utf8: true,
@@ -148,6 +153,10 @@ impl Input {
self.parse_single = parse;
}
+ pub fn take_raw_guard(&mut self) -> Option<RawGuard> {
+ self.raw.take()
+ }
+
pub fn read_key(&mut self) -> Result<Option<crate::Key>> {
self.fill_buf()?;
diff --git a/src/blocking/output.rs b/src/blocking/output.rs
index 85faac1..83466f8 100644
--- a/src/blocking/output.rs
+++ b/src/blocking/output.rs
@@ -30,6 +30,8 @@ impl Drop for ScreenGuard {
}
pub struct Output {
+ screen: Option<ScreenGuard>,
+
cur: vt100::Parser,
next: vt100::Parser,
}
@@ -55,8 +57,10 @@ impl crate::private::Output for Output {
impl crate::Textmode for Output {}
impl Output {
- pub fn new() -> Result<(Self, ScreenGuard)> {
- Ok((Self::new_without_screen(), ScreenGuard::new()?))
+ pub fn new() -> Result<Self> {
+ let mut self_ = Self::new_without_screen();
+ self_.screen = Some(ScreenGuard::new()?);
+ Ok(self_)
}
pub fn new_without_screen() -> Self {
@@ -69,7 +73,15 @@ impl Output {
let cur = vt100::Parser::new(rows, cols, 0);
let next = vt100::Parser::new(rows, cols, 0);
- Self { cur, next }
+ Self {
+ screen: None,
+ cur,
+ next,
+ }
+ }
+
+ pub fn take_screen_guard(&mut self) -> Option<ScreenGuard> {
+ self.screen.take()
}
pub fn refresh(&mut self) -> Result<()> {