From 17a13f00f8f17ba32b3f5737fda7055af023b269 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 16 May 2023 23:53:10 +0900 Subject: [PATCH] Allow customizing scrollbar of the preview window via --scrollbar=xy --- CHANGELOG.md | 9 +++++++++ man/man1/fzf.1 | 5 +++-- src/options.go | 14 +++++++++++--- src/terminal.go | 13 +++++++++++-- 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, " ") }