aboutsummaryrefslogtreecommitdiffstats
path: root/examples/process_full.rs
blob: 3be0ec03cf70c4bb547dc63e8e06b01c598b60b1 (plain) (blame)
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
use std::io::Read as _;

fn read_frames() -> impl Iterator<Item = Vec<u8>> {
    (1..=7625).map(|i| {
        let mut file =
            std::fs::File::open(format!("tests/data/crawl/crawl{}", i))
                .unwrap();
        let mut frame = vec![];
        file.read_to_end(&mut frame).unwrap();
        frame
    })
}

fn draw_frames(frames: &[Vec<u8>]) {
    let stdout = std::io::stdout();
    let mut stdout = stdout.lock();
    let mut parser = vt100::Parser::default();
    for frame in frames {
        parser.process(&frame);
        parser
            .screen()
            .write_contents_formatted(&mut stdout)
            .unwrap();
    }
}

fn main() {
    let frames: Vec<Vec<u8>> = read_frames().collect();
    let start = std::time::Instant::now();
    let mut i = 0;
    loop {
        i += 1;
        draw_frames(&frames);
        if (std::time::Instant::now() - start).as_secs() >= 30 {
            break;
        }
    }
    eprintln!("{} iterations", i);
}