|
@ -10,22 +10,26 @@ use stopwatch::*; |
|
|
extern crate crossbeam_channel;
|
|
|
extern crate crossbeam_channel;
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
fn main() {
|
|
|
|
|
|
if let Err(err) = run() {
|
|
|
|
|
|
println!("{}", err);
|
|
|
|
|
|
std::process::exit(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn run() -> std::io::Result<()> {
|
|
|
// 30 fps should be enough
|
|
|
// 30 fps should be enough
|
|
|
let step_duration = std::time::Duration::from_millis(1000 / 30);
|
|
|
let step_duration = std::time::Duration::from_millis(1000 / 30);
|
|
|
let start = Instant::now();
|
|
|
let start = Instant::now();
|
|
|
let ticker = tick(step_duration);
|
|
|
let ticker = tick(step_duration);
|
|
|
|
|
|
|
|
|
let signals = match signal_handler() {
|
|
|
|
|
|
Ok(r) => r,
|
|
|
|
|
|
Err(err) => {
|
|
|
|
|
|
println!("{}", err);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
let signals = signal_handler()?;
|
|
|
|
|
|
let input = input_handler()?;
|
|
|
|
|
|
|
|
|
let out = stdout();
|
|
|
let out = stdout();
|
|
|
let mut out = out.lock();
|
|
|
let mut out = out.lock();
|
|
|
let mut elapsed = FmtDuration::from(start.elapsed());
|
|
|
let mut elapsed = FmtDuration::from(start.elapsed());
|
|
|
|
|
|
let mut last_round = start.clone();
|
|
|
|
|
|
let mut round: u32 = 1;
|
|
|
|
|
|
|
|
|
loop {
|
|
|
loop {
|
|
|
select! {
|
|
|
select! {
|
|
@ -38,7 +42,13 @@ fn main() { |
|
|
recv(signals) -> _ => {
|
|
|
recv(signals) -> _ => {
|
|
|
reset_line(&mut out).unwrap();
|
|
|
reset_line(&mut out).unwrap();
|
|
|
writeln!(out, "Total time: {}", elapsed).unwrap();
|
|
|
writeln!(out, "Total time: {}", elapsed).unwrap();
|
|
|
return;
|
|
|
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
}
|
|
|
|
|
|
recv(input) -> _ => {
|
|
|
|
|
|
reset_line(&mut out)?;
|
|
|
|
|
|
writeln!(out, "Lap {}: {}", round, FmtDuration::from(last_round.elapsed()))?;
|
|
|
|
|
|
last_round = Instant::now();
|
|
|
|
|
|
round +=1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|