Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NO_COLOR env variable (https://no-color.org) #737

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/hurl/src/cli/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -440,14 +441,20 @@ pub fn parse_options(matches: &ArgMatches) -> Result<CliOptions, CliError> {
})
}

/// Returns true if Hurl output uses ANSI code and false otherwise.
pub fn output_color(matches: &ArgMatches) -> bool {
if has_flag(matches, "color") {
true
} else if has_flag(matches, "no_color") {
false
} else {
atty::is(Stream::Stdout)
return true;
}
if has_flag(matches, "no_color") {
return false;
}
if let Ok(v) = env::var("NO_COLOR") {
if !v.is_empty() {
return false;
}
}
atty::is(Stream::Stdout)
}

fn to_entry(matches: &ArgMatches) -> Result<Option<usize>, CliError> {
Expand Down