#terminal #renderer #bar #type #passing #progress #status #spinners #bars

termprogress

A terminal progress bar renderer with status and spinners

6 releases

0.3.4 Aug 10, 2020
0.2.4 Aug 9, 2020
0.1.2 Jul 25, 2020
Download history 8/week @ 2022-04-20 60/week @ 2022-04-27 49/week @ 2022-05-04 96/week @ 2022-05-11 32/week @ 2022-05-18 31/week @ 2022-05-25 50/week @ 2022-06-01 17/week @ 2022-06-08 7/week @ 2022-06-15 10/week @ 2022-06-22 12/week @ 2022-06-29 6/week @ 2022-07-06 12/week @ 2022-07-13 18/week @ 2022-07-20 19/week @ 2022-07-27 23/week @ 2022-08-03

74 downloads per month
Used in leanify-many

GPL-3.0-or-later

26KB
851 lines

Termprogress - Terminal progress bars

Simple and customiseable terminal progress bars for Rust.

Features

  • Customiseable, has a traits system to allow for passing any type of progress bar around
  • Optionally prevents long titles from overflowing the terminal by using the terminal_size crate
  • Interfaces for easily manipulating bar

How it looks

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 |

Getting started.

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!");

Default features

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.

Traits

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())
}

License

GPL'd with love <3

Dependencies

~45KB