Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn load_and_verify_catalog(
let catalog_filename = catalog.metadata().signature_file_path().clone();
let algo = catalog.metadata().algo();

let bar = crate::progress::ProgressBar::new(Some(catalog.len()));
let bar = crate::progress::ProgressBar::new_with_description(Some(catalog.len()), "Verifying");

let mut report = crate::parallel::for_each(catalog.into_iter(), move |entry| {
let res = entry
Expand Down Expand Up @@ -209,7 +209,7 @@ fn create_catalog(params: SignParams, config: &config::Config) -> anyhow::Result

let mut catalog = directory.empty_catalog(algo);

let bar = crate::progress::ProgressBar::new(None);
let bar = crate::progress::ProgressBar::new_with_description(None, "Signing");

catalog.populate_with_progress(Some(bar))?;

Expand Down
36 changes: 16 additions & 20 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,36 @@ use indicatif::{HumanBytes, ProgressDrawTarget, ProgressStyle};

const SIZE_UPDATE_FREQ: std::time::Duration = std::time::Duration::from_secs(3);

const PROGRESS_BAR_TEMPLATE: &str =
"[{elapsed_precise}] {bar:40.cyan/blue} {prefix} {pos:>7}/{len:7} {msg}";
const SPINNER_TEMPLATE: &str =
"[{elapsed_precise}] {spinner:.cyan/blue} {prefix} {pos:>7}/{prefix}+ {msg}";

#[derive(Clone)]
pub struct ProgressBar {
bar: Arc<indicatif::ProgressBar>,
size: Arc<AtomicU64>,
discovered_count: Arc<AtomicU64>,
description: &'static str,
}

impl ProgressBar {
pub fn new(len: Option<usize>) -> Self {
pub fn new_with_description(len: Option<usize>, description: &'static str) -> Self {
let bar = match len {
Some(length) => {
let bar = indicatif::ProgressBar::new(length.try_into().unwrap());
bar.set_style(
ProgressStyle::with_template(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)
.unwrap(),
);
bar.set_style(ProgressStyle::with_template(PROGRESS_BAR_TEMPLATE).unwrap());
bar
}
None => {
let bar = indicatif::ProgressBar::new_spinner();
bar.set_style(
ProgressStyle::with_template(
"[{elapsed_precise}] {spinner:.cyan/blue} {pos:>7}/{prefix}+ {msg}",
)
.unwrap(),
);
bar.set_style(ProgressStyle::with_template(SPINNER_TEMPLATE).unwrap());
bar
}
};

bar.set_draw_target(ProgressDrawTarget::stderr_with_hz(5));
bar.set_prefix(description);
let bar = Arc::new(bar);
let size = Arc::new(AtomicU64::default());
let discovered_count = Arc::new(AtomicU64::default());
Expand Down Expand Up @@ -73,17 +70,15 @@ impl ProgressBar {
bar,
size,
discovered_count,
description,
}
}

pub fn set_length(&self, len: usize) {
self.bar.set_length(len.try_into().unwrap());
self.bar.set_style(
ProgressStyle::with_template(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)
.unwrap(),
);
self.bar
.set_style(ProgressStyle::with_template(PROGRESS_BAR_TEMPLATE).unwrap());
self.bar.set_prefix(self.description);
}

pub fn notify_file_discovered(&self) {
Expand All @@ -92,7 +87,8 @@ impl ProgressBar {
let count = self
.discovered_count
.load(std::sync::atomic::Ordering::Relaxed);
self.bar.set_prefix(count.to_string());
self.bar
.set_prefix(format!("{} {}", self.description, count));
}

pub fn notify_record_processed(&self, record_size: Option<u64>) {
Expand Down