Add a progressbar to the command
Note: characters in config have to be escaped.
This commit is contained in:
parent
5b82d53fd2
commit
6f768fe4ad
3 changed files with 56 additions and 1 deletions
|
@ -19,6 +19,7 @@ build = "../../../build.rs"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
toml-query = "0.6"
|
toml-query = "0.6"
|
||||||
|
indicatif = "0.9"
|
||||||
|
|
||||||
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.9.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.9.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
|
extern crate indicatif;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
|
@ -44,6 +45,7 @@ extern crate libimagstore;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagrt::setup::generate_runtime_setup;
|
use libimagrt::setup::generate_runtime_setup;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::io::ToExitCode;
|
use libimagerror::io::ToExitCode;
|
||||||
|
@ -55,6 +57,7 @@ use libimagentrylink::internal::*;
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
@ -119,6 +122,20 @@ fn main() {
|
||||||
ui::build_ui);
|
ui::build_ui);
|
||||||
|
|
||||||
let mut entries_counter = 0;
|
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()
|
let diags = rt.store()
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -149,6 +166,17 @@ fn main() {
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.map_err_trace_exit_unwrap(1);
|
.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 version_counts : BTreeMap<String, usize> = BTreeMap::new();
|
||||||
let mut sum_header_sections = 0;
|
let mut sum_header_sections = 0;
|
||||||
let mut sum_bytecount_content = 0;
|
let mut sum_bytecount_content = 0;
|
||||||
|
@ -186,9 +214,11 @@ fn main() {
|
||||||
max_internal_links = Some((diag.num_internal_links, diag.id.clone()));
|
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();
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
10
imagrc.toml
10
imagrc.toml
|
@ -4,6 +4,16 @@
|
||||||
[rt]
|
[rt]
|
||||||
editor = "vim"
|
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
|
# imag supports templates when specifying formats. The templates support several
|
||||||
# functionalities, from colorizing to underlining and such things.
|
# functionalities, from colorizing to underlining and such things.
|
||||||
|
|
Loading…
Reference in a new issue