ProgressBar

Struct ProgressBar 

Source
pub struct ProgressBar { /* private fields */ }

Implementations§

Source§

impl ProgressBar

Source

pub fn new(total: u64, message: impl Into<String>) -> (Self, ProgressHandle)

Examples found in repository?
examples/progress_basic.rs (line 8)
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}
More examples
Hide additional examples
examples/p1_demo.rs (line 36)
5fn main() {
6    println!("=== P1 Components Demo ===\n");
7
8    // 1. MultiSelect
9    let languages = match MultiSelect::new("Select languages you know:")
10        .option("Rust", "rust")
11        .option("Python", "python")
12        .option("JavaScript", "javascript")
13        .option("Go", "go")
14        .run()
15    {
16        Ok(langs) => langs,
17        Err(e) => {
18            eprintln!("Error: {}", e);
19            return;
20        }
21    };
22
23    println!("\nSelected: {:?}\n", languages);
24
25    // 2. Spinner
26    let (spinner, handle) = Spinner::new("Analyzing your selections...");
27    let task = thread::spawn(move || {
28        thread::sleep(Duration::from_secs(2));
29        handle.finish();
30    });
31    spinner.run().unwrap();
32    task.join().unwrap();
33    println!("✓ Analysis complete\n");
34
35    // 3. ProgressBar
36    let (bar, handle) = ProgressBar::new(100, "Generating recommendations...");
37    let task = thread::spawn(move || {
38        for _ in 0..100 {
39            thread::sleep(Duration::from_millis(30));
40            handle.inc(1);
41        }
42        handle.finish();
43    });
44    bar.run().unwrap();
45    task.join().unwrap();
46    println!("✓ Recommendations ready\n");
47
48    // 4. Confirm
49    let save = match Confirm::new("Save your profile?").default(true).run() {
50        Ok(s) => s,
51        Err(e) => {
52            eprintln!("Error: {}", e);
53            return;
54        }
55    };
56
57    if save {
58        println!("\n✓ Profile saved!");
59    } else {
60        println!("\n✗ Profile not saved");
61    }
62}
Source

pub fn run(self) -> Result<()>

Examples found in repository?
examples/progress_basic.rs (line 25)
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}
More examples
Hide additional examples
examples/p1_demo.rs (line 44)
5fn main() {
6    println!("=== P1 Components Demo ===\n");
7
8    // 1. MultiSelect
9    let languages = match MultiSelect::new("Select languages you know:")
10        .option("Rust", "rust")
11        .option("Python", "python")
12        .option("JavaScript", "javascript")
13        .option("Go", "go")
14        .run()
15    {
16        Ok(langs) => langs,
17        Err(e) => {
18            eprintln!("Error: {}", e);
19            return;
20        }
21    };
22
23    println!("\nSelected: {:?}\n", languages);
24
25    // 2. Spinner
26    let (spinner, handle) = Spinner::new("Analyzing your selections...");
27    let task = thread::spawn(move || {
28        thread::sleep(Duration::from_secs(2));
29        handle.finish();
30    });
31    spinner.run().unwrap();
32    task.join().unwrap();
33    println!("✓ Analysis complete\n");
34
35    // 3. ProgressBar
36    let (bar, handle) = ProgressBar::new(100, "Generating recommendations...");
37    let task = thread::spawn(move || {
38        for _ in 0..100 {
39            thread::sleep(Duration::from_millis(30));
40            handle.inc(1);
41        }
42        handle.finish();
43    });
44    bar.run().unwrap();
45    task.join().unwrap();
46    println!("✓ Recommendations ready\n");
47
48    // 4. Confirm
49    let save = match Confirm::new("Save your profile?").default(true).run() {
50        Ok(s) => s,
51        Err(e) => {
52            eprintln!("Error: {}", e);
53            return;
54        }
55    };
56
57    if save {
58        println!("\n✓ Profile saved!");
59    } else {
60        println!("\n✗ Profile not saved");
61    }
62}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.