From 61f808ce9049b5d67be901698f4b2ea7fea2636f Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 26 Sep 2026 16:39:24 +0200 Subject: [PATCH] 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) --- docs-master/Config.md | 5 +++-- pkg/config/theme_config.go | 13 +++++++++++-- pkg/config/theme_config_test.go | 4 ++++ pkg/config/user_config.go | 2 +- schema-master/config.json | 9 +++------ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/docs-master/Config.md b/docs-master/Config.md index 6d8f2fe10..e2107039b 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -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. diff --git a/pkg/config/theme_config.go b/pkg/config/theme_config.go index 04fdf3726..7729adb77 100644 --- a/pkg/config/theme_config.go +++ b/pkg/config/theme_config.go @@ -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)}, } } diff --git a/pkg/config/theme_config_test.go b/pkg/config/theme_config_test.go index a4bd39028..4d83b56a3 100644 --- a/pkg/config/theme_config_test.go +++ b/pkg/config/theme_config_test.go @@ -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 diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index f4d00cf60..8f67873a5 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -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"}, diff --git a/schema-master/config.json b/schema-master/config.json index 9b6383a7a..b6194d3f0 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -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": {