1use std::{
2 io::{Write, stdout},
3 thread,
4 time::Duration,
5};
6
7use crossterm::{cursor, execute, style::Print, terminal};
8
9use crate::PER_CHARACTER_DELAY_MS;
10
11pub struct View {}
14
15impl View {
16 pub fn animate(data: &[String]) -> std::io::Result<()> {
18 let mut stdout = stdout();
19
20 execute!(
22 stdout,
23 terminal::Clear(terminal::ClearType::All),
24 cursor::MoveTo(0, 0),
25 cursor::Hide
26 )?;
27
28 for (y, line) in data.iter().enumerate() {
29 for (x, c) in line.chars().enumerate() {
30 execute!(stdout, cursor::MoveTo((x * 2) as u16, y as u16), Print(c))?;
31 stdout.flush()?;
32 thread::sleep(Duration::from_millis(PER_CHARACTER_DELAY_MS));
33 }
34 }
35
36 execute!(stdout, cursor::MoveTo(0, data.len() as u16), cursor::Show)?;
38
39 Ok(())
40 }
41}