diff --git a/src/benchmark.rs b/src/benchmark.rs index e453a96..1317225 100644 --- a/src/benchmark.rs +++ b/src/benchmark.rs @@ -8,7 +8,8 @@ use statistical::{mean, median, standard_deviation}; use crate::benchmark_result::BenchmarkResult; use crate::command::Command; use crate::format::{format_duration, format_duration_unit}; -use crate::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME}; +use crate::internal::{max, min, MIN_EXECUTION_TIME}; +use crate::progress_bar::get_progress_bar; use crate::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption}; use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD}; use crate::shell::execute_and_time; diff --git a/src/internal.rs b/src/internal.rs index 9e9c2e1..66d903b 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -2,41 +2,13 @@ use std::cmp::Ordering; use std::iter::Iterator; use colored::*; -use indicatif::{ProgressBar, ProgressStyle}; use crate::benchmark_result::BenchmarkResult; -use crate::options::OutputStyleOption; use crate::units::{Scalar, Second}; /// Threshold for warning about fast execution time pub const MIN_EXECUTION_TIME: Second = 5e-3; -#[cfg(not(windows))] -const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80); - -#[cfg(windows)] -const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200); - -/// Return a pre-configured progress bar -pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar { - let progressbar_style = match option { - OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(), - _ => ProgressStyle::default_spinner() - .tick_chars(TICK_SETTINGS.0) - .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"), - }; - - let progress_bar = match option { - OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(), - _ => ProgressBar::new(length), - }; - progress_bar.set_style(progressbar_style); - progress_bar.enable_steady_tick(TICK_SETTINGS.1); - progress_bar.set_message(msg.to_owned()); - - progress_bar -} - /// A max function for f64's without NaNs pub fn max(vals: &[f64]) -> f64 { *vals diff --git a/src/main.rs b/src/main.rs index 0581c08..b46dc18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ pub mod internal; pub mod options; pub mod outlier_detection; pub mod parameter_range; +pub mod progress_bar; pub mod shell; pub mod timer; pub mod types; diff --git a/src/progress_bar.rs b/src/progress_bar.rs new file mode 100644 index 0000000..a736010 --- /dev/null +++ b/src/progress_bar.rs @@ -0,0 +1,29 @@ +use indicatif::{ProgressBar, ProgressStyle}; + +use crate::options::OutputStyleOption; + +#[cfg(not(windows))] +const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80); + +#[cfg(windows)] +const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200); + +/// Return a pre-configured progress bar +pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar { + let progressbar_style = match option { + OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(), + _ => ProgressStyle::default_spinner() + .tick_chars(TICK_SETTINGS.0) + .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"), + }; + + let progress_bar = match option { + OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(), + _ => ProgressBar::new(length), + }; + progress_bar.set_style(progressbar_style); + progress_bar.enable_steady_tick(TICK_SETTINGS.1); + progress_bar.set_message(msg.to_owned()); + + progress_bar +}