use core::time;
use std::{
    fs::File,
    io::{BufRead, BufReader, Write},
    time::{Instant, SystemTime},
};

fn main() -> Result<(), color_eyre::Report> {
    color_eyre::install().unwrap();
    let stderr = std::io::stdin();
    let mut lines = BufReader::new(stderr).lines();
    let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
    let mut file = File::options()
        .create_new(true)
        .write(true)
        .truncate(true)
        .open(format!("{}.log", now.as_secs()))?;

    let start = Instant::now();
    while let Some(Ok(next)) = lines.next() {
        let line = format!("{}~{next}\n", start.elapsed().as_millis());
        file.write_all(line.as_bytes())?;
    }
    file.flush()?;

    Ok(())
}
