[no-color] - implement NO_COLOR support

This commit is contained in:
Max Zhuravsky 2021-11-25 23:37:02 +03:00
parent b32f441851
commit aab1d3db59
No known key found for this signature in database
GPG Key ID: 997EBA75BF8F9987
3 changed files with 14 additions and 3 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@ parts
prime
stage
*.snap
# IntelliJ IDEA files
.idea

View File

@ -5,7 +5,7 @@ use crate::theme::{Options, UseColours, ColourScale, Definitions};
impl Options {
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
let use_colours = UseColours::deduce(matches)?;
let use_colours = UseColours::deduce(matches, vars)?;
let colour_scale = ColourScale::deduce(matches)?;
let definitions = if use_colours == UseColours::Never {
@ -21,10 +21,15 @@ impl Options {
impl UseColours {
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
let default_value = match vars.get(vars::NO_COLOR) {
Some(_) => Self::Never,
None => Self::Automatic,
};
let word = match matches.get_where(|f| f.matches(&flags::COLOR) || f.matches(&flags::COLOUR))? {
Some(w) => w,
None => return Ok(Self::Automatic),
None => return Ok(default_value),
};
if word == "always" {

View File

@ -15,6 +15,9 @@ pub static COLUMNS: &str = "COLUMNS";
/// Environment variable used to datetime format.
pub static TIME_STYLE: &str = "TIME_STYLE";
/// Environment variable used to disable colors.
/// See: https://no-color.org/
pub static NO_COLOR: &str = "NO_COLOR";
// exa-specific variables