Skip to content

Commit

Permalink
Rename to Colors::forced_value
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Jan 24, 2024
1 parent e2a02af commit f3ef44c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,17 @@ pub enum Colors {
}

impl Colors {
fn forced_value(&self) -> Option<bool> {
/// If colors were forced on or off by the user through an option or
/// environment variable, return that value.
///
/// Otherwise, return None, meaning we should decide based on the
/// detected terminal characteristics.
pub fn forced_value(&self) -> Option<bool> {
// From https://bixense.com/clicolors/
if env::var("NO_COLOR").map_or(false, |x| x != "0") {
Some(false)
} else if env::var("CLICOLOR_FORCE").map_or(false, |x| x != "0") {
Some(true)
} else {
None
}
}

pub fn active(&self) -> Option<bool> {
if let Some(active) = self.forced_value() {
Some(active)
} else {
match self {
Colors::Always => Some(true),
Expand All @@ -161,7 +158,8 @@ impl Colors {
}

pub fn active_stdout(&self) -> bool {
self.active().unwrap_or_else(::console::colors_enabled)
self.forced_value()
.unwrap_or_else(::console::colors_enabled)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ src/options.rs: replace Colors::forced_value -> Option<bool> with Some(true)
src/options.rs: replace Colors::forced_value -> Option<bool> with Some(false)
src/options.rs: replace != with == in Colors::forced_value
src/options.rs: replace != with == in Colors::forced_value
src/options.rs: replace Colors::active -> Option<bool> with None
src/options.rs: replace Colors::active -> Option<bool> with Some(true)
src/options.rs: replace Colors::active -> Option<bool> with Some(false)
src/options.rs: replace Colors::active_stdout -> bool with true
src/options.rs: replace Colors::active_stdout -> bool with false
src/options.rs: replace or_slices -> &'c[T] with Vec::leak(Vec::new())
Expand Down

0 comments on commit f3ef44c

Please sign in to comment.