Move progress bar to separate module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 8618c86 · Browse files · 4 files·+32 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+32 added−29 removed
- other:+32 added−29 removed
Provenance
- Commit
13986b1- Tree
9b4f71b- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
8618c86
4 files changed+32 added−29 removed
modified:src/benchmark.rs+2 added-1 removed
6 unmodified lines7 8 use crate::benchmark_result::BenchmarkResult;9 use crate::command::Command;10 use crate::format::{format_duration, format_duration_unit};11-use crate::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};11+use crate::internal::{max, min, MIN_EXECUTION_TIME};12+use crate::progress_bar::get_progress_bar;13 use crate::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};14 use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};15 use crate::shell::execute_and_time;16 use crate::timer::wallclocktimer::WallClockTimer;469 unmodified linesmodified:src/internal.rs-28 removed
1 use std::cmp::Ordering;2 use std::iter::Iterator;3 4 use colored::*;5-use indicatif::{ProgressBar, ProgressStyle};5 6 use crate::benchmark_result::BenchmarkResult;8-use crate::options::OutputStyleOption;7 use crate::units::{Scalar, Second};8 9 /// Threshold for warning about fast execution time10 pub const MIN_EXECUTION_TIME: Second = 5e-3;11 14-#[cfg(not(windows))]15-const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);16-17-#[cfg(windows)]18-const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);19-20-/// Return a pre-configured progress bar21-pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {22- let progressbar_style = match option {23- OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),24- _ => ProgressStyle::default_spinner()25- .tick_chars(TICK_SETTINGS.0)26- .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),27- };28-29- let progress_bar = match option {30- OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(),31- _ => ProgressBar::new(length),32- };33- progress_bar.set_style(progressbar_style);34- progress_bar.enable_steady_tick(TICK_SETTINGS.1);35- progress_bar.set_message(msg.to_owned());36-37- progress_bar38-}39-12 /// A max function for f64's without NaNs13 pub fn max(vals: &[f64]) -> f64 {14 *vals15 .iter()212 unmodified linesmodified:src/main.rs+1 added
16 unmodified lines17 pub mod internal;18 pub mod options;19 pub mod outlier_detection;20 pub mod parameter_range;21+pub mod progress_bar;22 pub mod shell;23 pub mod timer;24 pub mod types;25 pub mod units;398 unmodified linesadded:src/progress_bar.rs+29 added
1+use indicatif::{ProgressBar, ProgressStyle};2+3+use crate::options::OutputStyleOption;4+5+#[cfg(not(windows))]6+const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);7+8+#[cfg(windows)]9+const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);10+11+/// Return a pre-configured progress bar12+pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {13+ let progressbar_style = match option {14+ OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),15+ _ => ProgressStyle::default_spinner()16+ .tick_chars(TICK_SETTINGS.0)17+ .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),18+ };19+20+ let progress_bar = match option {21+ OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(),22+ _ => ProgressBar::new(length),23+ };24+ progress_bar.set_style(progressbar_style);25+ progress_bar.enable_steady_tick(TICK_SETTINGS.1);26+ progress_bar.set_message(msg.to_owned());27+28+ progress_bar29+}