Styling

ProgressStyle combines a parsed template, progress characters, spinner frames, optional line color, and custom keys.

Template Variables

VariableFormat SpecDescriptionExample Output
{bar}:40, :40.#/-Progress bar########>-------
{wide_bar}noneWidth-adaptive progress barfills remaining columns
{pos}noneCurrent position42
{count}noneCompact current position1.2k
{human_pos}noneAlias for compact position1.2k
{len}noneTotal length or ?100
{total_count}noneCompact total length1.5M
{human_len}noneAlias for compact total length1.5M
{remaining}noneRemaining units58
{human_remaining}noneCompact remaining units58.0k
{ratio}:.3Completion ratio0.420
{percent}:.2Percentage without %42 or 42.50
{elapsed}noneHuman elapsed time3m 14s
{elapsed_precise}nonePrecise elapsed time00:03:14
{elapsed_millis}noneMillisecond elapsed time00:03:14.123
{eta}noneEstimated remaining time~12s
{eta_precise}nonePrecise ETA00:00:12
{eta_millis}noneMillisecond ETA00:00:12.345
{per_sec}:.2Average rate123.45
{rate}noneFormatted item rate1.23k items/s
{bytes}nonePosition as bytes1.00 MB
{total_bytes}noneLength as bytes50.00 MB
{bytes_per_sec}noneByte throughput1.23 MB/s
{spinner}noneCurrent spinner frame-
{msg}:20, :>20, :^20Message with optional padding/truncationdownloading
{prefix}:10, :>10, :^10Prefix with optional padding/truncationtask
{postfix}:10, :>10, :^10Postfix with optional padding/truncationok
{status}:10, :>10, :^10running, spinning, finished, or abandonedrunning
{wide_msg}none, :20, :>20, :^20Terminal-width or explicit-width message fieldterminal-width text

Bar Format

{bar:N} sets the width. {bar:N.fill/empty} sets fill and empty characters. Color words inside a template are accepted for compatibility with terminal-style templates; whole-line color is configured with ColorSpec.

{wide_bar} uses the active draw target width. Width detection uses terminal APIs and falls back to COLUMNS/LINES or safe defaults when a TTY is not available.

#![allow(unused)]
fn main() {
let style = loaders::ProgressStyle::with_template(
    "{prefix} [{bar:30.#/-}] {percent:.1}% {msg}",
)?;
Ok::<(), loaders::bar::template::TemplateError>(())
}

Reusable Progress Characters

ProgressChars stores fill, head, and empty characters as a reusable value.

#![allow(unused)]
fn main() {
use loaders::{ProgressChars, ProgressStyle};

let style = ProgressStyle::default_bar()
    .progress_chars_set(ProgressChars::blocks());
}

Use try_progress_chars when parsing user configuration and invalid inputs should return an error.

Text Padding and Truncation

String variables support width specs for alignment and fixed width:

  • :20 left-aligned width 20
  • :>20 right-aligned width 20
  • :^20 centered width 20

When the content is longer than the width it is truncated to fit.

Colors

#![allow(unused)]
fn main() {
use loaders::{Color, ColorSpec, ProgressStyle};

let style = ProgressStyle::default_bar()
    .color(ColorSpec::new().set_fg(Color::Cyan).set_bold(true));
}

Custom Keys

#![allow(unused)]
fn main() {
let style = loaders::ProgressStyle::with_template("{phase} {bar:20}")?
    .with_key("phase", |state| format!("phase {}", state.pos / 10 + 1));
Ok::<(), loaders::bar::template::TemplateError>(())
}