#progress-bar #status #progress #terminal #status-bar #terminal-text #text-formatting

status-line

This crate allows you to display status & progress information in a terminal

3 unstable releases

0.2.0 Dec 13, 2021
0.1.1 Nov 25, 2021
0.1.0 Nov 24, 2021

#627 in Command-line interface

Download history 4177/week @ 2024-07-26 3728/week @ 2024-08-02 3821/week @ 2024-08-09 5571/week @ 2024-08-16 5393/week @ 2024-08-23 4643/week @ 2024-08-30 5077/week @ 2024-09-06 5010/week @ 2024-09-13 5224/week @ 2024-09-20 6710/week @ 2024-09-27 6435/week @ 2024-10-04 4937/week @ 2024-10-11 6302/week @ 2024-10-18 5383/week @ 2024-10-25 5349/week @ 2024-11-01 5169/week @ 2024-11-08

23,076 downloads per month
Used in 2 crates

MIT license

11KB
111 lines

status-line

This crate allows you to display status & progress information in a terminal

Crates.io Documentation License: MIT

This crate handles the problem of displaying a small amount of textual information in a terminal, periodically refreshing it, and finally erasing it, similar to how progress bars are displayed.

A status line can be viewed as a generalization of a progress bar. Unlike progress bar drawing crates, this crate does not require that you render the status text as a progress bar. It does not enforce any particular data format or template, nor it doesn't help you with formatting.

The status line text may contain any information you wish, and may even be split into multiple lines. You fully control the data model, as well as how the data gets printed on the screen. The standard Display trait is used to convert the data into printed text.

Status updates can be made with a very high frequency, up to tens of millions of updates per second. StatusLine decouples redrawing rate from the data update rate by using a background thread to handle text printing with low frequency.

Example

use std::fmt::{Display, Formatter};
use std::sync::atomic::{AtomicU64, Ordering};
use status_line::StatusLine;

// Define the data model representing the status of your app.
// Make sure it is Send + Sync, so it can be read and written from different threads:
struct Progress(AtomicU64);

// Define how you want to display it:
impl Display for Progress {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}%", self.0.load(Ordering::Relaxed))
    }
}

// StatusLine takes care of displaying the progress data:
let status = StatusLine::new(Progress(AtomicU64::new(0)));   // shows 0%
status.0.fetch_add(1, Ordering::Relaxed);                    // shows 1%
status.0.fetch_add(1, Ordering::Relaxed);                    // shows 2%
drop(status)                                                 // hides the status line

Dependencies

~235KB