Skip to content

Commit 43d27c1

Browse files
committed
[no-color] - implement NO_COLOR support
1 parent 6c85838 commit 43d27c1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ parts
1919
prime
2020
stage
2121
*.snap
22+
23+
# IntelliJ IDEA files
24+
.idea

src/options/theme.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::theme::{Options, UseColours, ColourScale, Definitions};
55

66
impl Options {
77
pub fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
8-
let use_colours = UseColours::deduce(matches)?;
8+
let use_colours = UseColours::deduce(matches, vars)?;
99
let colour_scale = ColourScale::deduce(matches)?;
1010

1111
let definitions = if use_colours == UseColours::Never {
@@ -21,10 +21,15 @@ impl Options {
2121

2222

2323
impl UseColours {
24-
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
24+
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
25+
let default_value = match vars.get(vars::NO_COLOR) {
26+
Some(_) => Self::Never,
27+
None => Self::Automatic,
28+
};
29+
2530
let word = match matches.get_where(|f| f.matches(&flags::COLOR) || f.matches(&flags::COLOUR))? {
2631
Some(w) => w,
27-
None => return Ok(Self::Automatic),
32+
None => return Ok(default_value),
2833
};
2934

3035
if word == "always" {

src/options/vars.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub static COLUMNS: &str = "COLUMNS";
1515
/// Environment variable used to datetime format.
1616
pub static TIME_STYLE: &str = "TIME_STYLE";
1717

18+
/// Environment variable used to disable colors.
19+
/// See: https://no-color.org/
20+
pub static NO_COLOR: &str = "NO_COLOR";
1821

1922
// exa-specific variables
2023

0 commit comments

Comments
 (0)