aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/ttyplay
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-04 02:08:27 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-04 02:08:27 -0500
commit33cc13b554e6f4cc6e139b0eecf5c6e697433a9d (patch)
tree59a6558bb7f824852f823d6a9d47c9034c3ab613 /src/bin/ttyplay
parent922151a0ad78027a54e6d0da6555117493e67ef8 (diff)
downloadttyrec-bin-33cc13b554e6f4cc6e139b0eecf5c6e697433a9d.tar.gz
ttyrec-bin-33cc13b554e6f4cc6e139b0eecf5c6e697433a9d.zip
initial implementation
Diffstat (limited to 'src/bin/ttyplay')
-rw-r--r--src/bin/ttyplay/main.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/bin/ttyplay/main.rs b/src/bin/ttyplay/main.rs
new file mode 100644
index 0000000..f30cda4
--- /dev/null
+++ b/src/bin/ttyplay/main.rs
@@ -0,0 +1,43 @@
+use textmode::Textmode as _;
+
+#[derive(Debug, structopt::StructOpt)]
+#[structopt(about = "ttyplay")]
+struct Opt {
+ #[structopt(short, long, default_value = "ttyrec")]
+ file: std::ffi::OsString,
+}
+
+async fn async_main(opt: Opt) -> anyhow::Result<()> {
+ let Opt { file } = opt;
+
+ let fh = async_std::fs::File::open(file).await?;
+ let mut reader = ttyrec::Reader::new(fh);
+
+ 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 mut last_frame_time = None;
+ while let Ok(frame) = reader.read_frame().await {
+ if let Some(time) = last_frame_time {
+ async_std::task::sleep(frame.time - time).await;
+ }
+ output.write(&frame.data);
+ output.refresh().await?;
+ last_frame_time = Some(frame.time);
+ }
+
+ Ok(())
+}
+
+#[paw::main]
+fn main(opt: Opt) {
+ match async_std::task::block_on(async_main(opt)) {
+ Ok(_) => (),
+ Err(e) => {
+ eprintln!("ttyplay: {}", e);
+ std::process::exit(1);
+ }
+ };
+}