rbar

Crates.iorbar
lib.rsrbar
version0.2.2
sourcesrc
created_at2023-04-26 22:44:52.772817
updated_at2023-06-10 19:52:42.753036
descriptionA simple, customizable loading/progress bar that gets the terminal width and automatically adjusts
homepage
repositoryhttps://sr.ht/~parkman29/rbar
max_upload_size
id849864
size16,814
(parkman29)

documentation

README

rBar

This is just a simple customizable loading bar that scales to the size of your terminal and has the ability to print a message

Details

The current version is 0.2.2

str_to_color

Takes one argument, color and converts it into an ansi escape sequence,
  • The supported colors are: black, red, green, yellow, blue, magenta, cyan, & white

  • Anything else will result in the default terminal color

  • You may also use a custom ascii sequence and not use this

BarConf

  • Color: an ansi escape code within a string, you can use get_bar_color for this

  • Chars: list of chars, going from left to right:

    [beginning outline, filled, edge of filled, unfilled, ending outline]

draw_bar

The arguments are: percentage, message, message_before, bar_config

  • Percentage is a u8 (Usually 0-100)
  • Message is a str that can be any length
  • Message_before is a bool that determines if you want the message while loading to be before or after the bar text
  • Bar_config is the previous struct listed

Example:

use rbar;
use std::{thread, time};

// this example makes a loading bar similar to the one used by cargo
fn main() {
  for i in 0..100 {
    let bar = rbar::BarConf {
      color: rbar::str_to_color("default"),
      chars: ['[','=','>','-',']']
    };

    rbar::draw_bar(i, "Loading...", false, bar);
    thread::sleep(time::Duration::from_millis(100));
  }
}

Output:

[=>--------------------------------] 1%      Loading...

A little later...

[==================================] 100%    Loading...
Commit count: 0

cargo fmt