13 stable releases

3.0.2 Sep 1, 2020
2.2.3 Mar 27, 2020
2.2.0 Jan 31, 2020
1.0.3 Jan 25, 2020

#37 in Command-line interface

Download history 13/week @ 2021-02-25 12/week @ 2021-03-04 7/week @ 2021-03-11 115/week @ 2021-03-18 117/week @ 2021-03-25 69/week @ 2021-04-01 111/week @ 2021-04-08 439/week @ 2021-04-15 191/week @ 2021-04-22 132/week @ 2021-04-29 416/week @ 2021-05-06 80/week @ 2021-05-13 174/week @ 2021-05-20 106/week @ 2021-05-27 58/week @ 2021-06-03 38/week @ 2021-06-10

604 downloads per month
Used in 2 crates

Apache-2.0

31KB
722 lines

progressing

Build Status nightly

Tag Crates.io Docs

Changelog Last commit

License

Look and feel

At first, the trait Baring is needed.

use progressing::{
    // The underlying Trait
    Baring,
    // Just handy names for the examples below
    bernoulli::Bar as BernoulliBar,
    clamping::Bar as ClampingBar,
    mapping::Bar as MappingBar,
};

In the following, different use-cases of the provided progress-bars are presented. Note, that the examples below use set(...), but add(...) is supported as well.

  • Printing value 0.3 clamped to [0, 1] prints [=====>------------].

    let mut progress_bar = ClampingBar::new();
    progress_bar.set_len(20);
    progress_bar.set(0.3);
    println!("{}", progress_bar);
    
  • Printing value 4 mapped from [-9, 5] to [0, 1] prints [================>-] (4 / 5).

    let mut progress_bar = MappingBar::with_range(-9, 5);
    progress_bar.set_len(20);
    progress_bar.set(4);
    println!("{}", progress_bar);
    
  • Every bar can be used with a simple time-approximation based on the past process. For a process of this duration, this example would print [================>-] (4 / 5) ~ 2 min. The only difference is the call of timed().

    let mut progress_bar = MappingBar::with_range(-9, 5).timed();
    progress_bar.set_len(20);
    progress_bar.set(4);
    println!("{}", progress_bar);
    
  • In case something should be counted and failures may occur, try this example. When counting 42 successes, where 60 is the goal and 130 attempts have been made, [============>-----] (42 / 60 # 130) is printed. Adding trials may be handier using bools.

    let mut progress_bar = BernoulliBar::from_goal(60);
    progress_bar.set_len(20);
    progress_bar.set((42, 130));
    println!("{}", progress_bar);
    
    let is_successful = true;
    if is_successful {
        // Does increase both 42 and 130
        progress_bar.add(true);
    } else {
        // Does increase 130 only
        progress_bar.add(false);
    }
    
  • You may change a bar's style by setting it to a string of 5 characters.

    let mut progress_bar = ClampingBar::new();
    progress_bar.set_len(20);
    progress_bar.set(0.3);
    
    // different custom styles are possible
    
    // prints (----->............)
    progress_bar.set_style("(->.)");
    println!("{}", progress_bar);
    
    // prints [#####             ]
    progress_bar.set_style("[#  ]");
    println!("{}", progress_bar);
    
    // prints (#####-------------)
    progress_bar.set_style("(#--)");
    println!("{}", progress_bar);
    
  • Another typical use-case may be printing some, not every progress in a loop.

    let mut progress_bar = BernoulliBar::with_goal(100).timed();
    progress_bar.set_len(20);
    progress_bar.set(13);
    
    // do the job and show progress
    for _ in 0..100 {
        progress_bar.add(true);
        if progress_bar.has_progressed_significantly() {
            progress_bar.remember_significant_progress();
            println!("{}", progress_bar);
        }
    
        std::thread::sleep(std::time::Duration::from_millis(100));
    }
    println!("{}", progress_bar);
    

    will print

    [=>................] (10/100) #14 ~8s
    [===>..............] (20/100) #20 ~7s
    [=====>............] (30/100) #30 ~6s
    [=======>..........] (40/100) #40 ~5s
    [=========>........] (50/100) #50 ~4s
    [==========>.......] (60/100) #60 ~3s
    [============>.....] (70/100) #70 ~2s
    [==============>...] (80/100) #80 ~1s
    [================>.] (90/100) #90 ~0s
    [==================] (100/100) #100 ~0s
    [==================] (100/100) #113 ~0s
    

    A line is printed every time when another 10 % of the goal is reached. Please note, that the progress-bar starts with 13 and hence needs 113 attempts in total.

Setup and usage

Just add progressing = '3' to the dependencies in Cargo.toml.

Please refer to the examples for some more examples.

Dependencies

~82KB