Skip to content

Commit

Permalink
Even fancier
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Mar 25, 2024
1 parent a51e414 commit 66769ca
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ use std::time::Duration;

use indicatif::{ProgressBar, ProgressStyle};

const PROGRESS_BAR_TEMPLATE: &str = "{msg} [{bar:32.cyan/blue}] {pos} / {len}";
const PROGRESS_BAR_CHARACTERS: &str = "▪▸-";
const PROGRESS_BAR_TEMPLATE: &str =
"{spinner:.bold.cyan} {msg:>11.bold.cyan} [{bar:32}] {pos} / {len}";
const PROGRESS_BAR_CHARACTERS: &str = "=> ";
const PROGRESS_BAR_TICKERS: &str = "⠙⠹⠸⠼⠴⠦⠧⠇⠏ ";

fn new_progress_style() -> ProgressStyle {
ProgressStyle::with_template(PROGRESS_BAR_TEMPLATE)
.unwrap()
.progress_chars(PROGRESS_BAR_CHARACTERS)
.tick_chars(PROGRESS_BAR_TICKERS)
}

pub fn new_progress_bar(message: impl Into<String>, length: usize) -> ProgressBar {
let pb = ProgressBar::new(length as u64)
.with_message(message.into())
.with_style(
ProgressStyle::with_template(PROGRESS_BAR_TEMPLATE)
.unwrap()
.progress_chars(PROGRESS_BAR_CHARACTERS),
);
pb.enable_steady_tick(Duration::from_millis(10));
let pb = ProgressBar::new_spinner()
.with_style(new_progress_style())
.with_message(message.into());
pb.enable_steady_tick(Duration::from_millis(60));
pb.set_length(length as u64);
pb
}

0 comments on commit 66769ca

Please sign in to comment.