mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 15:53:39 -05:00
Allow customizing scrollbar of the preview window via --scrollbar=xy
This commit is contained in:
@@ -75,7 +75,7 @@ const usage = `usage: fzf [options]
|
||||
--info=STYLE Finder info style [default|hidden|inline|inline:SEPARATOR]
|
||||
--separator=STR String to form horizontal separator on info line
|
||||
--no-separator Hide info line separator
|
||||
--scrollbar[=CHAR] Scrollbar character
|
||||
--scrollbar[=C1[C2]] Scrollbar character(s) (each for main and preview window)
|
||||
--no-scrollbar Hide scrollbar
|
||||
--prompt=STR Input prompt (default: '> ')
|
||||
--pointer=STR Pointer to the current line (default: '>')
|
||||
@@ -1960,8 +1960,16 @@ func postProcessOptions(opts *Options) {
|
||||
errorExit("--height option is currently not supported on this platform")
|
||||
}
|
||||
|
||||
if opts.Scrollbar != nil && runewidth.StringWidth(*opts.Scrollbar) > 1 {
|
||||
errorExit("scrollbar display width should be 1")
|
||||
if opts.Scrollbar != nil {
|
||||
runes := []rune(*opts.Scrollbar)
|
||||
if len(runes) > 2 {
|
||||
errorExit("--scrollbar should be given one or two characters")
|
||||
}
|
||||
for _, r := range runes {
|
||||
if runewidth.RuneWidth(r) != 1 {
|
||||
errorExit("scrollbar display width should be 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Default actions for CTRL-N / CTRL-P when --history is set
|
||||
|
||||
@@ -199,6 +199,7 @@ type Terminal struct {
|
||||
header0 []string
|
||||
ellipsis string
|
||||
scrollbar string
|
||||
previewScrollbar string
|
||||
ansi bool
|
||||
tabstop int
|
||||
margin [4]sizeSpec
|
||||
@@ -690,8 +691,16 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
} else {
|
||||
t.scrollbar = "|"
|
||||
}
|
||||
t.previewScrollbar = t.scrollbar
|
||||
} else {
|
||||
t.scrollbar = *opts.Scrollbar
|
||||
runes := []rune(*opts.Scrollbar)
|
||||
if len(runes) > 0 {
|
||||
t.scrollbar = string(runes[0])
|
||||
t.previewScrollbar = t.scrollbar
|
||||
if len(runes) > 1 {
|
||||
t.previewScrollbar = string(runes[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
||||
@@ -1956,7 +1965,7 @@ func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int)
|
||||
t.previewer.bar[i] = bar
|
||||
t.pborder.Move(y, x)
|
||||
if i >= yoff+barStart && i < yoff+barStart+barLength {
|
||||
t.pborder.CPrint(tui.ColPreviewScrollbar, t.scrollbar)
|
||||
t.pborder.CPrint(tui.ColPreviewScrollbar, t.previewScrollbar)
|
||||
} else {
|
||||
t.pborder.CPrint(tui.ColPreviewScrollbar, " ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user