From 97cd43606097a23b20b761928fcf65db9d42214a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 5 Dec 2021 16:05:58 -0500 Subject: add a command to reset speed to default --- src/bin/ttyplay/event.rs | 1 + src/bin/ttyplay/input.rs | 19 +++++++++---------- src/bin/ttyplay/timer.rs | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/bin/ttyplay/event.rs b/src/bin/ttyplay/event.rs index da8cdd4..3a68965 100644 --- a/src/bin/ttyplay/event.rs +++ b/src/bin/ttyplay/event.rs @@ -15,6 +15,7 @@ pub enum TimerAction { PreviousFrame, SpeedUp, SlowDown, + DefaultSpeed, Quit, } diff --git a/src/bin/ttyplay/input.rs b/src/bin/ttyplay/input.rs index 8c45b69..266c419 100644 --- a/src/bin/ttyplay/input.rs +++ b/src/bin/ttyplay/input.rs @@ -30,16 +30,15 @@ pub fn spawn_task( crate::event::TimerAction::Pause, ), textmode::Key::Ctrl(b'i') => crate::event::Event::ToggleUi, - textmode::Key::Char('=' | '+') => { - crate::event::Event::TimerAction( - crate::event::TimerAction::SpeedUp, - ) - } - textmode::Key::Char('_' | '-') => { - crate::event::Event::TimerAction( - crate::event::TimerAction::SlowDown, - ) - } + textmode::Key::Char('+') => crate::event::Event::TimerAction( + crate::event::TimerAction::SpeedUp, + ), + textmode::Key::Char('-') => crate::event::Event::TimerAction( + crate::event::TimerAction::SlowDown, + ), + textmode::Key::Char('=') => crate::event::Event::TimerAction( + crate::event::TimerAction::DefaultSpeed, + ), _ => continue, }; event_w.send(event).await.unwrap(); diff --git a/src/bin/ttyplay/timer.rs b/src/bin/ttyplay/timer.rs index 6b3ec00..e8e4ce9 100644 --- a/src/bin/ttyplay/timer.rs +++ b/src/bin/ttyplay/timer.rs @@ -132,6 +132,12 @@ pub fn spawn_task( start_time = now - (now - start_time) * 2; } } + crate::event::TimerAction::DefaultSpeed => { + let now = std::time::Instant::now(); + start_time = now + - (((now - start_time) * 16) / playback_ratio); + playback_ratio = 16; + } crate::event::TimerAction::Quit => break, }, Res::TimerAction(Err(e)) => panic!("{}", e), -- cgit v1.2.3-54-g00ecf