table_streaming/
table_streaming.rs1use smart_markdown::{StreamRenderer, ThemeMode};
2use std::io::{self, Write};
3use std::thread;
4use std::time::Duration;
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let mut sr = StreamRenderer::new(80, ThemeMode::Dark);
8
9 println!("Streaming Table Updates Demo\n--------------------------\n");
10
11 for line in sr.push("# Real-time Data Analysis\n\n") {
13 println!("{line}");
14 }
15 io::stdout().flush()?;
16 thread::sleep(Duration::from_millis(300));
17
18 for line in sr.push("| Time | Metric | Value | Status |\n") {
19 println!("{line}");
20 }
21 io::stdout().flush()?;
22 thread::sleep(Duration::from_millis(300));
23
24 for line in sr.push("|------|--------|-------|--------|\n") {
25 println!("{line}");
26 }
27 io::stdout().flush()?;
28 thread::sleep(Duration::from_millis(300));
29
30 let lines = sr.push("| 10:00 | CPU Usage | 45% | Normal |\n");
32 for line in lines {
33 println!("{line}");
34 }
35 io::stdout().flush()?;
36 thread::sleep(Duration::from_millis(500));
37
38 let lines = sr.push("| 10:05 | CPU Usage | 67% | Warning |\n");
39 for line in lines {
40 println!("{line}");
41 }
42 io::stdout().flush()?;
43 thread::sleep(Duration::from_millis(500));
44
45 let lines = sr.push("| 10:10 | CPU Usage | 82% | Alert |\n");
46 for line in lines {
47 println!("{line}");
48 }
49 io::stdout().flush()?;
50 thread::sleep(Duration::from_millis(500));
51
52 let lines = sr.push("| 10:15 | CPU Usage | 95% | Critical |\n");
53 for line in lines {
54 println!("{line}");
55 }
56 io::stdout().flush()?;
57 thread::sleep(Duration::from_millis(500));
58
59 for line in sr.flush_remaining() {
61 println!("{line}");
62 }
63
64 println!();
65 Ok(())
66}