Bladeren bron

[no-color] - implement NO_COLOR support

Max Zhuravsky 4 jaren geleden
bovenliggende
commit
aab1d3db59
3 gewijzigde bestanden met toevoegingen van 14 en 3 verwijderingen
  1. 3 0
      .gitignore
  2. 8 3
      src/options/theme.rs
  3. 3 0
      src/options/vars.rs

+ 3 - 0
.gitignore

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

+ 8 - 3
src/options/theme.rs

@@ -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" {

+ 3 - 0
src/options/vars.rs

@@ -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