Allow customizing the color of preview scrollbar via 'preview-scrollbar'

This commit is contained in:
Junegunn Choi 2023-05-14 18:28:46 +09:00
parent 94999101e3
commit 5a39102405
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
4 changed files with 186 additions and 164 deletions

View File

@ -446,8 +446,10 @@ color mappings.
\fBdisabled \fRQuery string when search is disabled (\fB--disabled\fR)
\fBinfo \fRInfo line (match counters)
\fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR)
\fBseparator \fRHorizontal separator on info line
\fBscrollbar \fRScrollbar
\fBpreview-border \fRBorder around the preview window (\fB--preview\fR)
\fBpreview-scrollbar \fRScrollbar
\fBseparator \fRHorizontal separator on info line
\fBlabel \fRBorder label (\fB--border-label\fR and \fB--preview-label\fR)
\fBpreview-label \fRBorder label of the preview window (\fB--preview-label\fR)
\fBprompt \fRPrompt

View File

@ -888,10 +888,14 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme {
mergeAttr(&theme.CurrentMatch)
case "border":
mergeAttr(&theme.Border)
case "preview-border":
mergeAttr(&theme.PreviewBorder)
case "separator":
mergeAttr(&theme.Separator)
case "scrollbar":
mergeAttr(&theme.Scrollbar)
case "preview-scrollbar":
mergeAttr(&theme.PreviewScrollbar)
case "label":
mergeAttr(&theme.BorderLabel)
case "preview-label":

View File

@ -1930,7 +1930,9 @@ func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unc
func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int) {
height := t.pwindow.Height()
w := t.pborder.Width()
redraw := false
if len(t.previewer.bar) != height {
redraw = true
t.previewer.bar = make([]bool, height)
}
xshift := -1 - t.borderWidth
@ -1947,7 +1949,7 @@ func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int)
// Avoid unnecessary redraws
bar := i >= yoff+barStart && i < yoff+barStart+barLength
if bar == t.previewer.bar[i] && !t.tui.NeedScrollbarRedraw() {
if !redraw && bar == t.previewer.bar[i] && !t.tui.NeedScrollbarRedraw() {
continue
}
@ -1956,7 +1958,7 @@ func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int)
if i >= yoff+barStart && i < yoff+barStart+barLength {
t.pborder.CPrint(tui.ColPreviewScrollbar, t.scrollbar)
} else {
t.pborder.Print(" ")
t.pborder.CPrint(tui.ColPreviewScrollbar, " ")
}
}
}

View File

@ -274,6 +274,8 @@ type ColorTheme struct {
Separator ColorAttr
Scrollbar ColorAttr
Border ColorAttr
PreviewBorder ColorAttr
PreviewScrollbar ColorAttr
BorderLabel ColorAttr
PreviewLabel ColorAttr
}
@ -528,6 +530,8 @@ func EmptyTheme() *ColorTheme {
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
Gutter: ColorAttr{colUndefined, AttrUndefined},
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
Separator: ColorAttr{colUndefined, AttrUndefined},
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
@ -556,6 +560,8 @@ func NoColorTheme() *ColorTheme {
PreviewFg: ColorAttr{colDefault, AttrUndefined},
PreviewBg: ColorAttr{colDefault, AttrUndefined},
Gutter: ColorAttr{colDefault, AttrUndefined},
PreviewBorder: ColorAttr{colDefault, AttrUndefined},
PreviewScrollbar: ColorAttr{colDefault, AttrUndefined},
PreviewLabel: ColorAttr{colDefault, AttrUndefined},
Separator: ColorAttr{colDefault, AttrUndefined},
Scrollbar: ColorAttr{colDefault, AttrUndefined},
@ -589,6 +595,8 @@ func init() {
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
Gutter: ColorAttr{colUndefined, AttrUndefined},
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
Separator: ColorAttr{colUndefined, AttrUndefined},
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
@ -614,6 +622,8 @@ func init() {
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
Gutter: ColorAttr{colUndefined, AttrUndefined},
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
Separator: ColorAttr{colUndefined, AttrUndefined},
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
@ -639,6 +649,8 @@ func init() {
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
Gutter: ColorAttr{colUndefined, AttrUndefined},
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
Separator: ColorAttr{colUndefined, AttrUndefined},
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
@ -682,8 +694,10 @@ func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
theme.PreviewFg = o(theme.Fg, theme.PreviewFg)
theme.PreviewBg = o(theme.Bg, theme.PreviewBg)
theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel)
theme.PreviewBorder = o(theme.Border, theme.PreviewBorder)
theme.Separator = o(theme.Border, theme.Separator)
theme.Scrollbar = o(theme.Border, theme.Scrollbar)
theme.PreviewScrollbar = o(theme.PreviewBorder, theme.PreviewScrollbar)
initPalette(theme)
}
@ -721,6 +735,6 @@ func initPalette(theme *ColorTheme) {
ColBorderLabel = pair(theme.BorderLabel, theme.Bg)
ColPreviewLabel = pair(theme.PreviewLabel, theme.PreviewBg)
ColPreview = pair(theme.PreviewFg, theme.PreviewBg)
ColPreviewBorder = pair(theme.Border, theme.PreviewBg)
ColPreviewScrollbar = pair(theme.Scrollbar, theme.PreviewBg)
ColPreviewBorder = pair(theme.PreviewBorder, theme.PreviewBg)
ColPreviewScrollbar = pair(theme.PreviewScrollbar, theme.PreviewBg)
}