Skip to content

Commit a6f335d

Browse files
committed
Respect the NO_COLOR environment variable
See <https://no-color.org/> Support for CLICOLOR and CLICOLOR_FORCE is a bigger change, and will have to wait till v2.10. See <https://bixense.com/clicolors/> for more details.
1 parent e1e0c24 commit a6f335d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515

1616
[slog#267]: https://github.com/slog-rs/slog/issues/267
1717

18+
### Changed
19+
* Respect the [`NO_COLOR`] environment variable.
20+
21+
[`NO_COLOR`]: https://no-color.org/
22+
1823
## 2.9.1 - 2024-02-18
1924
### Fixed
2025
* Switch from `atty` to `is_terminal`

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,10 @@ enum AnyTerminal {
14041404

14051405
impl AnyTerminal {
14061406
fn should_use_color(&self) -> bool {
1407+
// Respect NO_COLOR <https://no-color.org/>
1408+
if std::env::var_os("NO_COLOR").map_or(false, |x| !x.is_empty()) {
1409+
return false;
1410+
}
14071411
match *self {
14081412
AnyTerminal::Stdout { .. } => std::io::stdout().is_terminal(),
14091413
AnyTerminal::Stderr { .. } => std::io::stderr().is_terminal(),

0 commit comments

Comments
 (0)