From 7c3b0c34756fb009fc602e9d4341c7707db69302 Mon Sep 17 00:00:00 2001 From: Kevin Vigor Date: Fri, 19 Apr 2024 17:43:15 -0600 Subject: [PATCH] Add a "yes-color" configuration option to allow overriding NO_COLOR environment variable, which crossterm honors by default. As noted in https://no-color.org/, "User-level configuration files and per-instance command-line arguments should override $NO_COLOR". --- book/src/configuration.md | 1 + helix-tui/src/backend/crossterm.rs | 3 +++ helix-view/src/editor.rs | 3 +++ 3 files changed, 7 insertions(+) diff --git a/book/src/configuration.md b/book/src/configuration.md index 5e22cebf8f662..f47c241c2442a 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -58,6 +58,7 @@ Its settings will be merged with the configuration directory `config.toml` and t | `completion-replace` | Set to `true` to make completions always replace the entire word and not just the part before the cursor | `false` | | `auto-info` | Whether to display info boxes | `true` | | `true-color` | Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative | `false` | +| `yes-color` | Force override of NO_COLOR environment variable (see https://no-color.org/) | `false` | | `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | | `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | diff --git a/helix-tui/src/backend/crossterm.rs b/helix-tui/src/backend/crossterm.rs index 37721e8965336..7475a2717372c 100644 --- a/helix-tui/src/backend/crossterm.rs +++ b/helix-tui/src/backend/crossterm.rs @@ -91,6 +91,9 @@ where W: Write, { pub fn new(buffer: W, config: &EditorConfig) -> CrosstermBackend { + if config.yes_color { + crossterm::style::force_color_output(true); + } CrosstermBackend { buffer, capabilities: Capabilities::from_env_or_default(config), diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index d7058d3ef0221..6f37c595d35bf 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -301,6 +301,8 @@ pub struct Config { pub true_color: bool, /// Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative. Defaults to `false`. pub undercurl: bool, + /// Force override of NO_COLOR environment variable (see https://no-color.org/) + pub yes_color: bool, /// Search configuration. #[serde(default)] pub search: SearchConfig, @@ -892,6 +894,7 @@ impl Default for Config { cursor_shape: CursorShapeConfig::default(), true_color: false, undercurl: false, + yes_color: false, search: SearchConfig::default(), lsp: LspConfig::default(), terminal: get_terminal_provider(),