streaming_demo/
streaming_demo.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!(
10 "Streaming Markdown Demo with Table Updates\n----------------------------------------\n"
11 );
12
13 for line in sr.push("# Live Data Dashboard\n\n") {
15 println!("{line}");
16 }
17 io::stdout().flush()?;
18 thread::sleep(Duration::from_millis(200));
19
20 for line in sr.push("## System Metrics\n\n") {
21 println!("{line}");
22 }
23 io::stdout().flush()?;
24 thread::sleep(Duration::from_millis(200));
25
26 for line in sr.push("| Component | Status | Value | Trend |\n") {
28 println!("{line}");
29 }
30 io::stdout().flush()?;
31 thread::sleep(Duration::from_millis(200));
32
33 for line in sr.push("|-----------|--------|-------|-------|\n") {
34 println!("{line}");
35 }
36 io::stdout().flush()?;
37 thread::sleep(Duration::from_millis(200));
38
39 let lines = sr.push("| CPU Usage | Normal | 42% | → |\n");
41 for line in lines {
42 println!("{line}");
43 }
44 io::stdout().flush()?;
45 thread::sleep(Duration::from_millis(500));
46
47 let lines = sr.push("| Memory | Normal | 67% | ↗ |\n");
49 for line in lines {
50 println!("{line}");
51 }
52 io::stdout().flush()?;
53 thread::sleep(Duration::from_millis(500));
54
55 let lines = sr.push("| Disk I/O | High | 89% | ↗↗ |\n");
57 for line in lines {
58 println!("{line}");
59 }
60 io::stdout().flush()?;
61 thread::sleep(Duration::from_millis(500));
62
63 for line in sr.push("\n### Alerts\n\n") {
65 println!("{line}");
66 }
67 io::stdout().flush()?;
68 thread::sleep(Duration::from_millis(200));
69
70 for line in sr.push("- High disk I/O detected\n") {
72 println!("{line}");
73 }
74 io::stdout().flush()?;
75 thread::sleep(Duration::from_millis(200));
76
77 for line in sr.push("- Memory usage trending upward\n") {
78 println!("{line}");
79 }
80 io::stdout().flush()?;
81 thread::sleep(Duration::from_millis(200));
82
83 for line in sr.flush_remaining() {
85 println!("{line}");
86 }
87
88 println!();
89 Ok(())
90}