mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
Let users turn off the bold text of the selected line
The text of the selected line is always bold. Some users don't like this (#2304), but there is no way to turn it off. Setting selectedLineBgColor doesn't help. Its attributes apply to the text too, so it can add bold, but it can't take it away. Add gui.theme.selectedLineFgColor for the text of the selected line, in focused and unfocused views alike. Its attributes are added to those of the text, and a color replaces the colors of the text. It is [bold] by default, so nothing changes unless you set it; 'default' leaves the text as it is. Putting bold into the default of selectedLineBgColor instead wouldn't work well. To turn it off, you would have to replace the whole list, and lose the color that is computed from the terminal's background. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c1b14ea2af
commit
5196c4fab5
@@ -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"},
|
||||
|
||||
+17
-2
@@ -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) {
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user