feat(ui): respect NO_COLOR environment variable (#804)

* feat(ui) Respect NO_COLOR environment variable

* Add NO_COLOR to man and readme

* chore: generate completions & manpage

* Really update manpage this time

* Add `enpty` color scheme to readme

* Rename "empty" color theme to "none"

This seems a better wording for what this theme is. However, empty is
still supported for backwards compatibility (though not mentioned in
readme and manpage, but it wasn't mentioned before anyway)
Since `ColorTheme::empty` is private, I felt it's okay to rename too to
follow suite.

* Add details to related readme paragraph

---------

Co-authored-by: Skim bot <skim-bot@skim-rs.github.io>
Co-authored-by: LoricAndre <57358788+LoricAndre@users.noreply.github.com>
This commit is contained in:
Mark Zaidelman 2025-06-22 02:04:52 +03:00 committed by GitHub
parent e73e7f841b
commit 0f4b13e8c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 9 deletions

View file

@ -319,6 +319,8 @@ limited to the default appearance - Skim supports comprehensive customization of
--color=[BASE_SCHEME][,COLOR:ANSI]
```
Skim also respects the `NO_COLOR` environment variable. Set it to anything and `sk` (and many other terminal apps) will disable all colored output. See [no-color.org](https://no-color.org/) for more details.
### Available Base Color Schemes
Skim comes with several built-in color schemes that you can use as a starting point:
@ -328,6 +330,7 @@ sk --color=dark # Default dark theme (256 colors)
sk --color=light # Light theme (256 colors)
sk --color=16 # Simple 16-color theme
sk --color=bw # Minimal black & white theme (no colors, just styles)
sk --color=none # Minimal black & white theme (no colors, no styles)
sk --color=molokai # Molokai-inspired theme (256 colors)
```

View file

@ -12,6 +12,10 @@ sk is a general purpose command\-line fuzzy finder.
.PP
ENVIRONMENT VARIABLES
.PP
NO_COLOR
.PP
If set and not empty, sk will not use any colors in the output.
.PP
SKIM_DEFAULT_COMMAND
.PP
Default command to use when input is tty. On *nix systems, sk runs the command with sh \-c, so make sure that it\*(Aqs POSIX\-compliant.
@ -426,6 +430,7 @@ Base Color Schemes
\- light: 256\-color light theme
\- 16: Basic 16\-color theme
\- bw: Minimal black & white theme (no colors, just styles)
\- none: Minimal black & white theme (no colors, no styles). Default when NO_COLOR is set
\- molokai: Molokai\-inspired 256\-color theme
Color Customization

View file

@ -19,6 +19,10 @@ use crate::{CaseMatching, FuzzyAlgorithm, Selector};
///
/// # ENVIRONMENT VARIABLES
///
/// ## NO_COLOR
///
/// If set and not empty, sk will not use any colors in the output.
///
/// ## SKIM_DEFAULT_COMMAND
///
/// Default command to use when input is tty. On *nix systems, sk runs the command with sh -c, so make sure that
@ -468,6 +472,7 @@ pub struct SkimOptions {
/// - **light**: 256-color light theme
/// - **16**: Basic 16-color theme
/// - **bw**: Minimal black & white theme (no colors, just styles)
/// - **none**: Minimal black & white theme (no colors, no styles). Default when NO_COLOR is set
/// - **molokai**: Molokai-inspired 256-color theme
///
/// ### Color Customization

View file

@ -1,5 +1,5 @@
//! Handle the color theme
use std::sync::LazyLock;
use std::{env, sync::LazyLock};
use crate::options::SkimOptions;
use skim_tuikit::prelude::*;
@ -52,11 +52,14 @@ impl ColorTheme {
if let Some(color) = options.color.clone() {
ColorTheme::from_options(&color)
} else {
ColorTheme::dark256()
match env::var_os("NO_COLOR") {
Some(no_color) if !no_color.is_empty() => ColorTheme::none(),
_ => ColorTheme::dark256(),
}
}
}
fn empty() -> Self {
fn none() -> Self {
ColorTheme {
fg: Color::Default,
bg: Color::Default,
@ -88,7 +91,7 @@ impl ColorTheme {
matched_effect: Effect::UNDERLINE,
current_effect: Effect::REVERSE,
current_match_effect: Effect::UNDERLINE | Effect::REVERSE,
..ColorTheme::empty()
..ColorTheme::none()
}
}
@ -107,7 +110,7 @@ impl ColorTheme {
selected: Color::MAGENTA,
header: Color::CYAN,
border: Color::LIGHT_BLACK,
..ColorTheme::empty()
..ColorTheme::none()
}
}
@ -126,7 +129,7 @@ impl ColorTheme {
selected: Color::AnsiValue(168),
header: Color::AnsiValue(109),
border: Color::AnsiValue(59),
..ColorTheme::empty()
..ColorTheme::none()
}
}
@ -145,7 +148,7 @@ impl ColorTheme {
selected: Color::AnsiValue(168),
header: Color::AnsiValue(109),
border: Color::AnsiValue(59),
..ColorTheme::empty()
..ColorTheme::none()
}
}
@ -164,7 +167,7 @@ impl ColorTheme {
selected: Color::AnsiValue(168),
header: Color::AnsiValue(31),
border: Color::AnsiValue(145),
..ColorTheme::empty()
..ColorTheme::none()
}
}
@ -179,7 +182,7 @@ impl ColorTheme {
"light" => ColorTheme::light256(),
"16" => ColorTheme::default16(),
"bw" => ColorTheme::bw(),
"empty" => ColorTheme::empty(),
"none" | "empty" => ColorTheme::none(),
"dark" | "default" | _ => ColorTheme::dark256(),
};
continue;