1 stable release

1.0.0 Nov 8, 2023

#580 in Command-line interface

MIT license

13KB
168 lines

Borderline

Borderline is a Crate to render borders to the terminal. You can place text or progress bars inside the borders. The usage is as simple as:

use borderline::LineBuilder;

// Create a line builder:
let mut lb = LineBuilder::new();

// Print the header first:
borderline::print_header("Borderline Test-Drive");

// Now, we are able to attach as many "line" as we want.
// Every line must be started with a call to `line_begin`
// and ended with a call to `line_end`:
lb.line_begin("- Loading...");

// perform other actions here...

// When ending a line, you can specify the second part
// of the line, which will be printed on the right side:
lb.line_end("done.");

// You can also print a progress bar:
lb.line_begin("- Loading many files:");

// Set up the progress bar using the total number of steps:
lb.progress_bar_setup(1_000);

// Do some work and update the progress bar:
for i in 0..1_000 {
    sleep(std::time::Duration::from_millis(50));
    lb.progress_bar_update(i);
}

// End the progress bar:
lb.progressbar_end();

// End the line and print the second text part:
lb.line_end("done.");

// At the end, we can print the closing border:
borderline::print_border();

While the progress bar is active: progressbar.png

When the program is done: done.png

In case that the given text is too long, it gets wrapped at word boundaries. When this is not possible, the text is wrapped at the given width.

Changelog

Version 1.0.0

  • Initial release

No runtime deps