1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Status spinner demo -- shows a spinner with status messages while "doing work".
//!
//! Run with: `cargo run --example status`
//!
//! Port of Python rich's status.py demo. Demonstrates the Status widget
//! which combines a Spinner with a Live display for animated feedback.
use std::thread;
use std::time::Duration;
use gilt::console::Console;
use gilt::status::Status;
fn main() {
let console = Console::builder()
.force_terminal(true)
.no_color(false)
.build();
let tasks = [
"Downloading data",
"Processing files",
"Training model",
"Evaluating results",
"Generating report",
];
let mut status = Status::new("Getting ready...").with_console(console);
status.start();
for (i, task) in tasks.iter().enumerate() {
// Update the status message for the current task.
status
.update()
.status(&format!("{} ({}/{})...", task, i + 1, tasks.len()))
.apply()
.unwrap();
// Simulate work.
thread::sleep(Duration::from_secs(1));
eprintln!(" Done: {}", task);
}
status.stop();
eprintln!();
eprintln!("All tasks complete!");
}