]> git.lizzy.rs Git - micro.git/commitdiff
Fix some issues with default colors in colorschemes (#2225)
authorDmitry Maluka <dmitrymaluka@gmail.com>
Tue, 28 Sep 2021 20:30:29 +0000 (22:30 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Sep 2021 20:30:29 +0000 (13:30 -0700)
* Fix default colors for unconfigured syntax groups

When GetColor is called for a syntax group not specified in the
colorscheme, it should fallback not to the terminal's default colors
(tcell.DefaultColor) but to the colorscheme's defaults (DefStyle)
which may be different from tcell.DefaultColor.

For example, if we are using micro's default colorscheme in a terminal
which uses a black-on-white theme, then dots and commas in Go files
("symbol" syntax group in go.yaml) are displayed black on a dark
background, i.e. barely visible.

* Avoid using terminal's default colors directly

If a syntax group color is set to "default" (which we have for some
syntax groups in some colorschemes), it defaults to the terminal's
default colors (tcell.DefaultColor), which is fine for 16-color
colorschemes but not quite fine for truecolor and 256-color
colorschemes which should not depend on the terminal colors.
It should default to the colorscheme's default (DefStyle) instead.

For example, if we are using micro's default colorscheme in a terminal
which uses a black-on-white theme, then "bool" type in C files
("type.extended" syntax group in c.yaml) is displayed black on a dark
background, i.e. barely visible.

internal/config/colorscheme.go

index 5222cd54d4ac85a7325171296cf7837397eff3d5..4a2ef2f43127daa37ba4c71d833c5073e945c6a1 100644 (file)
@@ -35,8 +35,6 @@ func GetColor(color string) tcell.Style {
                }
        } else if style, ok := Colorscheme[color]; ok {
                st = style
-       } else {
-               st = StringToStyle(color)
        }
 
        return st
@@ -131,12 +129,12 @@ func StringToStyle(str string) tcell.Style {
        bg = strings.TrimSpace(bg)
 
        var fgColor, bgColor tcell.Color
-       if fg == "" {
+       if fg == "" || fg == "default" {
                fgColor, _, _ = DefStyle.Decompose()
        } else {
                fgColor = StringToColor(fg)
        }
-       if bg == "" {
+       if bg == "" || bg == "default" {
                _, bgColor, _ = DefStyle.Decompose()
        } else {
                bgColor = StringToColor(bg)