Pick a selection color that is readable on light backgrounds

On a light background, the selected line is black text on the palette's
blue. With most palettes, this is hard to read. Light palettes make all
their colors dark enough to read as text on the light background, so
none of them works well as a background for text.

On a light background, mix 25% of #0064ff into the terminal's background
instead. On white, this gives #bfd8ff. The colored text on the selected
line then stays as readable as it is elsewhere.

On a dark background, keep the palette's blue. Dark palettes make it
dark enough to work as a background, and it keeps working on terminals
with only 8 colors. There, a color mixed from a dark background would
turn into black.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 08:16:06 +02:00
co-authored by Claude Opus 5.5
parent f75038abf4
commit 61f808ce90
5 changed files with 22 additions and 11 deletions
+3 -2
View File
@@ -193,9 +193,10 @@ gui:
- blue
# Background color of selected line.
# Default: 'blue' if the terminal has a dark background, or a suitable RGB blue
# computed from the background color if it is light.
# See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
selectedLineBgColor:
- blue
selectedLineBgColor: []
# Background color of selected line when view doesn't have focus.
# Default: a suitable RGB grey computed from the terminal's background color.
+11 -2
View File
@@ -25,8 +25,8 @@ func (c *GuiConfig) ThemeForBackground(lightBackground bool, backgroundColor str
// on the terminal's background. GetDefaultConfig leaves these fields empty in
// gui.theme, so that a value there comes from the user, and wins over these.
//
// They are derived from the background color, so that they keep the same
// distance from it however dark or light it is. If we don't know the
// Most of them are derived from the background color, so that they keep the
// same distance from it however dark or light it is. If we don't know the
// background color, we assume black or white.
func themeDefaults(lightBackground bool, backgroundColor string) ThemeConfig {
if len(backgroundColor) != 7 || !utils.IsValidHexValue(backgroundColor) {
@@ -35,11 +35,20 @@ func themeDefaults(lightBackground bool, backgroundColor string) ThemeConfig {
if lightBackground {
return ThemeConfig{
// The colors of a light palette are dark enough to read as text on
// the background, so none of them works as a background for text.
// Some blue mixed into the background keeps the colored text on the
// selected line as readable as elsewhere.
SelectedLineBgColor: []string{mixHexColors(backgroundColor, "#0064ff", 0.25)},
InactiveViewSelectedLineBgColor: []string{mixHexColors(backgroundColor, "#000000", 0.15)},
}
}
return ThemeConfig{
// Dark palettes make their blue dark enough to work as a background for
// text. Unlike a color derived from a dark background, it doesn't turn
// into black on terminals with only 8 colors.
SelectedLineBgColor: []string{"blue"},
InactiveViewSelectedLineBgColor: []string{mixHexColors(backgroundColor, "#ffffff", 0.3)},
}
}
+4
View File
@@ -91,6 +91,10 @@ func TestBackgroundDefaultsAreDerivedFromTheBackgroundColor(t *testing.T) {
gui := GetDefaultConfig().Gui
assert.Equal(t, []string{"#626262"}, gui.ThemeForBackground(false, "#1e1e1e").InactiveViewSelectedLineBgColor)
assert.Equal(t, []string{"#d7d1c1"}, gui.ThemeForBackground(true, "#fdf6e3").InactiveViewSelectedLineBgColor)
assert.Equal(t, []string{"blue"}, gui.ThemeForBackground(false, "#1e1e1e").SelectedLineBgColor)
assert.Equal(t, []string{"#bed2ea"}, gui.ThemeForBackground(true, "#fdf6e3").SelectedLineBgColor)
assert.Equal(t, []string{"#bfd8ff"}, gui.ThemeForBackground(true, "").SelectedLineBgColor)
}
// If gui.theme had a default for a field that also has a default for the
+1 -1
View File
@@ -241,6 +241,7 @@ type ThemeConfig struct {
// Color of keybindings help text in the bottom line
OptionsTextColor []string `yaml:"optionsTextColor" jsonschema:"minItems=1,uniqueItems=true"`
// Background color of selected line.
// Default: 'blue' if the terminal has a dark background, or a suitable RGB blue computed from the background color if it is light.
// See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line
SelectedLineBgColor []string `yaml:"selectedLineBgColor" jsonschema:"minItems=1,uniqueItems=true"`
// Background color of selected line when view doesn't have focus.
@@ -895,7 +896,6 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig {
SearchingActiveBorderColor: []string{"cyan", "bold"},
InactiveBorderColor: []string{"dim"},
OptionsTextColor: []string{"blue"},
SelectedLineBgColor: []string{"blue"},
CherryPickedCommitBgColor: []string{"cyan"},
CherryPickedCommitFgColor: []string{"blue"},
MarkedBaseCommitBgColor: []string{"yellow"},
+3 -6
View File
@@ -774,10 +774,7 @@
"type": "array",
"minItems": 1,
"uniqueItems": true,
"description": "Background color of selected line.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line",
"default": [
"blue"
]
"description": "Background color of selected line.\nDefault: 'blue' if the terminal has a dark background, or a suitable RGB blue computed from the background color if it is light.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line"
},
"inactiveViewSelectedLineBgColor": {
"items": {
@@ -917,7 +914,7 @@
"type": "array",
"minItems": 1,
"uniqueItems": true,
"description": "Background color of selected line.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line"
"description": "Background color of selected line.\nDefault: 'blue' if the terminal has a dark background, or a suitable RGB blue computed from the background color if it is light.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line"
},
"inactiveViewSelectedLineBgColor": {
"items": {
@@ -1039,7 +1036,7 @@
"type": "array",
"minItems": 1,
"uniqueItems": true,
"description": "Background color of selected line.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line"
"description": "Background color of selected line.\nDefault: 'blue' if the terminal has a dark background, or a suitable RGB blue computed from the background color if it is light.\nSee https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#highlighting-the-selected-line"
},
"inactiveViewSelectedLineBgColor": {
"items": {