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": {