use gilt::live::Live;
use gilt::markdown::Markdown;
use std::thread;
use std::time::Duration;
fn main() {
let document = "\
# Streaming Markdown
Watch this **render live** as tokens arrive — headings, *emphasis*,
`inline code`, lists, and a fenced code block all reflow at your terminal's
width because the document is re-rendered through the live console each frame.
## Highlights
- Rendered through the **live console** — correct width and theme
- Resize-responsive: the whole document re-lays-out every frame
- One call per chunk: `live.update_renderable(Markdown::new(acc), true)`
## Usage
```rust
let mut live = Live::from_renderable(Markdown::new(\"\"));
live.start();
for chunk in stream {
acc.push_str(chunk);
live.update_renderable(Markdown::new(&acc), true);
}
live.stop();
```
Any `Renderable` — `Table`, `Tree`, `Panel`, `Layout` — works the same way.
";
let tokens: Vec<&str> = document.split_inclusive(char::is_whitespace).collect();
let mut live = Live::from_renderable(Markdown::new("")).with_auto_refresh(false);
live.start();
let mut acc = String::new();
for token in tokens {
acc.push_str(token);
live.update_renderable(Markdown::new(&acc), true);
thread::sleep(Duration::from_millis(25));
}
thread::sleep(Duration::from_millis(800));
live.stop();
}