Skip to content

Commit

Permalink
Instead of ProgressStyle, use separate progress_template and progress…
Browse files Browse the repository at this point in the history
…_chars strings

so we can still derive Debug, as ProgressStyle in indicatif 0.17 does not implement debug anymore with its progresstracker
  • Loading branch information
jqnatividad committed Sep 5, 2022
1 parent 690ca3f commit 2747fc3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ pub struct Download {
show_progress: bool,
url: String,
headers: reqwest::header::HeaderMap,
progress_style: ProgressStyle,
progress_template: String,
progress_chars: String,
}
impl Download {
/// Specify download url
Expand All @@ -616,9 +617,8 @@ impl Download {
show_progress: false,
url: url.to_owned(),
headers: reqwest::header::HeaderMap::new(),
progress_style: ProgressStyle::default_bar()
.template("[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}")
.progress_chars("=>-"),
progress_template: "[{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta}) {msg}".to_string(),
progress_chars: "=>-".to_string(),
}
}

Expand All @@ -629,8 +629,9 @@ impl Download {
}

/// Set the progress style
pub fn set_progress_style(&mut self, progress_style: ProgressStyle) -> &mut Self {
self.progress_style = progress_style;
pub fn set_progress_style(&mut self, progress_template: String, progress_chars: String) -> &mut Self {
self.progress_template = progress_template;
self.progress_chars = progress_chars;
self
}

Expand Down Expand Up @@ -699,7 +700,11 @@ impl Download {
let mut downloaded = 0;
let mut bar = if show_progress {
let pb = ProgressBar::new(size);
pb.set_style(self.progress_style.clone());
pb.set_style(
ProgressStyle::default_bar()
.template(&self.progress_template).unwrap()
.progress_chars(&self.progress_chars)
);

Some(pb)
} else {
Expand Down

0 comments on commit 2747fc3

Please sign in to comment.