summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-09 13:31:23 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-09 14:52:09 +0100
commit4899ec32f152b8b598d67360e68e9054bfa1bdf6 (patch)
tree0d1eb410b16b2fa97cbe3f7cbc57c108d43b2f92
parent92364867ff01c66ccb4bd7de6634ed721af5ab09 (diff)
Make ProgressBars helper able to create spinners
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/config/not_validated.rs4
-rw-r--r--src/config/util.rs4
-rw-r--r--src/main.rs2
-rw-r--r--src/util/progress.rs22
4 files changed, 30 insertions, 2 deletions
diff --git a/src/config/not_validated.rs b/src/config/not_validated.rs
index 84ad993..d8a4d8d 100644
--- a/src/config/not_validated.rs
+++ b/src/config/not_validated.rs
@@ -23,6 +23,10 @@ pub struct NotValidatedConfiguration {
#[getset(get = "pub")]
progress_format: String,
+ #[serde(default = "default_spinner_format")]
+ #[getset(get = "pub")]
+ spinner_format: String,
+
#[serde(default = "default_package_print_format")]
#[getset(get = "pub")]
package_print_format: String,
diff --git a/src/config/util.rs b/src/config/util.rs
index 052899f..bf7e542 100644
--- a/src/config/util.rs
+++ b/src/config/util.rs
@@ -2,6 +2,10 @@ pub fn default_progress_format() -> String {
String::from("[{elapsed_precise}] ({percent:>3}%): {bar:40.cyan/blue} | {msg}")
}
+pub fn default_spinner_format() -> String {
+ String::from("[{elapsed_precise}] {spinner} | {msg}")
+}
+
pub fn default_package_print_format() -> String {
String::from(indoc::indoc!(r#"
{{i}} - {{p.name}} : {{p.version}}
diff --git a/src/main.rs b/src/main.rs
index b57908c..750e3d9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -84,7 +84,7 @@ async fn main() -> Result<()> {
let _ = crate::ui::package_repo_cleanness_check(&repo_path)?;
let max_packages = count_pkg_files(&repo_path);
let hide_bars = cli.is_present("hide_bars") || crate::util::stdout_is_pipe();
- let progressbars = ProgressBars::setup(config.progress_format().clone(), hide_bars);
+ let progressbars = ProgressBars::setup(config.progress_format().clone(), config.spinner_format().clone(), hide_bars);
let load_repo = || -> Result<Repository> {
let bar = progressbars.repo_loading();
diff --git a/src/util/progress.rs b/src/util/progress.rs
index 727c704..5874624 100644
--- a/src/util/progress.rs
+++ b/src/util/progress.rs
@@ -1,3 +1,5 @@
+use std::path::PathBuf;
+
use indicatif::*;
use uuid::Uuid;
use url::Url;
@@ -5,13 +7,15 @@ use url::Url;
#[derive(Clone, Debug)]
pub struct ProgressBars {
bar_template: String,
+ spinner_template: String,
hide: bool,
}
impl ProgressBars {
- pub fn setup(bar_template: String, hide: bool) -> Self {
+ pub fn setup(bar_template: String, spinner_template: String, hide: bool) -> Self {
ProgressBars {
bar_template,
+ spinner_template,
hide,
}
}
@@ -46,6 +50,10 @@ impl ProgressBars {
self.bar(&format!("Download: {}", url.as_str()), &self.bar_template)
}
+ pub fn verification_bar(&self, path: PathBuf) -> ProgressBar {
+ self.spinner(&self.spinner_template, format!("Verification: {}", path.display()))
+ }
+
fn bar(&self, msg: &str, template: &str) -> ProgressBar {
if self.hide {
ProgressBar::hidden()
@@ -57,5 +65,17 @@ impl ProgressBars {
}
}
+ fn spinner(&self, template: &str, msg: String) -> ProgressBar {
+ if self.hide {
+ ProgressBar::hidden()
+ } else {
+ let bar = ProgressBar::new_spinner();
+ bar.set_style(ProgressStyle::default_spinner().template(template));
+ bar.enable_steady_tick(100);
+ bar.set_message(&msg);
+ bar
+ }
+ }
+
}