progress_basic/
progress_basic.rs

1use std::{thread, time::Duration};
2
3use xacli_components::ProgressBar;
4
5fn main() {
6    println!("=== ProgressBar Component Demo ===\n");
7
8    let (bar, handle) = ProgressBar::new(100, "Downloading...");
9
10    // 后台任务
11    let task = thread::spawn(move || {
12        for i in 0..100 {
13            thread::sleep(Duration::from_millis(50));
14            handle.inc(1);
15
16            // 在中途更新消息
17            if i == 50 {
18                handle.set_message("Processing...");
19            }
20        }
21        handle.finish();
22    });
23
24    // 运行进度条(阻塞主线程)
25    if let Err(e) = bar.run() {
26        eprintln!("Error: {}", e);
27    }
28
29    // 等待任务完成
30    task.join().unwrap();
31
32    println!("Done!");
33}