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 <dmitrymaluka@gmail.com>
This commit is contained in:
Jöran Karl 2025-05-26 18:25:07 +02:00 committed by GitHub
parent bf255b6c35
commit cd0dc9a701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 13 deletions

View File

@ -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). - Syntax highlighting for over [130 languages](runtime/syntax).
- Color scheme support. - Color scheme support.
- By default, micro comes with 16, 256, and true color themes. - 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. - Copy and paste with the system clipboard.
- Small and simple. - Small and simple.
- Easily configurable. - Easily configurable.

View File

@ -36,6 +36,7 @@ var optionValidators = map[string]optionValidator{
"scrollmargin": validateNonNegativeValue, "scrollmargin": validateNonNegativeValue,
"scrollspeed": validateNonNegativeValue, "scrollspeed": validateNonNegativeValue,
"tabsize": validatePositiveValue, "tabsize": validatePositiveValue,
"truecolor": validateChoice,
} }
// a list of settings with pre-defined choices // a list of settings with pre-defined choices
@ -46,6 +47,7 @@ var OptionChoices = map[string][]string{
"matchbracestyle": {"underline", "highlight"}, "matchbracestyle": {"underline", "highlight"},
"multiopen": {"tab", "hsplit", "vsplit"}, "multiopen": {"tab", "hsplit", "vsplit"},
"reload": {"prompt", "auto", "disabled"}, "reload": {"prompt", "auto", "disabled"},
"truecolor": {"auto", "on", "off"},
} }
// a list of settings that can be globally and locally modified and their // a list of settings that can be globally and locally modified and their
@ -99,6 +101,7 @@ var defaultCommonSettings = map[string]interface{}{
"tabmovement": false, "tabmovement": false,
"tabsize": float64(4), "tabsize": float64(4),
"tabstospaces": false, "tabstospaces": false,
"truecolor": "auto",
"useprimary": true, "useprimary": true,
"wordwrap": false, "wordwrap": false,
} }

View File

@ -184,10 +184,13 @@ func Init() error {
drawChan = make(chan bool, 8) drawChan = make(chan bool, 8)
// Should we enable true color? // Should we enable true color?
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1" truecolor := config.GetGlobalOption("truecolor").(string)
if truecolor == "on" || (truecolor == "auto" && os.Getenv("MICRO_TRUECOLOR") == "1") {
if !truecolor { os.Setenv("TCELL_TRUECOLOR", "enable")
} else if truecolor == "off" {
os.Setenv("TCELL_TRUECOLOR", "disable") os.Setenv("TCELL_TRUECOLOR", "disable")
} else {
// For "auto", tcell already autodetects truecolor by default
} }
var oldTerm string var oldTerm string

View File

@ -47,10 +47,7 @@ color support comes in three flavors.
displaying any colorscheme, but it should be noted that the user-configured 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 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 colors while using the terminal emulator will be slightly off). Not all
terminals support true color but at this point most do. True color terminals support true color but at this point most do (see below).
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`).
True-color colorschemes in micro typically end with `-tc`, such as True-color colorschemes in micro typically end with `-tc`, such as
`solarized-tc`, `atom-dark`, `material-tc`, etc... If true color is not `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 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
True color requires your terminal to support it. This means that the Micro enables true color support by default as long as it detects that the
environment variable `COLORTERM` should have the value `truecolor`, `24bit`, terminal supports it (which is usually indicated by the environment variable
or `24-bit`. In addition, to enable true color in micro, the environment `COLORTERM` being set to `truecolor`, `24bit` or `24-bit`). You can also force
variable `MICRO_TRUECOLOR` must be set to 1. Note that you have to create enabling it unconditionally by setting the option `truecolor` to `on` (or
and set this variable yourself. 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. * `solarized-tc`: this is the solarized colorscheme for true color.
* `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme. * `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme.

View File

@ -462,6 +462,19 @@ Here are the available options:
default value: `false` 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 * `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 primary clipboard to copy selections in the background. This does not affect
the normal clipboard using `Ctrl-c` and `Ctrl-v`. the normal clipboard using `Ctrl-c` and `Ctrl-v`.