Skip to content
Myr

Make 'current-fg' inherit from 'fg' to simplify configuration

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Junegunn Choi · committed by Junegunn Choi · parent f1c1b02 · Browse files · 9 files+70 added−49 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+70 added−49 removed

  • other:+70 added−49 removed

9 files+70 added−49 removed

modified:src/tui/dummy.go+4 added-2 removed
9 unmodified lines
1011var DefaultBorderShape = BorderRounded1213func (a Attr) Merge(b Attr) Attr {14 if b == AttrRegular {15 return b14 if b&AttrRegular > 0 {15 // Only keep bold attribute set by the system16 return b | (a & BoldForce)17 }1819 return a | b20}
1 unmodified line
22const (23 AttrUndefined = Attr(0)24 AttrRegular = Attr(1 << 8)25 AttrClear = Attr(1 << 9)26 BoldForce = Attr(1 << 10)2728 Bold = Attr(1)29 Dim = Attr(1 << 1)30 Italic = Attr(1 << 2)
30 unmodified lines
modified:src/tui/light.go+1 added-1 removed
1009 unmodified lines
1010 codes := []string{}1011 if (attr & AttrClear) > 0 {1012 return codes1013 }1014 if (attr & Bold) > 0 {1014 if (attr&Bold) > 0 || (attr&BoldForce) > 0 {1015 codes = append(codes, "1")1016 }1017 if (attr & Dim) > 0 {1018 codes = append(codes, "2")
196 unmodified lines
modified:src/tui/tcell.go+11 added-5 removed
95 unmodified lines
96const (97 AttrUndefined = Attr(0)98 AttrRegular = Attr(1 << 7)99 AttrClear = Attr(1 << 8)100 BoldForce = Attr(1 << 10)101)102103func (r *FullscreenRenderer) PassThrough(str string) {104 // No-op
36 unmodified lines
141 }142}143144func (a Attr) Merge(b Attr) Attr {145 if b&AttrRegular > 0 {146 // Only keep bold attribute set by the system147 return b | (a & BoldForce)148 }149150 return a | b151}152153// handle the following as private members of FullscreenRenderer instance
407 unmodified lines
561 height = util.Max(0, height)562 normal := ColBorder563 switch windowType {564 case WindowList:559 normal = ColListBorder565 normal = ColNormal566 case WindowHeader:561 normal = ColHeaderBorder567 normal = ColHeader568 case WindowInput:563 normal = ColInputBorder569 normal = ColInput570 case WindowPreview:565 normal = ColPreviewBorder571 normal = ColPreview572 }573 w := &TcellWindow{574 color: r.theme.Colored,575 windowType: windowType,
123 unmodified lines
699 style = w.normal.style()700 }701 style = style.702 Blink(a&Attr(tcell.AttrBlink) != 0).697 Bold(a&Attr(tcell.AttrBold) != 0).703 Bold(a&Attr(tcell.AttrBold) != 0 || a&BoldForce != 0).704 Dim(a&Attr(tcell.AttrDim) != 0).705 Reverse(a&Attr(tcell.AttrReverse) != 0).706 Underline(a&Attr(tcell.AttrUnderline) != 0).707 StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).
162 unmodified lines
modified:src/tui/tui.go+13 added-1 removed
211 unmodified lines
212func NewColorAttr() ColorAttr {213 return ColorAttr{Color: colUndefined, Attr: AttrUndefined}214}215216func (a ColorAttr) Merge(other ColorAttr) ColorAttr {217 if other.Color != colUndefined {218 a.Color = other.Color219 }220 if other.Attr != AttrUndefined {221 a.Attr = a.Attr.Merge(other.Attr)222 }223 return a224}225226const (227 colUndefined Color = -2228 colDefault Color = -1229)
683 unmodified lines
913 theme.Bg = o(baseTheme.Bg, theme.Bg)914 theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg)915 theme.Prompt = o(baseTheme.Prompt, theme.Prompt)916 theme.Match = o(baseTheme.Match, theme.Match)907 theme.Current = o(baseTheme.Current, theme.Current)917 // Inherit from 'fg', so that we don't have to write 'current-fg:dim'918 // e.g. fzf --delimiter / --nth -1 --color fg:dim,nth:regular919 theme.Current = theme.Fg.Merge(o(baseTheme.Current, theme.Current))920 theme.CurrentMatch = o(baseTheme.CurrentMatch, theme.CurrentMatch)921 theme.Spinner = o(baseTheme.Spinner, theme.Spinner)922 theme.Info = o(baseTheme.Info, theme.Info)923 theme.Cursor = o(baseTheme.Cursor, theme.Cursor)
111 unmodified lines
modified:src/ansi.go+1 added-1 removed
42 unmodified lines
43 return ""44 }4546 ret := ""47 if s.attr&tui.Bold > 0 {47 if s.attr&tui.Bold > 0 || s.attr&tui.BoldForce > 0 {48 ret += "1;"49 }50 if s.attr&tui.Dim > 0 {51 ret += "2;"
430 unmodified lines
modified:src/options.go+1 added-1 removed
3133 unmodified lines
3134 theme := opts.Theme3135 boldify := func(c tui.ColorAttr) tui.ColorAttr {3136 dup := c3137 if (c.Attr & tui.AttrRegular) == 0 {3138 dup.Attr |= tui.Bold3138 dup.Attr |= tui.BoldForce3139 }3140 return dup3141 }3142 theme.Current = boldify(theme.Current)
89 unmodified lines
modified:src/result.go+9 added-8 removed
148 unmodified lines
149 }150 }151152 for _, off := range nthOffsets {153 // Exclude the whole line154 if int(off[1])-int(off[0]) == result.item.text.Length() {155 continue156 }153 for i := off[0]; i < off[1]; i++ {154 cols[i].nth = true155 }156 }
28 unmodified lines
185 var colors []colorOffset186 add := func(idx int) {187 if (curr.color || curr.nth || curr.match) && idx > start {188 if curr.match {193 color := colMatch189 var color tui.ColorPair190 if curr.nth {191 color = colBase.WithAttr(attrNth).Merge(colMatch)192 } else {193 color = colBase.Merge(colMatch)194 }195 var url *url196 if curr.color && theme.Colored {197 ansi := itemColors[curr.index]198 url = ansi.color.url
7 unmodified lines
206 // e.g. echo -e "\x1b[32;7mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline207 // echo -e "\x1b[42mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline208 if color.Fg().IsDefault() && origColor.HasBg() {209 color = origColor210 if curr.nth {211 color = color.WithAttr(attrNth)212 }213 } else {214 color = origColor.MergeNonDefault(color)215 }216 }213 if curr.nth {214 color = color.WithAttr(attrNth)215 }217 colors = append(colors, colorOffset{218 offset: [2]int32{int32(start), int32(idx)}, color: color, match: true, url: url})219 } else if curr.color {220 ansi := itemColors[curr.index]
75 unmodified lines
modified:src/terminal.go+28 added-28 removed
2723 unmodified lines
2724 }2725 sort.Sort(ByOrder(charOffsets))2726 }27272728 // When postTask is nil, we're printing header lines. No need to care about nth.2729 var nthOffsets []Offset2730 if postTask != nil {2728 wholeCovered := len(t.nthCurrent) == 02729 for _, nth := range t.nthCurrent {2730 // Do we still want to apply a different style when the current nth2731 // covers the whole string? Probably not. And we can simplify the logic.2732 if nth.IsFull() {2733 wholeCovered = true2734 break2731 wholeCovered := len(t.nthCurrent) == 02732 for _, nth := range t.nthCurrent {2733 // Do we still want to apply a different style when the current nth2734 // covers the whole string? Probably not. And we can simplify the logic.2735 if nth.IsFull() {2736 wholeCovered = true2737 break2738 }2739 }2736 }2737 // But if 'nth' is set to 'regular', it's a sign that you're applying2738 // a different style to the rest of the string. e.g. 'nth:regular,fg:dim'2739 // In this case, we still need to apply and clear the style.2740 // We do the same when postTask is nil, which means we're printing header lines.2741 if t.nthAttr == tui.AttrRegular && wholeCovered || postTask == nil {2742 if t.nthAttr == tui.AttrRegular {2740 if wholeCovered && t.nthAttr&tui.AttrRegular > 0 {2741 // But if 'nth' is set to 'regular', it's a sign that you're applying2742 // a different style to the rest of the string. e.g. 'nth:regular,fg:dim'2743 // In this case, we still need to apply it to clear the style.2744 colBase = colBase.WithAttr(t.nthAttr)2745 }2745 }2746 var nthOffsets []Offset2747 if !wholeCovered && t.nthAttr > 0 && postTask != nil {2748 var tokens []Token2749 if item.transformed != nil {2750 tokens = item.transformed.tokens2751 } else {2752 tokens = Transform(Tokenize(item.text.ToString(), t.delimiter), t.nthCurrent)2746 if !wholeCovered && t.nthAttr > 0 {2747 var tokens []Token2748 if item.transformed != nil {2749 tokens = item.transformed.tokens2750 } else {2751 tokens = Transform(Tokenize(item.text.ToString(), t.delimiter), t.nthCurrent)2752 }2753 for _, token := range tokens {2754 start := token.prefixLength2755 end := start + int32(token.text.Length())2756 nthOffsets = append(nthOffsets, Offset{int32(start), int32(end)})2757 }2758 sort.Sort(ByOrder(nthOffsets))2759 }2754 for _, token := range tokens {2755 start := token.prefixLength2756 end := start + int32(token.text.Length())2757 nthOffsets = append(nthOffsets, Offset{int32(start), int32(end)})2758 }2759 sort.Sort(ByOrder(nthOffsets))2760 }2761 allOffsets := result.colorOffsets(charOffsets, nthOffsets, t.theme, colBase, colMatch, t.nthAttr, current)27622763 maxLines := 1
3096 unmodified lines
modified:CHANGELOG.md+2 added-2 removed
88 unmodified lines
89 ls -al | fzf --nth -1 --color nth:reverse90 ls -al | fzf --nth -1 --color nth:reverse:bold9192 # Dim the other parts93 ls -al | fzf --nth -1 --color nth:regular,fg:dim,current-fg:dim93 ls -al | fzf --nth -1 --color nth:regular,fg:dim9495 # With 'change-nth'. The current nth option is exported as $FZF_NTH.96 ps -ef | fzf --reverse --header-lines 1 --header-border bottom --input-border \97 --color nth:regular,fg:dim,current-fg:dim \97 --color nth:regular,fg:dim \98 --bind 'ctrl-n:change-nth(8..|1|2|3|4|5|6|7|)' \99 --bind 'result:transform-prompt:echo "${FZF_NTH}> "'100 ```101- A single-character delimiter is now treated as a plain string delimiter rather than a regular expression delimiter, even if it's a regular expression meta-character.
2333 unmodified lines