Allow customizing scrollbar of the preview window via --scrollbar=xy

pull/3299/head
Junegunn Choi 1 year ago
parent 43436e48e0
commit 17a13f00f8
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -5,6 +5,15 @@ CHANGELOG
------
- Added color name `preview-border` and `preview-scrollbar`
- Added new border style `block` which uses [block elements](https://en.wikipedia.org/wiki/Block_Elements)
- `--scrollbar` can take two characters, one for the main window, the other
for the preview window
- Putting it altogether
```sh
fzf-tmux -p 80% --padding 1,2 --preview 'bat --style=plain --color=always {}' \
--color 'bg:#222233,bg+:#333344,gutter:#222233,border:#111122,scrollbar:#ffaa00' \
--color 'preview-bg:#332233,preview-border:#222222,preview-scrollbar:#00aaff' \
--preview-window 'border-block' --border block --scrollbar '▌▐'
```
- Bug fixes and improvements
0.40.0

@ -377,9 +377,10 @@ Do not display horizontal separator on the info line. A synonym for
\fB--separator=''\fB
.TP
.BI "--scrollbar=" "CHAR"
.BI "--scrollbar=" "CHAR1[CHAR2]"
Use the given character to render scrollbar. (default: '│' or ':' depending on
\fB--no-unicode\fR).
\fB--no-unicode\fR). The optional \fBCHAR2\fR is used to render scrollbar of
the preview window.
.TP
.B "--no-scrollbar"

@ -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, " ")
}

Loading…
Cancel
Save