mirror of
https://github.com/junegunn/fzf.git
synced 2025-12-06 04:44:25 +08:00
feat: add alt-gutter color option (#4602)
* Add alt-gutter color option * Simplify the code --------- Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
@@ -272,6 +272,7 @@ color mappings. Each entry is separated by a comma and/or whitespaces.
|
||||
\fBgutter \fRGutter on the left
|
||||
\fBcurrent\-hl (hl+) \fRHighlighted substrings (current line)
|
||||
\fBalt\-bg \fRAlternate background color to create striped lines
|
||||
\fBalt\-gutter \fRAlternate gutter color to create the striped pattern
|
||||
\fBquery (input\-fg) \fRQuery string
|
||||
\fBghost \fRGhost text (\fB\-\-ghost\fR, \fBdim\fR applied by default)
|
||||
\fBdisabled \fRQuery string when search is disabled (\fB\-\-disabled\fR)
|
||||
|
||||
@@ -1476,6 +1476,8 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) (*tui.ColorTheme, *tui
|
||||
mergeAttr(&theme.Nomatch)
|
||||
case "gutter":
|
||||
mergeAttr(&theme.Gutter)
|
||||
case "alt-gutter":
|
||||
mergeAttr(&theme.AltGutter)
|
||||
case "hl":
|
||||
mergeAttr(&theme.Match)
|
||||
case "current-hl", "hl+":
|
||||
|
||||
@@ -3202,14 +3202,22 @@ func (t *Terminal) renderEmptyLine(line int, barRange [2]int) {
|
||||
t.renderBar(line, barRange)
|
||||
}
|
||||
|
||||
func (t *Terminal) gutter(current bool) {
|
||||
func (t *Terminal) gutter(current bool, alt bool) {
|
||||
var color tui.ColorPair
|
||||
if current {
|
||||
color = tui.ColCurrentCursorEmpty
|
||||
} else if !t.raw && t.gutterReverse || t.raw && t.gutterRawReverse {
|
||||
color = tui.ColCursorEmpty
|
||||
if alt {
|
||||
color = tui.ColAltCursorEmpty
|
||||
} else {
|
||||
color = tui.ColCursorEmpty
|
||||
}
|
||||
} else {
|
||||
color = tui.ColCursorEmptyChar
|
||||
if alt {
|
||||
color = tui.ColAltCursorEmptyChar
|
||||
} else {
|
||||
color = tui.ColCursorEmptyChar
|
||||
}
|
||||
}
|
||||
gutter := t.pointerEmpty
|
||||
if t.raw {
|
||||
@@ -3220,7 +3228,7 @@ func (t *Terminal) gutter(current bool) {
|
||||
|
||||
func (t *Terminal) renderGapLine(line int, barRange [2]int, drawLine bool) {
|
||||
t.move(line, 0, false)
|
||||
t.gutter(false)
|
||||
t.gutter(false, false)
|
||||
t.window.Print(t.markerEmpty)
|
||||
x := t.pointerLen + t.markerLen
|
||||
|
||||
@@ -3394,7 +3402,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
|
||||
return indentSize
|
||||
}
|
||||
if len(label) == 0 {
|
||||
t.gutter(true)
|
||||
t.gutter(true, false)
|
||||
} else {
|
||||
t.window.CPrint(tui.ColCurrentCursor, label)
|
||||
}
|
||||
@@ -3416,7 +3424,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
|
||||
return indentSize
|
||||
}
|
||||
if len(label) == 0 {
|
||||
t.gutter(false)
|
||||
t.gutter(false, index%2 == 1)
|
||||
} else {
|
||||
t.window.CPrint(tui.ColCursor, label)
|
||||
}
|
||||
|
||||
@@ -456,6 +456,7 @@ type ColorTheme struct {
|
||||
PreviewBg ColorAttr
|
||||
DarkBg ColorAttr
|
||||
Gutter ColorAttr
|
||||
AltGutter ColorAttr
|
||||
Prompt ColorAttr
|
||||
InputBg ColorAttr
|
||||
InputBorder ColorAttr
|
||||
@@ -826,6 +827,8 @@ var (
|
||||
ColCursor ColorPair
|
||||
ColCursorEmpty ColorPair
|
||||
ColCursorEmptyChar ColorPair
|
||||
ColAltCursorEmpty ColorPair
|
||||
ColAltCursorEmptyChar ColorPair
|
||||
ColMarker ColorPair
|
||||
ColSelected ColorPair
|
||||
ColSelectedMatch ColorPair
|
||||
@@ -891,6 +894,7 @@ func init() {
|
||||
PreviewFg: defaultColor,
|
||||
PreviewBg: defaultColor,
|
||||
Gutter: undefined,
|
||||
AltGutter: undefined,
|
||||
PreviewBorder: defaultColor,
|
||||
PreviewScrollbar: defaultColor,
|
||||
PreviewLabel: defaultColor,
|
||||
@@ -943,6 +947,7 @@ func init() {
|
||||
PreviewFg: undefined,
|
||||
PreviewBg: undefined,
|
||||
Gutter: undefined,
|
||||
AltGutter: undefined,
|
||||
PreviewBorder: undefined,
|
||||
PreviewScrollbar: undefined,
|
||||
PreviewLabel: undefined,
|
||||
@@ -991,6 +996,7 @@ func init() {
|
||||
PreviewFg: undefined,
|
||||
PreviewBg: undefined,
|
||||
Gutter: undefined,
|
||||
AltGutter: undefined,
|
||||
PreviewBorder: undefined,
|
||||
PreviewScrollbar: undefined,
|
||||
PreviewLabel: undefined,
|
||||
@@ -1041,6 +1047,7 @@ func init() {
|
||||
PreviewFg: undefined,
|
||||
PreviewBg: undefined,
|
||||
Gutter: undefined,
|
||||
AltGutter: undefined,
|
||||
PreviewBorder: undefined,
|
||||
PreviewScrollbar: undefined,
|
||||
PreviewLabel: undefined,
|
||||
@@ -1091,6 +1098,7 @@ func init() {
|
||||
PreviewFg: undefined,
|
||||
PreviewBg: undefined,
|
||||
Gutter: undefined,
|
||||
AltGutter: undefined,
|
||||
PreviewBorder: undefined,
|
||||
PreviewScrollbar: undefined,
|
||||
PreviewLabel: undefined,
|
||||
@@ -1208,6 +1216,7 @@ func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, boldify bool, forceBlac
|
||||
gutter.Attr = Dim
|
||||
}
|
||||
theme.Gutter = o(theme.DarkBg, gutter)
|
||||
theme.AltGutter = o(theme.Gutter, theme.AltGutter)
|
||||
theme.PreviewFg = o(theme.Fg, theme.PreviewFg)
|
||||
theme.PreviewBg = o(theme.Bg, theme.PreviewBg)
|
||||
theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel)
|
||||
@@ -1277,6 +1286,8 @@ func initPalette(theme *ColorTheme) {
|
||||
ColCursor = pair(theme.Cursor, theme.Gutter)
|
||||
ColCursorEmpty = pair(blank, theme.Gutter)
|
||||
ColCursorEmptyChar = pair(theme.Gutter, theme.ListBg)
|
||||
ColAltCursorEmpty = pair(blank, theme.AltGutter)
|
||||
ColAltCursorEmptyChar = pair(theme.AltGutter, theme.ListBg)
|
||||
if theme.SelectedBg.Color != theme.ListBg.Color {
|
||||
ColMarker = pair(theme.Marker, theme.SelectedBg)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user