Skip to main content

streaming/
streaming.rs

1use smart_markdown::Markdown;
2use std::io::{self, Write};
3use std::thread;
4use std::time::Duration;
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut md = Markdown::parse(
8        "## Build Pipeline\n\n\
9         | Task    | Status  | Details                         |\n\
10         |---------|---------|---------------------------------|\n\
11         | build   | pending |                                 |\n\
12         | test    | pending |                                 |\n\
13         | deploy  | pending |                                 |\n\
14         \n\
15         _Live streaming table update demo_\n\n\
16         \n\
17         ### Task Status\n\n\
18         - [x] Compile source\n\
19         - [x] Run unit tests\n\
20         - [ ] Integration tests\n\
21         - [ ] Deploy to staging\n\
22         \n\
23         See the pipeline logs or visit <https://ci.example.com>\n\
24         for detailed build output.\n",
25    );
26
27    println!("\nStreaming Markdown Demo\n-----------------------\n");
28    md.render();
29    io::stdout().flush()?;
30    thread::sleep(Duration::from_millis(800));
31
32    md.append_to_cell(0, 2, "compiling source");
33    md.render();
34    io::stdout().flush()?;
35    thread::sleep(Duration::from_millis(800));
36
37    md.append_to_cell(0, 2, " files...");
38    md.render();
39    io::stdout().flush()?;
40    thread::sleep(Duration::from_millis(800));
41
42    md.append_to_cell(1, 2, "running unit tests across all crates");
43    md.render();
44    io::stdout().flush()?;
45    thread::sleep(Duration::from_millis(800));
46
47    md.set_cell_content(0, 1, "done");
48    md.render();
49    io::stdout().flush()?;
50    thread::sleep(Duration::from_millis(800));
51
52    md.set_cell_content(1, 1, "running");
53    md.append_to_cell(1, 2, " with coverage instrumentation enabled for llvm-cov");
54    md.render();
55    io::stdout().flush()?;
56    thread::sleep(Duration::from_millis(1200));
57
58    md.set_cell_content(2, 1, "queued");
59    md.append_to_cell(0, 2, " and linking final binary artifact");
60    md.render();
61    io::stdout().flush()?;
62    thread::sleep(Duration::from_millis(800));
63
64    md.set_cell_content(2, 1, "done");
65    md.set_cell_content(2, 2, "release published to registry");
66    md.render();
67    io::stdout().flush()?;
68    thread::sleep(Duration::from_millis(800));
69
70    println!();
71
72    Ok(())
73}