Skip to content

Commit a505873

Browse files
committed
style: improve selected row contrast
1 parent f7b1a86 commit a505873

5 files changed

Lines changed: 52 additions & 3 deletions

File tree

pkg/config/app_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ func GetDefaultConfig() []byte {
240240
- blue
241241
selectedLineBgColor:
242242
- blue
243+
selectedLineFgColor:
244+
- white
245+
- bold
243246
update:
244247
method: prompt # can be: prompt | background | never
245248
days: 14 # how often a update is checked for

pkg/gui/layout.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import (
77
"github.com/jesseduffield/lazynpm/pkg/utils"
88
)
99

10+
// applyListHighlight keeps the focused row readable across all list panels.
11+
// gocui does not automatically use the configured theme value for selected rows.
12+
func (gui *Gui) applyListHighlight(view *gocui.View) {
13+
view.SelBgColor = theme.SelectedLineBgColor
14+
view.SelFgColor = theme.SelectedLineFgColor
15+
}
16+
1017
// getFocusLayout returns a manager function for when view gain and lose focus
1118
func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error {
1219
var previousView *gocui.View
@@ -249,6 +256,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
249256
packagesView.Title = gui.panelTitle("packages", 2, gui.Tr.SLocalize("PackagesTitle"))
250257
packagesView.ContainsList = true
251258
}
259+
gui.applyListHighlight(packagesView)
252260

253261
depsView, err := g.SetViewBeneath("deps", "packages", vHeights["deps"])
254262
if err != nil {
@@ -259,6 +267,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
259267
depsView.FgColor = textColor
260268
depsView.ContainsList = true
261269
}
270+
gui.applyListHighlight(depsView)
262271

263272
scriptsView, err := g.SetViewBeneath("scripts", "deps", vHeights["scripts"])
264273
if err != nil {
@@ -269,6 +278,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
269278
scriptsView.FgColor = textColor
270279
scriptsView.ContainsList = true
271280
}
281+
gui.applyListHighlight(scriptsView)
272282

273283
tarballsView, err := g.SetViewBeneath("tarballs", "scripts", vHeights["tarballs"])
274284
if err != nil {
@@ -279,6 +289,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
279289
tarballsView.FgColor = textColor
280290
tarballsView.ContainsList = true
281291
}
292+
gui.applyListHighlight(tarballsView)
282293
tarballsView.Visible = gui.showTarballsView()
283294

284295
if v, err := g.SetView("options", appStatusOptionsBoundary-1, height-2, optionsVersionBoundary-1, height, 0); err != nil {

pkg/gui/menu_panel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
7878
menuView.Title = title
7979
menuView.FgColor = theme.GocuiDefaultTextColor
8080
menuView.ContainsList = true
81+
gui.applyListHighlight(menuView)
8182
menuView.Clear()
8283
fmt.Fprint(menuView, list)
8384
gui.State.Panels.Menu.SelectedLine = 0

pkg/theme/theme.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ var (
2222
InactiveBorderColor gocui.Attribute
2323

2424
// SelectedLineBgColor is the background color for the selected line
25-
SelectedLineBgColor color.Attribute
25+
SelectedLineBgColor gocui.Attribute
26+
// SelectedLineFgColor is the foreground color for the selected line
27+
SelectedLineFgColor gocui.Attribute
2628

2729
OptionsFgColor color.Attribute
2830

@@ -35,7 +37,12 @@ var (
3537
func UpdateTheme(userConfig *viper.Viper) {
3638
ActiveBorderColor = GetGocuiColor(userConfig.GetStringSlice("gui.theme.activeBorderColor"))
3739
InactiveBorderColor = GetGocuiColor(userConfig.GetStringSlice("gui.theme.inactiveBorderColor"))
38-
SelectedLineBgColor = GetBgColor(userConfig.GetStringSlice("gui.theme.selectedLineBgColor"))
40+
SelectedLineBgColor = GetGocuiBgColor(userConfig.GetStringSlice("gui.theme.selectedLineBgColor"))
41+
selectedLineFgColor := userConfig.GetStringSlice("gui.theme.selectedLineFgColor")
42+
if len(selectedLineFgColor) == 0 {
43+
selectedLineFgColor = []string{"white", "bold"}
44+
}
45+
SelectedLineFgColor = GetGocuiColor(selectedLineFgColor)
3946
OptionsColor = GetGocuiColor(userConfig.GetStringSlice("gui.theme.optionsTextColor"))
4047
OptionsFgColor = GetFgColor(userConfig.GetStringSlice("gui.theme.optionsTextColor"))
4148

@@ -129,6 +136,29 @@ func GetGocuiColor(keys []string) gocui.Attribute {
129136
return attribute
130137
}
131138

139+
// GetGocuiBgColor converts configured background colors to gocui attributes.
140+
func GetGocuiBgColor(keys []string) gocui.Attribute {
141+
colorMap := map[string]gocui.Attribute{
142+
"default": gocui.ColorDefault,
143+
"black": gocui.ColorBlack,
144+
"red": gocui.ColorRed,
145+
"green": gocui.ColorGreen,
146+
"yellow": gocui.ColorYellow,
147+
"blue": gocui.ColorBlue,
148+
"magenta": gocui.ColorMagenta,
149+
"cyan": gocui.ColorCyan,
150+
"white": gocui.ColorWhite,
151+
"bold": gocui.AttrBold,
152+
}
153+
var attribute gocui.Attribute
154+
for _, key := range keys {
155+
if value, present := colorMap[key]; present {
156+
attribute |= value
157+
}
158+
}
159+
return attribute
160+
}
161+
132162
// GetColor bitwise OR's a list of attributes obtained via the given keys
133163
func GetBgColor(keys []string) color.Attribute {
134164
var attribute color.Attribute

vendor/github.com/jesseduffield/gocui/view.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)