aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-04 12:27:41 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-04 12:51:47 -0500
commita8622661af3716ef8a4718b6cc5df569e2f7e74e (patch)
tree2eee51679bf99677402e9e1dd8bffa8ea017e2a8
parent5a3c3fe737f2a46a9f9757981487394bf9b88005 (diff)
downloadteleterm-a8622661af3716ef8a4718b6cc5df569e2f7e74e.tar.gz
teleterm-a8622661af3716ef8a4718b6cc5df569e2f7e74e.zip
implement pausing
-rw-r--r--src/cmd/play.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/cmd/play.rs b/src/cmd/play.rs
index 9b81390..427f611 100644
--- a/src/cmd/play.rs
+++ b/src/cmd/play.rs
@@ -78,6 +78,7 @@ struct PlaySession {
base_time: std::time::Instant,
last_frame_time: std::time::Duration,
total_time_clamped: std::time::Duration,
+ paused: Option<std::time::Instant>,
}
impl PlaySession {
@@ -100,6 +101,7 @@ impl PlaySession {
base_time: std::time::Instant::now(),
last_frame_time: std::time::Duration::default(),
total_time_clamped: std::time::Duration::default(),
+ paused: None,
}
}
@@ -107,9 +109,21 @@ impl PlaySession {
match e {
crossterm::InputEvent::Keyboard(crossterm::KeyEvent::Char(
'q',
- )) => Ok(true),
- _ => Ok(false),
+ )) => return Ok(true),
+ crossterm::InputEvent::Keyboard(crossterm::KeyEvent::Char(
+ ' ',
+ )) => {
+ if let Some(time) = self.paused.take() {
+ let diff = std::time::Instant::now() - time;
+ self.to_write.time_incr(diff);
+ self.base_time += diff;
+ } else {
+ self.paused = Some(std::time::Instant::now());
+ }
+ }
+ _ => {}
}
+ Ok(false)
}
}
@@ -210,6 +224,10 @@ impl PlaySession {
}
fn poll_write_terminal(&mut self) -> component_future::Poll<(), Error> {
+ if self.paused.is_some() {
+ return Ok(component_future::Async::NothingToDo);
+ }
+
if let Some(data) = component_future::try_ready!(self
.to_write
.poll()
@@ -270,6 +288,12 @@ impl<T> DumbDelayQueue<T> {
timer: tokio::timer::Delay::new(time),
})
}
+
+ fn time_incr(&mut self, dur: std::time::Duration) {
+ for entry in &mut self.queue {
+ entry.timer.reset(entry.timer.deadline() + dur);
+ }
+ }
}
#[must_use = "streams do nothing unless polled"]