diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-05 01:32:10 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-05 01:32:10 -0500 |
commit | 91d2c04e349dec9b1b7873abf2cc6b960735654f (patch) | |
tree | bf687ec9216f076cbfd086ac46db5cfd4a45aa8d /src/bin/ttyplay/input.rs | |
parent | c1ea723f8277470e2bbaff7cd679e50d23c427f2 (diff) | |
download | ttyrec-bin-91d2c04e349dec9b1b7873abf2cc6b960735654f.tar.gz ttyrec-bin-91d2c04e349dec9b1b7873abf2cc6b960735654f.zip |
remove some indirection
Diffstat (limited to 'src/bin/ttyplay/input.rs')
-rw-r--r-- | src/bin/ttyplay/input.rs | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/bin/ttyplay/input.rs b/src/bin/ttyplay/input.rs index a922a55..d8c8e92 100644 --- a/src/bin/ttyplay/input.rs +++ b/src/bin/ttyplay/input.rs @@ -1,24 +1,38 @@ -pub fn to_event(key: &textmode::Key) -> Option<crate::event::Event> { - Some(match key { - textmode::Key::Char('g' | '0' | ')') => { - crate::event::Event::TimerAction( - crate::event::TimerAction::FirstFrame, - ) +pub fn spawn_task( + event_w: async_std::channel::Sender<crate::event::Event>, + mut input: textmode::Input, +) { + async_std::task::spawn(async move { + while let Some(key) = input.read_key().await.unwrap() { + let event = match key { + textmode::Key::Char('g' | '0' | ')') => { + crate::event::Event::TimerAction( + crate::event::TimerAction::FirstFrame, + ) + } + textmode::Key::Char('G' | '$') => { + crate::event::Event::TimerAction( + crate::event::TimerAction::LastFrame, + ) + } + textmode::Key::Char('l' | 'n') => { + crate::event::Event::TimerAction( + crate::event::TimerAction::NextFrame, + ) + } + textmode::Key::Char('h' | 'p') => { + crate::event::Event::TimerAction( + crate::event::TimerAction::PreviousFrame, + ) + } + textmode::Key::Char('q') => crate::event::Event::Quit, + textmode::Key::Char(' ') => crate::event::Event::TimerAction( + crate::event::TimerAction::Pause, + ), + textmode::Key::Ctrl(b'i') => crate::event::Event::ToggleUi, + _ => continue, + }; + event_w.send(event).await.unwrap(); } - textmode::Key::Char('G' | '$') => crate::event::Event::TimerAction( - crate::event::TimerAction::LastFrame, - ), - textmode::Key::Char('l' | 'n') => crate::event::Event::TimerAction( - crate::event::TimerAction::NextFrame, - ), - textmode::Key::Char('h' | 'p') => crate::event::Event::TimerAction( - crate::event::TimerAction::PreviousFrame, - ), - textmode::Key::Char('q') => crate::event::Event::Quit, - textmode::Key::Char(' ') => { - crate::event::Event::TimerAction(crate::event::TimerAction::Pause) - } - textmode::Key::Ctrl(b'i') => crate::event::Event::ToggleUi, - _ => return None, - }) + }); } |