Crates.io | termprogress |
lib.rs | termprogress |
version | 0.10.0 |
source | src |
created_at | 2020-07-24 02:13:13.658076 |
updated_at | 2023-08-01 23:24:08.966493 |
description | A terminal progress bar renderer with status and spinners |
homepage | |
repository | |
max_upload_size | |
id | 268858 |
size | 78,825 |
Simple and customiseable terminal progress bars for Rust.
The bar at 50, 75, and 100%:
[========================= ]: 50.00% some title
[===================================== ]: 75.00% some other title
[==================================================]: 100.00% some other title
The spinner in 4 stages:
Some title /
Some title -
Some title \
Some title |
To quickly use the default bar and spinner, you can include the prelude
:
use termprogress::prelude::*;
let mut progress = Bar::default(); // Create a new progress bar
progress.set_title("Work is being done...");
/// *does work*
progress.set_progress(0.25);
progress.set_progress(0.5);
progress.println("Something happened");
progress.set_progress(0.75);
progress.println("Almost done...");
progress.set_progress(1.0);
/// completes
progress.complete();
Spinner:
use termprogress::prelude::*;
let mut spinner = Spin::default(); //Create a new spinner
/// *does work*
spinner.bump();
spinner.bump();
progress.println("Something happened");
spinner.bump();
spinner.bump();
/// completes
progress.complete_with("Done!");
By default, the size
feature is enabled, which requires the dependency terminal_size
.
Without this, Bar
will not attempt to get the terminal's size to prevent overflows. You can disable it with default-features=false
.
The library comes with traits for progress bars: ProgressBar
, and Spinner
.
The default implementations for these are Bar
and Spin
, but you can provide your own implementations too for more customisability.
There is also Silent
, which implements both ProgressBar
and Spinner
, and does nothing, to allow for easily turning off or on progress displays depending on config.
pub fn does_work<P: ProgressBar>(bar: &mut P)
{
//does work...
bar.set_progress(0.5);
//more work...
bar.set_progress(1.0);
}
does_work(&mut Bar::default());
does_work(&mut MyBar::new());
if NOPROGRESS {
does_wotk(&mut Silent)
} else {
does_work(&mut Bar::default())
}
GPL'd with love <3