diff --git a/docs-master/Config.md b/docs-master/Config.md index e2107039b..09781c9de 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -192,6 +192,13 @@ gui: optionsTextColor: - blue + # Color and attributes of the text of the selected line. The attributes are + # added to those of the text, and a color replaces the colors of the text. + # Set it to 'default' to leave the text as it is, e.g. if you don't want the + # selected line in bold. + selectedLineFgColor: + - bold + # 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. @@ -1043,6 +1050,15 @@ gui: - reverse ``` +The text of the selected line is bold by default. If you don't want that, set `selectedLineFgColor` to `default`: + +```yaml +gui: + theme: + selectedLineFgColor: + - default +``` + ## Themes for dark and light backgrounds The colors in `gui.theme` apply whether your terminal has a dark or a light background. If you want different colors for the two, set them in `gui.darkTheme` or `gui.lightTheme`. These have the same fields as `gui.theme`, and a field that you set in them overrides the one in `gui.theme`: diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 8f67873a5..ce7ebd914 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -240,6 +240,9 @@ type ThemeConfig struct { SearchingActiveBorderColor []string `yaml:"searchingActiveBorderColor" jsonschema:"minItems=1,uniqueItems=true"` // Color of keybindings help text in the bottom line OptionsTextColor []string `yaml:"optionsTextColor" jsonschema:"minItems=1,uniqueItems=true"` + // Color and attributes of the text of the selected line. The attributes are added to those of the text, and a color replaces the colors of the text. + // Set it to 'default' to leave the text as it is, e.g. if you don't want the selected line in bold. + SelectedLineFgColor []string `yaml:"selectedLineFgColor" 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 @@ -896,6 +899,7 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { SearchingActiveBorderColor: []string{"cyan", "bold"}, InactiveBorderColor: []string{"dim"}, OptionsTextColor: []string{"blue"}, + SelectedLineFgColor: []string{"bold"}, CherryPickedCommitBgColor: []string{"cyan"}, CherryPickedCommitFgColor: []string{"blue"}, MarkedBaseCommitBgColor: []string{"yellow"}, diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index d8202ddfc..6fbbecdb6 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -138,6 +138,12 @@ type View struct { // focus. InactiveViewSelBgColor Attribute + // SelTextColor is applied to the text of the selected line when it is + // highlighted, whether the view has the focus or not. Its attributes are + // added to those of the text, and if it has a color, that replaces the + // color of the text. + SelTextColor Attribute + // If Editable is true, keystrokes will be added to the view's internal // buffer at the cursor position. Editable bool @@ -631,7 +637,7 @@ func NewView(name string, x0, y0, x1, y1 int, mode OutputMode) *View { v.FgColor, v.BgColor = ColorDefault, ColorDefault v.SelFgColor, v.SelBgColor = ColorDefault, ColorDefault - v.InactiveViewSelBgColor = ColorDefault + v.InactiveViewSelBgColor, v.SelTextColor = ColorDefault, ColorDefault v.TitleColor, v.FrameColor = ColorDefault, ColorDefault v.buf.ei.screenColMax = v.InnerWidth() return v @@ -722,7 +728,7 @@ func (v *View) setCharacter(x, y int, ch string, fgColor, bgColor Attribute, isW } if y >= rangeSelectStart && y <= rangeSelectEnd { - fgColor = fgColor | AttrBold + fgColor = applySelTextColor(fgColor, v.SelTextColor) if v.HighlightInactive || !isWindowFocused { bgColor = (bgColor & AttrStyleBits) | v.InactiveViewSelBgColor } else { @@ -1838,6 +1844,15 @@ func indexFunc(r rune) bool { return r == ' ' || r == 0 } +// applySelTextColor adds the attributes of selTextColor to fgColor, and +// replaces the color of fgColor with that of selTextColor if it has one. +func applySelTextColor(fgColor, selTextColor Attribute) Attribute { + if selTextColor&AttrColorBits != ColorDefault { + fgColor = fgColor&AttrStyleBits | selTextColor&AttrColorBits + } + return fgColor | selTextColor&AttrStyleBits +} + // SetHighlight toggles highlighting of separate lines, for custom lists // or multiple selection in views. func (v *View) SetHighlight(y int, on bool) { diff --git a/pkg/gocui/view_test.go b/pkg/gocui/view_test.go index 2ee5eb4b8..3ffd56e7c 100644 --- a/pkg/gocui/view_test.go +++ b/pkg/gocui/view_test.go @@ -780,3 +780,43 @@ func TestMulticolorWrappedFillUsesLastCellOfEachSegment(t *testing.T) { "trailing cell at (%d, 2) should have green bg", x) } } + +func TestApplySelTextColor(t *testing.T) { + scenarios := []struct { + name string + fgColor Attribute + selTextColor Attribute + expected Attribute + }{ + { + name: "adds attributes", + fgColor: ColorRed | AttrUnderline, + selTextColor: AttrBold, + expected: ColorRed | AttrUnderline | AttrBold, + }, + { + name: "replaces the color", + fgColor: ColorRed | AttrUnderline, + selTextColor: ColorWhite | AttrBold, + expected: ColorWhite | AttrUnderline | AttrBold, + }, + { + name: "replaces an RGB color", + fgColor: NewRGBColor(0x12, 0x34, 0x56), + selTextColor: ColorBlue, + expected: ColorBlue, + }, + { + name: "leaves the text alone if default", + fgColor: ColorRed | AttrUnderline, + selTextColor: ColorDefault, + expected: ColorRed | AttrUnderline, + }, + } + + for _, s := range scenarios { + t.Run(s.name, func(t *testing.T) { + assert.Equal(t, s.expected, applySelTextColor(s.fgColor, s.selTextColor)) + }) + } +} diff --git a/pkg/gui/views.go b/pkg/gui/views.go index 7b6fa93eb..2fb115f91 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -204,6 +204,7 @@ func (gui *Gui) configureViewProperties() { (*mapping.viewPtr).SelBgColor = theme.GocuiSelectedLineBgColor (*mapping.viewPtr).SelFgColor = gui.g.SelFgColor (*mapping.viewPtr).InactiveViewSelBgColor = theme.GocuiInactiveViewSelectedLineBgColor + (*mapping.viewPtr).SelTextColor = theme.GocuiSelectedLineFgColor } gui.Views.MenuFilterFrame.FrameRunes = frameRunesWithTopCorners(frameRunes, teeLeft, teeRight) diff --git a/pkg/theme/theme.go b/pkg/theme/theme.go index d2e5b1291..a1715fa34 100644 --- a/pkg/theme/theme.go +++ b/pkg/theme/theme.go @@ -26,6 +26,8 @@ var ( GocuiSelectedLineBgColor gocui.Attribute // GocuiInactiveViewSelectedLineBgColor is the background color for the selected line in gocui if the view doesn't have focus GocuiInactiveViewSelectedLineBgColor gocui.Attribute + // GocuiSelectedLineFgColor is applied to the text of the selected line in gocui + GocuiSelectedLineFgColor gocui.Attribute OptionsColor gocui.Attribute @@ -68,6 +70,7 @@ func UpdateTheme(themeConfig config.ThemeConfig) { GocuiSelectedLineBgColor = GetGocuiStyle(themeConfig.SelectedLineBgColor) GocuiInactiveViewSelectedLineBgColor = GetGocuiStyle(themeConfig.InactiveViewSelectedLineBgColor) + GocuiSelectedLineFgColor = GetGocuiStyle(themeConfig.SelectedLineFgColor) OptionsColor = GetGocuiStyle(themeConfig.OptionsTextColor) OptionsFgColor = GetTextStyle(themeConfig.OptionsTextColor, false) diff --git a/schema-master/config.json b/schema-master/config.json index b6194d3f0..526b2fbf0 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -767,6 +767,18 @@ "blue" ] }, + "selectedLineFgColor": { + "items": { + "type": "string" + }, + "type": "array", + "minItems": 1, + "uniqueItems": true, + "description": "Color and attributes of the text of the selected line. The attributes are added to those of the text, and a color replaces the colors of the text.\nSet it to 'default' to leave the text as it is, e.g. if you don't want the selected line in bold.", + "default": [ + "bold" + ] + }, "selectedLineBgColor": { "items": { "type": "string" @@ -907,6 +919,15 @@ "uniqueItems": true, "description": "Color of keybindings help text in the bottom line" }, + "selectedLineFgColor": { + "items": { + "type": "string" + }, + "type": "array", + "minItems": 1, + "uniqueItems": true, + "description": "Color and attributes of the text of the selected line. The attributes are added to those of the text, and a color replaces the colors of the text.\nSet it to 'default' to leave the text as it is, e.g. if you don't want the selected line in bold." + }, "selectedLineBgColor": { "items": { "type": "string" @@ -1029,6 +1050,15 @@ "uniqueItems": true, "description": "Color of keybindings help text in the bottom line" }, + "selectedLineFgColor": { + "items": { + "type": "string" + }, + "type": "array", + "minItems": 1, + "uniqueItems": true, + "description": "Color and attributes of the text of the selected line. The attributes are added to those of the text, and a color replaces the colors of the text.\nSet it to 'default' to leave the text as it is, e.g. if you don't want the selected line in bold." + }, "selectedLineBgColor": { "items": { "type": "string"