#terminal-size #bar #loading #customizable #color #automatic #adjusts

bin+lib rbar

A simple, customizable loading/progress bar that gets the terminal width and automatically adjusts

7 releases

1.1.1 Apr 27, 2023
1.0.4 Apr 27, 2023
0.2.2 Jun 10, 2023
0.2.1 Apr 28, 2023
0.0.0 Apr 27, 2023

#16 in #terminal-size

Download history 27/week @ 2024-07-29 27/week @ 2024-09-23

107 downloads per month

MIT license

6KB
58 lines

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...

Dependencies

~2–10MB
~124K SLoC