aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-07 18:38:22 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-07 18:38:22 -0500
commitae4f5469711705e2686fd2be65e4fbc700f93e12 (patch)
tree2d525a7544e6ddfcd4851aedbfa219ad85e965e4 /examples
parent4a3d1dd61bd2e32b26206f035406fd655d040087 (diff)
downloadtextmode-ae4f5469711705e2686fd2be65e4fbc700f93e12.tar.gz
textmode-ae4f5469711705e2686fd2be65e4fbc700f93e12.zip
separate out the guards from the main structs
Diffstat (limited to 'examples')
-rw-r--r--examples/async.rs4
-rw-r--r--examples/basic.rs2
-rw-r--r--examples/tmux.rs23
3 files changed, 18 insertions, 11 deletions
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();
}
}