From cd0dc9a70193759740252b3aa305daff21ae08fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Mon, 26 May 2025 18:25:07 +0200 Subject: [PATCH] options: Add `truecolor` to control the usage (#2867) - `auto`: enable usage of true color if it is supported, otherwise disable it - `on`: force usage of true color - `off`: disable true color usage Co-authored-by: Dmytro Maluka --- README.md | 2 +- internal/config/settings.go | 3 +++ internal/screen/screen.go | 9 ++++++--- runtime/help/colors.md | 16 +++++++--------- runtime/help/options.md | 13 +++++++++++++ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6f0cc390..2d0e79db 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ You can also check out the website for Micro at https://micro-editor.github.io. - Syntax highlighting for over [130 languages](runtime/syntax). - Color scheme support. - By default, micro comes with 16, 256, and true color themes. -- True color support (set the `MICRO_TRUECOLOR` environment variable to 1 to enable it). +- True color support. - Copy and paste with the system clipboard. - Small and simple. - Easily configurable. diff --git a/internal/config/settings.go b/internal/config/settings.go index 14e5f18b..837b56ba 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -36,6 +36,7 @@ var optionValidators = map[string]optionValidator{ "scrollmargin": validateNonNegativeValue, "scrollspeed": validateNonNegativeValue, "tabsize": validatePositiveValue, + "truecolor": validateChoice, } // a list of settings with pre-defined choices @@ -46,6 +47,7 @@ var OptionChoices = map[string][]string{ "matchbracestyle": {"underline", "highlight"}, "multiopen": {"tab", "hsplit", "vsplit"}, "reload": {"prompt", "auto", "disabled"}, + "truecolor": {"auto", "on", "off"}, } // a list of settings that can be globally and locally modified and their @@ -99,6 +101,7 @@ var defaultCommonSettings = map[string]interface{}{ "tabmovement": false, "tabsize": float64(4), "tabstospaces": false, + "truecolor": "auto", "useprimary": true, "wordwrap": false, } diff --git a/internal/screen/screen.go b/internal/screen/screen.go index 6855da71..f8f91361 100644 --- a/internal/screen/screen.go +++ b/internal/screen/screen.go @@ -184,10 +184,13 @@ func Init() error { drawChan = make(chan bool, 8) // Should we enable true color? - truecolor := os.Getenv("MICRO_TRUECOLOR") == "1" - - if !truecolor { + truecolor := config.GetGlobalOption("truecolor").(string) + if truecolor == "on" || (truecolor == "auto" && os.Getenv("MICRO_TRUECOLOR") == "1") { + os.Setenv("TCELL_TRUECOLOR", "enable") + } else if truecolor == "off" { os.Setenv("TCELL_TRUECOLOR", "disable") + } else { + // For "auto", tcell already autodetects truecolor by default } var oldTerm string diff --git a/runtime/help/colors.md b/runtime/help/colors.md index 8675f505..c085919a 100644 --- a/runtime/help/colors.md +++ b/runtime/help/colors.md @@ -47,10 +47,7 @@ color support comes in three flavors. displaying any colorscheme, but it should be noted that the user-configured 16-color palette is ignored when using true-color mode (this means the colors while using the terminal emulator will be slightly off). Not all - terminals support true color but at this point most do. True color - support in micro is off by default but can be enabled by setting the - environment variable `MICRO_TRUECOLOR` to 1. In addition your terminal - must support it (usually indicated by setting `$COLORTERM` to `truecolor`). + terminals support true color but at this point most do (see below). True-color colorschemes in micro typically end with `-tc`, such as `solarized-tc`, `atom-dark`, `material-tc`, etc... If true color is not enabled but a true color colorscheme is used, micro will do its best to @@ -84,11 +81,12 @@ These may vary widely based on the 16 colors selected for your terminal. ### True color -True color requires your terminal to support it. This means that the -environment variable `COLORTERM` should have the value `truecolor`, `24bit`, -or `24-bit`. In addition, to enable true color in micro, the environment -variable `MICRO_TRUECOLOR` must be set to 1. Note that you have to create -and set this variable yourself. +Micro enables true color support by default as long as it detects that the +terminal supports it (which is usually indicated by the environment variable +`COLORTERM` being set to `truecolor`, `24bit` or `24-bit`). You can also force +enabling it unconditionally by setting the option `truecolor` to `on` (or +alternatively by setting the environment variable `MICRO_TRUECOLOR` to 1, which +is supported for backward compatibility). * `solarized-tc`: this is the solarized colorscheme for true color. * `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme. diff --git a/runtime/help/options.md b/runtime/help/options.md index e16d2259..c536aabd 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -462,6 +462,19 @@ Here are the available options: default value: `false` +* `truecolor`: controls whether micro will use true colors (24-bit colors) when + using a colorscheme with true colors, such as `solarized-tc` or `atom-dark`. + * `auto`: enable usage of true color if micro detects that it is supported by + the terminal, otherwise disable it. + * `on`: force usage of true color even if micro does not detect its support + by the terminal (of course this is not guaranteed to work well unless the + terminal actually supports true color). + * `off`: disable true color usage. + + Note: The change will take effect after the next start of `micro`. + + default value: `auto` + * `useprimary` (only useful on unix): defines whether or not micro will use the primary clipboard to copy selections in the background. This does not affect the normal clipboard using `Ctrl-c` and `Ctrl-v`.