Skip to content

Commit cd0dc9a

Browse files
JoeKardmaluka
andauthored
options: Add truecolor to control the usage (zyedidia#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 <[email protected]>
1 parent bf255b6 commit cd0dc9a

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can also check out the website for Micro at https://micro-editor.github.io.
4747
- Syntax highlighting for over [130 languages](runtime/syntax).
4848
- Color scheme support.
4949
- By default, micro comes with 16, 256, and true color themes.
50-
- True color support (set the `MICRO_TRUECOLOR` environment variable to 1 to enable it).
50+
- True color support.
5151
- Copy and paste with the system clipboard.
5252
- Small and simple.
5353
- Easily configurable.

internal/config/settings.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var optionValidators = map[string]optionValidator{
3636
"scrollmargin": validateNonNegativeValue,
3737
"scrollspeed": validateNonNegativeValue,
3838
"tabsize": validatePositiveValue,
39+
"truecolor": validateChoice,
3940
}
4041

4142
// a list of settings with pre-defined choices
@@ -46,6 +47,7 @@ var OptionChoices = map[string][]string{
4647
"matchbracestyle": {"underline", "highlight"},
4748
"multiopen": {"tab", "hsplit", "vsplit"},
4849
"reload": {"prompt", "auto", "disabled"},
50+
"truecolor": {"auto", "on", "off"},
4951
}
5052

5153
// a list of settings that can be globally and locally modified and their
@@ -99,6 +101,7 @@ var defaultCommonSettings = map[string]interface{}{
99101
"tabmovement": false,
100102
"tabsize": float64(4),
101103
"tabstospaces": false,
104+
"truecolor": "auto",
102105
"useprimary": true,
103106
"wordwrap": false,
104107
}

internal/screen/screen.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ func Init() error {
184184
drawChan = make(chan bool, 8)
185185

186186
// Should we enable true color?
187-
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
188-
189-
if !truecolor {
187+
truecolor := config.GetGlobalOption("truecolor").(string)
188+
if truecolor == "on" || (truecolor == "auto" && os.Getenv("MICRO_TRUECOLOR") == "1") {
189+
os.Setenv("TCELL_TRUECOLOR", "enable")
190+
} else if truecolor == "off" {
190191
os.Setenv("TCELL_TRUECOLOR", "disable")
192+
} else {
193+
// For "auto", tcell already autodetects truecolor by default
191194
}
192195

193196
var oldTerm string

runtime/help/colors.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ color support comes in three flavors.
4747
displaying any colorscheme, but it should be noted that the user-configured
4848
16-color palette is ignored when using true-color mode (this means the
4949
colors while using the terminal emulator will be slightly off). Not all
50-
terminals support true color but at this point most do. True color
51-
support in micro is off by default but can be enabled by setting the
52-
environment variable `MICRO_TRUECOLOR` to 1. In addition your terminal
53-
must support it (usually indicated by setting `$COLORTERM` to `truecolor`).
50+
terminals support true color but at this point most do (see below).
5451
True-color colorschemes in micro typically end with `-tc`, such as
5552
`solarized-tc`, `atom-dark`, `material-tc`, etc... If true color is not
5653
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.
8481

8582
### True color
8683

87-
True color requires your terminal to support it. This means that the
88-
environment variable `COLORTERM` should have the value `truecolor`, `24bit`,
89-
or `24-bit`. In addition, to enable true color in micro, the environment
90-
variable `MICRO_TRUECOLOR` must be set to 1. Note that you have to create
91-
and set this variable yourself.
84+
Micro enables true color support by default as long as it detects that the
85+
terminal supports it (which is usually indicated by the environment variable
86+
`COLORTERM` being set to `truecolor`, `24bit` or `24-bit`). You can also force
87+
enabling it unconditionally by setting the option `truecolor` to `on` (or
88+
alternatively by setting the environment variable `MICRO_TRUECOLOR` to 1, which
89+
is supported for backward compatibility).
9290

9391
* `solarized-tc`: this is the solarized colorscheme for true color.
9492
* `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme.

runtime/help/options.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,19 @@ Here are the available options:
462462

463463
default value: `false`
464464

465+
* `truecolor`: controls whether micro will use true colors (24-bit colors) when
466+
using a colorscheme with true colors, such as `solarized-tc` or `atom-dark`.
467+
* `auto`: enable usage of true color if micro detects that it is supported by
468+
the terminal, otherwise disable it.
469+
* `on`: force usage of true color even if micro does not detect its support
470+
by the terminal (of course this is not guaranteed to work well unless the
471+
terminal actually supports true color).
472+
* `off`: disable true color usage.
473+
474+
Note: The change will take effect after the next start of `micro`.
475+
476+
default value: `auto`
477+
465478
* `useprimary` (only useful on unix): defines whether or not micro will use the
466479
primary clipboard to copy selections in the background. This does not affect
467480
the normal clipboard using `Ctrl-c` and `Ctrl-v`.

0 commit comments

Comments
 (0)