summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-05-16 23:53:10 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-05-16 23:59:08 +0900
commit17a13f00f8f17ba32b3f5737fda7055af023b269 (patch)
tree31de164fcb30da2440433ccb8353ee7045fbf508
parent43436e48e0dacb51f9ab3da84b4c1ec697b744da (diff)
Allow customizing scrollbar of the preview window via --scrollbar=xy
-rw-r--r--CHANGELOG.md9
-rw-r--r--man/man1/fzf.15
-rw-r--r--src/options.go14
-rw-r--r--src/terminal.go13
4 files changed, 34 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b67cc726..daad09d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index 1ff1fe03..1dcbc550 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -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"
diff --git a/src/options.go b/src/options.go
index e50c1fcc..6e3040b3 100644
--- a/src/options.go
+++ b/src/options.go
@@ -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
diff --git a/src/terminal.go b/src/terminal.go
index c8e2791c..5748b3d6 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -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, " ")
}