From 2747fc3e3866b1968adaa312835c10571415416c Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Mon, 5 Sep 2022 09:30:37 -0400 Subject: [PATCH] Instead of ProgressStyle, use separate progress_template and progress_chars strings so we can still derive Debug, as ProgressStyle in indicatif 0.17 does not implement debug anymore with its progresstracker --- src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 35742ba..0fef5ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 @@ -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(), } } @@ -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 } @@ -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 {