1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::too_many_lines)]
mod display;
mod event;
mod frames;
mod input;
mod timer;
#[derive(Debug, structopt::StructOpt)]
#[structopt(about = "ttyplay")]
struct Opt {
#[structopt(short, long, default_value = "ttyrec")]
file: std::ffi::OsString,
#[structopt(long)]
clamp: Option<u64>,
#[structopt(short, long)]
paused: bool,
#[structopt(short, long, default_value = "4")]
speed: u32,
}
async fn async_main(opt: Opt) -> anyhow::Result<()> {
let Opt {
file,
clamp,
paused,
speed,
} = opt;
let speed = speed.clamp(0, 8);
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 frame_data = async_std::sync::Arc::new(async_std::sync::Mutex::new(
frames::FrameData::new(),
));
frames::load_from_file(frame_data.clone(), fh, event_w.clone(), clamp);
let timer_task = timer::spawn_task(
event_w.clone(),
frame_data.clone(),
timer_r,
paused,
speed,
);
event::handle_events(event_r, timer_w.clone(), output).await?;
timer_w.send(event::TimerAction::Quit).await?;
timer_task.await;
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);
}
};
}
|