mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 17:00:18 +00:00
Move progress bar to separate module
This commit is contained in:
1 parent
8618c86421
commit
13986b17f4
4 files changed
+32
-29
No files matched your search
+2
-1
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user