From a4db8bd7b550c010b99f26337d841395e319890a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 20 Jan 2025 00:49:08 +0900 Subject: Make 'current-fg' inherit from 'fg' to simplify configuration If you do not want 'current-fg' to inherit attributes of 'fg', prefix it with 'regular:' to reset them. # italic and underline fzf --color fg:italic,current-fg:underline # only underline fzf --color fg:italic,current-fg:regular:underline --- src/tui/dummy.go | 6 ++++-- src/tui/light.go | 2 +- src/tui/tcell.go | 16 +++++++++++----- src/tui/tui.go | 14 +++++++++++++- 4 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src/tui') diff --git a/src/tui/dummy.go b/src/tui/dummy.go index aaa9a7ea..1e62e849 100644 --- a/src/tui/dummy.go +++ b/src/tui/dummy.go @@ -11,8 +11,9 @@ func HasFullscreenRenderer() bool { var DefaultBorderShape = BorderRounded func (a Attr) Merge(b Attr) Attr { - if b == AttrRegular { - return b + if b&AttrRegular > 0 { + // Only keep bold attribute set by the system + return b | (a & BoldForce) } return a | b @@ -22,6 +23,7 @@ const ( AttrUndefined = Attr(0) AttrRegular = Attr(1 << 8) AttrClear = Attr(1 << 9) + BoldForce = Attr(1 << 10) Bold = Attr(1) Dim = Attr(1 << 1) diff --git a/src/tui/light.go b/src/tui/light.go index 48202bce..f4688060 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -1011,7 +1011,7 @@ func attrCodes(attr Attr) []string { if (attr & AttrClear) > 0 { return codes } - if (attr & Bold) > 0 { + if (attr&Bold) > 0 || (attr&BoldForce) > 0 { codes = append(codes, "1") } if (attr & Dim) > 0 { diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 991052bd..0bf160c4 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -97,6 +97,7 @@ const ( AttrUndefined = Attr(0) AttrRegular = Attr(1 << 7) AttrClear = Attr(1 << 8) + BoldForce = Attr(1 << 10) ) func (r *FullscreenRenderer) PassThrough(str string) { @@ -141,6 +142,11 @@ func (c Color) Style() tcell.Color { } func (a Attr) Merge(b Attr) Attr { + if b&AttrRegular > 0 { + // Only keep bold attribute set by the system + return b | (a & BoldForce) + } + return a | b } @@ -556,13 +562,13 @@ func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, normal := ColBorder switch windowType { case WindowList: - normal = ColListBorder + normal = ColNormal case WindowHeader: - normal = ColHeaderBorder + normal = ColHeader case WindowInput: - normal = ColInputBorder + normal = ColInput case WindowPreview: - normal = ColPreviewBorder + normal = ColPreview } w := &TcellWindow{ color: r.theme.Colored, @@ -694,7 +700,7 @@ func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn { } style = style. Blink(a&Attr(tcell.AttrBlink) != 0). - Bold(a&Attr(tcell.AttrBold) != 0). + Bold(a&Attr(tcell.AttrBold) != 0 || a&BoldForce != 0). Dim(a&Attr(tcell.AttrDim) != 0). Reverse(a&Attr(tcell.AttrReverse) != 0). Underline(a&Attr(tcell.AttrUnderline) != 0). diff --git a/src/tui/tui.go b/src/tui/tui.go index 212a1bed..58c1bec5 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -213,6 +213,16 @@ func NewColorAttr() ColorAttr { return ColorAttr{Color: colUndefined, Attr: AttrUndefined} } +func (a ColorAttr) Merge(other ColorAttr) ColorAttr { + if other.Color != colUndefined { + a.Color = other.Color + } + if other.Attr != AttrUndefined { + a.Attr = a.Attr.Merge(other.Attr) + } + return a +} + const ( colUndefined Color = -2 colDefault Color = -1 @@ -904,7 +914,9 @@ func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool, hasInp theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg) theme.Prompt = o(baseTheme.Prompt, theme.Prompt) theme.Match = o(baseTheme.Match, theme.Match) - theme.Current = o(baseTheme.Current, theme.Current) + // Inherit from 'fg', so that we don't have to write 'current-fg:dim' + // e.g. fzf --delimiter / --nth -1 --color fg:dim,nth:regular + theme.Current = theme.Fg.Merge(o(baseTheme.Current, theme.Current)) theme.CurrentMatch = o(baseTheme.CurrentMatch, theme.CurrentMatch) theme.Spinner = o(baseTheme.Spinner, theme.Spinner) theme.Info = o(baseTheme.Info, theme.Info) -- cgit v1.2.3