Skip to content

Commit 6487487

Browse files
Merge pull request #2483 from stefanhaller/fix-setting-selectedLineBgColor
2 parents ff5d015 + 63e8b8c commit 6487487

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

pkg/theme/style.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func GetTextStyle(keys []string, background bool) style.TextStyle {
3030
} else if utils.IsValidHexValue(key) {
3131
c := style.NewRGBColor(color.HEX(key, background))
3232
if background {
33-
s.SetBg(c)
33+
s = s.SetBg(c)
3434
} else {
35-
s.SetFg(c)
35+
s = s.SetFg(c)
3636
}
3737
}
3838
}

pkg/theme/style_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package theme
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"github.com/gookit/color"
8+
"github.com/jesseduffield/lazygit/pkg/gui/style"
9+
)
10+
11+
func TestGetTextStyle(t *testing.T) {
12+
scenarios := []struct {
13+
name string
14+
keys []string
15+
background bool
16+
expected style.TextStyle
17+
}{
18+
{
19+
name: "empty",
20+
keys: []string{""},
21+
background: true,
22+
expected: style.New(),
23+
},
24+
{
25+
name: "named color, fg",
26+
keys: []string{"blue"},
27+
background: false,
28+
expected: style.New().SetFg(style.NewBasicColor(color.FgBlue)),
29+
},
30+
{
31+
name: "named color, bg",
32+
keys: []string{"blue"},
33+
background: true,
34+
expected: style.New().SetBg(style.NewBasicColor(color.BgBlue)),
35+
},
36+
{
37+
name: "hex color, fg",
38+
keys: []string{"#123456"},
39+
background: false,
40+
expected: style.New().SetFg(style.NewRGBColor(color.RGBColor{0x12, 0x34, 0x56, 0})),
41+
},
42+
{
43+
name: "hex color, bg",
44+
keys: []string{"#abcdef"},
45+
background: true,
46+
expected: style.New().SetBg(style.NewRGBColor(color.RGBColor{0xab, 0xcd, 0xef, 1})),
47+
},
48+
}
49+
50+
for _, scenario := range scenarios {
51+
t.Run(scenario.name, func(t *testing.T) {
52+
if actual := GetTextStyle(scenario.keys, scenario.background); !reflect.DeepEqual(actual, scenario.expected) {
53+
t.Errorf("GetTextStyle() = %v, expected %v", actual, scenario.expected)
54+
}
55+
})
56+
}
57+
}

0 commit comments

Comments
 (0)