]> git.lizzy.rs Git - micro.git/commitdiff
Support for multiple modifiers in colorschemes (#1772)
authorfranekjel <franekjel@users.noreply.github.com>
Tue, 14 Jul 2020 21:58:03 +0000 (23:58 +0200)
committerGitHub <noreply@github.com>
Tue, 14 Jul 2020 21:58:03 +0000 (17:58 -0400)
* Support for multiple modifiers (eg. "bold italic")

* Test for multiple modifiers (bold + italic + underline)

internal/config/colorscheme.go
internal/config/colorscheme_test.go

index c8ba4e3e3fca4a1b1fac4a55be6396871a7db3d6..8109d07a6e06f18528b99abee058af320b6541f5 100644 (file)
@@ -117,16 +117,12 @@ func ParseColorscheme(text string) (map[string]tcell.Style, error) {
 
 // StringToStyle returns a style from a string
 // The strings must be in the format "extra foregroundcolor,backgroundcolor"
-// The 'extra' can be bold, reverse, or underline
+// The 'extra' can be bold, reverse, italic or underline
 func StringToStyle(str string) tcell.Style {
        var fg, bg string
        spaceSplit := strings.Split(str, " ")
        var split []string
-       if len(spaceSplit) > 1 {
-               split = strings.Split(spaceSplit[1], ",")
-       } else {
-               split = strings.Split(str, ",")
-       }
+       split = strings.Split(spaceSplit[len(spaceSplit)-1], ",")
        if len(split) > 1 {
                fg, bg = split[0], split[1]
        } else {
index 83080df15ad8fce874600ce5db4d76e15f737915..106fd1be0215ca558afc983302e8b5ee9e5d7951 100644 (file)
@@ -26,6 +26,18 @@ func TestAttributeStringToStyle(t *testing.T) {
        assert.NotEqual(t, 0, attr&tcell.AttrBold)
 }
 
+func TestMultiAttributesStringToStyle(t *testing.T) {
+       s := StringToStyle("bold italic underline cyan,brightcyan")
+
+       fg, bg, attr := s.Decompose()
+
+       assert.Equal(t, tcell.ColorTeal, fg)
+       assert.Equal(t, tcell.ColorAqua, bg)
+       assert.NotEqual(t, 0, attr&tcell.AttrBold)
+       assert.NotEqual(t, 0, attr&tcell.AttrItalic)
+       assert.NotEqual(t, 0, attr&tcell.AttrUnderline)
+}
+
 func TestColor256StringToStyle(t *testing.T) {
        s := StringToStyle("128,60")