diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-03-09 02:33:01 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-03-09 02:40:29 -0500 |
commit | dd845e949ac59e08bf12d0fcac8b4069c5c7645c (patch) | |
tree | 3f9dc84ac00fb692f80726c3539084185a9f88fa /examples | |
parent | 3a92d03b3c47926b0eeaac8f301833b23d68a6ec (diff) | |
download | textmode-dd845e949ac59e08bf12d0fcac8b4069c5c7645c.tar.gz textmode-dd845e949ac59e08bf12d0fcac8b4069c5c7645c.zip |
add async implementation of Input
this is just copied and pasted for now, need to figure out how to
generate one from the other
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tmux.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/examples/tmux.rs b/examples/tmux.rs index 5d1578b..490a22b 100644 --- a/examples/tmux.rs +++ b/examples/tmux.rs @@ -93,7 +93,7 @@ impl State { fn spawn_input_task( &self, ex: &smol::Executor<'_>, - mut input: textmode::blocking::Input, + mut input: textmode::Input, ) { let notify = self.wevents.clone(); ex.spawn(async move { @@ -103,12 +103,8 @@ impl State { input.parse_special_keys(false); loop { input.parse_single(waiting_for_command); - let key_input = smol::unblock(move || { - let key = input.read_key(); - (input, key) - }); - match key_input.await { - (returned_input, Ok(Some(key))) => { + match input.read_key().await { + Ok(Some(key)) => { if waiting_for_command { match key { textmode::Key::Ctrl(b'n') => { @@ -151,12 +147,11 @@ impl State { } } } - input = returned_input; } - (_, Ok(None)) => { + Ok(None) => { break; } - (_, Err(e)) => { + Err(e) => { eprintln!("{}", e); break; } @@ -299,8 +294,8 @@ impl State { #[must_use] struct Tmux { - input: textmode::blocking::Input, - _raw: textmode::blocking::RawGuard, + input: textmode::Input, + _raw: textmode::RawGuard, tm: textmode::Output, _screen: textmode::ScreenGuard, state: State, @@ -308,7 +303,7 @@ struct Tmux { impl Tmux { async fn new() -> Self { - let (input, _raw) = textmode::blocking::Input::new(); + let (input, _raw) = textmode::Input::new(); let (tm, _screen) = textmode::Output::new().await.unwrap(); let state = State::new(); Self { |