summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-09-27 08:48:22 +0200
committerGitHub <noreply@github.com>2018-09-27 08:48:22 +0200
commitccbc2b2672defc61f4e67040fc193b8271bd9f60 (patch)
tree3e29463c7dbd8a054eab02b8c189365feed6f3c7
parent6a81c0afd1d98520d4820f6a1dcb161ee4029761 (diff)
parent6f768fe4add31a7ff1530f5f5e86915a094fc3bf (diff)
downloadimag-ccbc2b2672defc61f4e67040fc193b8271bd9f60.zip
imag-ccbc2b2672defc61f4e67040fc193b8271bd9f60.tar.gz
Merge pull request #1478 from matthiasbeyer/imag-diagnostics/progressbar
imag-diagnostics: Add a progressbar to the command
-rw-r--r--bin/core/imag-diagnostics/Cargo.toml1
-rw-r--r--bin/core/imag-diagnostics/src/main.rs46
-rw-r--r--imagrc.toml10
3 files changed, 56 insertions, 1 deletions
diff --git a/bin/core/imag-diagnostics/Cargo.toml b/bin/core/imag-diagnostics/Cargo.toml
index e0615a2..08c4e7c 100644
--- a/bin/core/imag-diagnostics/Cargo.toml
+++ b/bin/core/imag-diagnostics/Cargo.toml
@@ -19,6 +19,7 @@ build = "../../../build.rs"
log = "0.4"
toml = "0.4"
toml-query = "0.6"
+indicatif = "0.9"
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
diff --git a/bin/core/imag-diagnostics/src/main.rs b/bin/core/imag-diagnostics/src/main.rs
index 8836886..d8d8482 100644
--- a/bin/core/imag-diagnostics/src/main.rs
+++ b/bin/core/imag-diagnostics/src/main.rs
@@ -35,6 +35,7 @@
extern crate clap;
extern crate toml;
extern crate toml_query;
+extern crate indicatif;
#[macro_use] extern crate log;
#[macro_use] extern crate libimagrt;
@@ -44,6 +45,7 @@ extern crate libimagstore;
use std::io::Write;
+use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
use libimagerror::trace::MapErrTrace;
use libimagerror::io::ToExitCode;
@@ -55,6 +57,7 @@ use libimagentrylink::internal::*;
use toml::Value;
use toml_query::read::TomlValueReadExt;
+use indicatif::{ProgressBar, ProgressStyle};
use std::collections::BTreeMap;
@@ -119,6 +122,20 @@ fn main() {
ui::build_ui);
let mut entries_counter = 0;
+ let template = get_config(&rt, "rt.progressbar_style");
+ let tick_chars = get_config(&rt, "rt.progressticker_chars");
+
+ let style = if let Some(tick_chars) = tick_chars {
+ ProgressStyle::default_spinner().tick_chars(&tick_chars)
+ } else {
+ ProgressStyle::default_spinner()
+ };
+
+ let spinner = ProgressBar::new_spinner();
+ spinner.enable_steady_tick(100);
+ spinner.set_style(style);
+ spinner.set_message("Accumulating data");
+
let diags = rt.store()
.entries()
.map_err_trace_exit_unwrap(1)
@@ -149,6 +166,17 @@ fn main() {
.collect::<Result<Vec<_>, _>>()
.map_err_trace_exit_unwrap(1);
+ spinner.finish();
+ let n = diags.len();
+ let progress = ProgressBar::new(n as u64);
+ let style = if let Some(template) = template {
+ ProgressStyle::default_bar().template(&template)
+ } else {
+ ProgressStyle::default_bar()
+ };
+ progress.set_style(style);
+ progress.set_message("Calculating stats");
+
let mut version_counts : BTreeMap<String, usize> = BTreeMap::new();
let mut sum_header_sections = 0;
let mut sum_bytecount_content = 0;
@@ -186,9 +214,11 @@ fn main() {
max_internal_links = Some((diag.num_internal_links, diag.id.clone()));
}
}
+
+ progress.inc(1);
}
- let n = diags.len();
+ progress.finish();
let mut out = rt.stdout();
@@ -232,3 +262,17 @@ fn main() {
}
}
+fn get_config(rt: &Runtime, s: &'static str) -> Option<String> {
+ rt.config().and_then(|cfg| {
+ cfg.read(s)
+ .map_err_trace_exit_unwrap(1)
+ .map(|opt| match opt {
+ &Value::String(ref s) => s.to_owned(),
+ _ => {
+ error!("Config type wrong: 'rt.progressbar_style' should be a string");
+ ::std::process::exit(1)
+ }
+ })
+ })
+}
+
diff --git a/imagrc.toml b/imagrc.toml
index 17f3fd7..1371b93 100644
--- a/imagrc.toml
+++ b/imagrc.toml
@@ -4,6 +4,16 @@
[rt]
editor = "vim"
+# If the command uses a progress bar to indicate progress, this is the template
+# for it.
+#
+# The docs for the template language can be found at
+#
+# https://docs.rs/indicatif
+#
+progressbar_style = "[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}"
+progressticker_chars = "|/-\\-/-\\"
+
#
# imag supports templates when specifying formats. The templates support several
# functionalities, from colorizing to underlining and such things.