aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-05 01:39:02 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-05 01:39:02 -0500
commit4f21ca4dfdf95945342b7a244d55549eda6251c2 (patch)
tree5b4af0feeb4a97912ae60790b1954e866fd21d29
parent91d2c04e349dec9b1b7873abf2cc6b960735654f (diff)
downloadttyrec-bin-4f21ca4dfdf95945342b7a244d55549eda6251c2.tar.gz
ttyrec-bin-4f21ca4dfdf95945342b7a244d55549eda6251c2.zip
more refactoring
-rw-r--r--src/bin/ttyplay/main.rs55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/bin/ttyplay/main.rs b/src/bin/ttyplay/main.rs
index f2cec77..6c9fc15 100644
--- a/src/bin/ttyplay/main.rs
+++ b/src/bin/ttyplay/main.rs
@@ -151,27 +151,11 @@ fn spawn_timer_task(
})
}
-async fn async_main(opt: Opt) -> anyhow::Result<()> {
- let Opt { file } = opt;
-
- let fh = async_std::fs::File::open(file).await?;
-
- let mut input = textmode::Input::new().await?;
- let mut output = textmode::Output::new().await?;
- let _input_guard = input.take_raw_guard();
- let _output_guard = output.take_screen_guard();
-
- let frames = async_std::sync::Arc::new(async_std::sync::Mutex::new(
- frames::FrameData::new(),
- ));
- let (event_w, event_r) = async_std::channel::unbounded();
- let (timer_w, timer_r) = async_std::channel::unbounded();
-
- spawn_frame_reader_task(event_w.clone(), frames.clone(), fh);
- input::spawn_task(event_w.clone(), input);
- let timer_task =
- spawn_timer_task(event_w.clone(), frames.clone(), timer_r);
-
+async fn event_loop(
+ event_r: async_std::channel::Receiver<event::Event>,
+ timer_w: async_std::channel::Sender<event::TimerAction>,
+ mut output: textmode::Output,
+) -> anyhow::Result<()> {
let mut display = display::Display::new();
let mut current_screen = vt100::Parser::default().screen().clone();
let events = event::Reader::new(event_r);
@@ -182,7 +166,7 @@ async fn async_main(opt: Opt) -> anyhow::Result<()> {
continue;
}
event::Event::FrameTransition((idx, screen)) => {
- current_screen = screen.clone();
+ current_screen = screen;
display.current_frame(idx);
}
event::Event::FrameLoaded(n) => {
@@ -205,6 +189,33 @@ async fn async_main(opt: Opt) -> anyhow::Result<()> {
display.render(&current_screen, &mut output).await?;
}
+ Ok(())
+}
+
+async fn async_main(opt: Opt) -> anyhow::Result<()> {
+ let Opt { file } = opt;
+
+ let fh = async_std::fs::File::open(file).await?;
+
+ let mut input = textmode::Input::new().await?;
+ let mut output = textmode::Output::new().await?;
+ let _input_guard = input.take_raw_guard();
+ let _output_guard = output.take_screen_guard();
+
+ let (event_w, event_r) = async_std::channel::unbounded();
+ let (timer_w, timer_r) = async_std::channel::unbounded();
+
+ input::spawn_task(event_w.clone(), input);
+
+ let frames = async_std::sync::Arc::new(async_std::sync::Mutex::new(
+ frames::FrameData::new(),
+ ));
+ spawn_frame_reader_task(event_w.clone(), frames.clone(), fh);
+ let timer_task =
+ spawn_timer_task(event_w.clone(), frames.clone(), timer_r);
+
+ event_loop(event_r, timer_w.clone(), output).await?;
+
timer_w.send(event::TimerAction::Quit).await?;
timer_task.await;