use smart_markdown::{StreamRenderer, ThemeMode};
use std::io::{self, Write};
use std::thread;
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut sr = StreamRenderer::new(80, ThemeMode::Dark);
println!("Streaming Table Updates Demo\n--------------------------\n");
for line in sr.push("# Real-time Data Analysis\n\n") {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(300));
for line in sr.push("| Time | Metric | Value | Status |\n") {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(300));
for line in sr.push("|------|--------|-------|--------|\n") {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(300));
let lines = sr.push("| 10:00 | CPU Usage | 45% | Normal |\n");
for line in lines {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(500));
let lines = sr.push("| 10:05 | CPU Usage | 67% | Warning |\n");
for line in lines {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(500));
let lines = sr.push("| 10:10 | CPU Usage | 82% | Alert |\n");
for line in lines {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(500));
let lines = sr.push("| 10:15 | CPU Usage | 95% | Critical |\n");
for line in lines {
println!("{line}");
}
io::stdout().flush()?;
thread::sleep(Duration::from_millis(500));
for line in sr.flush_remaining() {
println!("{line}");
}
println!();
Ok(())
}