Skip to content
Myr

Add 'nocolor' option for output.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This maintains most output styles, but removes coloring from output. On Windows, this is the default setting if Full would have been used

authored by Steve Pentland · committed by David Peter · parent faff3e6 · Browse files · 2 files+17 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−5 removed

  • other:+17 added−5 removed

2 files+17 added−5 removed

modified:src/hyperfine/internal.rs+5 added-2 removed
22 unmodified lines
23 Basic,2425 /// Output with full color and formatting26 Full,2728 /// Keep elements such as progress bar, but use no coloring29 NoColor,30}3132/// A set of options for hyperfine33pub struct HyperfineOptions {
32 unmodified lines
66/// Return a pre-configured progress bar67pub fn get_progress_bar(length: u64, msg: &str, option: &OutputStyleOption) -> ProgressBar {68 let progressbar_style = match *option {69 OutputStyleOption::Basic => ProgressStyle::default_bar(),67 OutputStyleOption::Full => ProgressStyle::default_spinner()70 OutputStyleOption::Full | OutputStyleOption::NoColor => ProgressStyle::default_spinner()71 .tick_chars("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")72 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),73 };7475 let progress_bar = match *option {76 OutputStyleOption::Basic => ProgressBar::hidden(),74 OutputStyleOption::Full => ProgressBar::new(length),77 OutputStyleOption::Full | OutputStyleOption::NoColor => ProgressBar::new(length),78 };79 progress_bar.set_style(progressbar_style.clone());80 progress_bar.enable_steady_tick(80);81 progress_bar.set_message(msg);
26 unmodified lines
modified:src/main.rs+12 added-3 removed
113 unmodified lines
114 .long("style")115 .short("s")116 .takes_value(true)117 .value_name("TYPE")118 .possible_values(&["auto", "basic", "full"])118 .possible_values(&["auto", "basic", "full", "nocolor"])119 .help(120 "Set output style type (default: auto). Set this to 'basic' to disable output \121 coloring and interactive elements. Set it to 'full' to enable all effects \122 even if no interactive terminal was detected.",122 even if no interactive terminal was detected. Setting to 'nocolor' maintains \123 all advanced output, but uses no colorization.",124 ),125 )126 .arg(127 Arg::with_name("ignore-failure")
21 unmodified lines
149150 options.output_style = match matches.value_of("style") {151 Some("full") => OutputStyleOption::Full,152 Some("basic") => OutputStyleOption::Basic,153 Some("nocolor") => OutputStyleOption::NoColor,154 _ => if atty::is(Stream::Stdout) {155 OutputStyleOption::Full156 } else {157 OutputStyleOption::Basic158 },159 };160161 // We default Windows to NoColor if full or auto had been specified.162 if cfg!(windows) && options.output_style == OutputStyleOption::Full {163 options.output_style = OutputStyleOption::NoColor;164 }165159 if options.output_style == OutputStyleOption::Basic {166 if options.output_style == OutputStyleOption::Basic167 || options.output_style == OutputStyleOption::NoColor168 {169 colored::control::set_override(false);170 }171172 if matches.is_present("ignore-failure") {
10 unmodified lines