From ae4f5469711705e2686fd2be65e4fbc700f93e12 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 7 Mar 2021 18:38:22 -0500 Subject: separate out the guards from the main structs --- examples/async.rs | 4 ++-- examples/basic.rs | 2 +- examples/tmux.rs | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/async.rs b/examples/async.rs index 3736cb8..b97ad24 100644 --- a/examples/async.rs +++ b/examples/async.rs @@ -21,9 +21,9 @@ async fn run(tm: &mut textmode::r#async::Output) -> std::io::Result<()> { fn main() { smol::block_on(async { - let mut tm = textmode::r#async::Output::new().await.unwrap(); + let (mut tm, _guard) = + textmode::r#async::Output::new().await.unwrap(); let e = run(&mut tm).await; - tm.cleanup().await.unwrap(); e.unwrap(); }); } diff --git a/examples/basic.rs b/examples/basic.rs index fb13d89..f3f846d 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,7 +1,7 @@ use textmode::Textmode as _; fn main() { - let mut tm = textmode::blocking::Output::new().unwrap(); + let (mut tm, _guard) = textmode::blocking::Output::new().unwrap(); tm.move_to(5, 5); tm.write_str("foo"); diff --git a/examples/tmux.rs b/examples/tmux.rs index e5e4fcd..b85b603 100644 --- a/examples/tmux.rs +++ b/examples/tmux.rs @@ -310,27 +310,37 @@ impl State { #[must_use] struct Tmux { input: textmode::Input, + _raw: textmode::RawGuard, tm: textmode::Output, + _screen: textmode::ScreenGuard, state: State, } impl Tmux { async fn new() -> Self { - let input = textmode::Input::new(); - let tm = textmode::Output::new().await.unwrap(); + let (input, _raw) = textmode::Input::new(); + let (tm, _screen) = textmode::Output::new().await.unwrap(); let state = State::new(); - Self { input, tm, state } + Self { + input, + _raw, + tm, + _screen, + state, + } } async fn run(self, ex: &smol::Executor<'_>) { let Self { - mut input, + input, + _raw, mut tm, + _screen, mut state, } = self; state.new_window(ex, state.wevents.clone()); - state.spawn_input_task(ex, input.clone()); + state.spawn_input_task(ex, input); ex.run(async { loop { @@ -391,9 +401,6 @@ impl Tmux { } }) .await; - - tm.cleanup().await.unwrap(); - input.cleanup(); } } -- cgit v1.2.3-54-g00ecf