Skip to content

Commit

Permalink
options: Add truecolor to control the mode
Browse files Browse the repository at this point in the history
- `off`: default, can be overriden by `$MICRO_TRUECOLOR`
- `on`: forced usage, same as `$MICRO_TRUECOLOR` set to 1
- `auto`: determines the capability based on `$COLORTERM`
  • Loading branch information
JoeKar committed Jul 16, 2023
1 parent ceaa143 commit 2c14b34
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ 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
- set the option `truecolor` to `auto` or `on` ..
- set the `MICRO_TRUECOLOR` environment variable to 1 to enable it
- both ways do only work in case the terminal supports true color mode
- Copy and paste with the system clipboard.
- Small and simple.
- Easily configurable.
Expand Down
18 changes: 18 additions & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var optionValidators = map[string]optionValidator{
"fileformat": validateLineEnding,
"encoding": validateEncoding,
"multiopen": validateMultiOpen,
"truecolor": validateTrueColor,
}

func ReadSettings() error {
Expand Down Expand Up @@ -360,6 +361,7 @@ var DefaultGlobalOnlySettings = map[string]interface{}{
"sucmd": "sudo",
"tabhighlight": false,
"tabreverse": true,
"truecolor": "off",
"xterm": false,
}

Expand Down Expand Up @@ -526,3 +528,19 @@ func validateMultiOpen(option string, value interface{}) error {

return nil
}

func validateTrueColor(option string, value interface{}) error {
val, ok := value.(string)

if !ok {
return errors.New("Expected string type for truecolor")
}

switch val {
case "off", "on", "auto":
default:
return errors.New(option + " must be 'off', 'on', or 'auto'")
}

return nil
}
10 changes: 9 additions & 1 deletion internal/screen/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,16 @@ func TempStart(screenWasNil bool) {
func Init() error {
drawChan = make(chan bool, 8)

// Is true color support available?
truecolorAvailable := (os.Getenv("COLORTERM") == "truecolor") ||
(os.Getenv("COLORTERM") == "24bit") ||
(os.Getenv("COLORTERM") == "24-bit")

// Should we enable true color?
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
truecolor := (truecolorAvailable &&
(config.GetGlobalOption("truecolor").(string) == "auto")) ||
(config.GetGlobalOption("truecolor").(string) == "on") ||
(os.Getenv("MICRO_TRUECOLOR") == "1")

if !truecolor {
os.Setenv("TCELL_TRUECOLOR", "disable")
Expand Down
15 changes: 10 additions & 5 deletions runtime/help/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ color support comes in three flavors.
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`).
the option `truecolor` to `on` or the environment variable `MICRO_TRUECOLOR`
to 1 to force the usage of true color mode.
In addition your terminal must support it (usually indicated by setting
`COLORTERM` to `truecolor`).
Furthermore it can be enabled by setting the option `truecolor` to `auto` then
the availability will be determined by `$COLORTERM`.
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
Expand Down Expand Up @@ -86,9 +90,10 @@ These may vary widely based on the 16 colors selected for your terminal.

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.
or `24-bit`. In case the currently used terminal doesn't "support" true color
within the mentioned `COLORTERM` then the usage can be forced by setting the
option `truecolor` to `on` or the environment variable `MICRO_TRUECOLOR` to 1.
Note that you have to create and set this environment variable yourself.

* `solarized-tc`: this is the solarized colorscheme for true color.
* `atom-dark`: this colorscheme is based off of Atom's "dark" colorscheme.
Expand Down
12 changes: 12 additions & 0 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ Here are the available options:

default value: `false`

* `truecolor`: controls the usage of the true color support/mode.
* `off`: true color support disabled, but can be overriden with the
`$MICRO_TRUECOLOR` environment variable set to `1`.
* `on`: Will force the usage of true color, but will need terminal support
to work properly.
* `auto`: Tries to detected the true color capability with the help of the
`$COLORTERM` environment variable.

Note: The change will take effect after the next start of `micro`.

default value: `off`

* `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.
Expand Down

0 comments on commit 2c14b34

Please sign in to comment.