More border optins for preview window

Close #2431
This commit is contained in:
Junegunn Choi 2021-04-06 17:37:11 +09:00
parent be36de2482
commit 15f4cfb6d9
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
4 changed files with 59 additions and 15 deletions

View File

@ -1,6 +1,15 @@
CHANGELOG CHANGELOG
========= =========
0.27.0
------
- More border options for `--preview-window`
```sh
fzf --preview 'cat {}' --preview-window border-left
fzf --preview 'cat {}' --preview-window top:border-bottom
fzf --preview 'cat {}' --preview-window top:border-horizontal
```
0.26.0 0.26.0
------ ------
- Added support for fixed header in preview window - Added support for fixed header in preview window

View File

@ -203,6 +203,8 @@ Draw border around the finder
.br .br
.BR right .BR right
.br .br
.BR none
.br
.TP .TP
.B "--no-unicode" .B "--no-unicode"
@ -442,7 +444,7 @@ e.g.
done'\fR done'\fR
.RE .RE
.TP .TP
.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:[no]wrap][:[no]follow][:[no]cycle][:[no]hidden][:+SCROLL[OFFSETS][/DENOM]][:~HEADER_LINES][:default]" .BI "--preview-window=" "[POSITION][:SIZE[%]][:border-BORDER_OPT][:[no]wrap][:[no]follow][:[no]cycle][:[no]hidden][:+SCROLL[OFFSETS][/DENOM]][:~HEADER_LINES][:default]"
.RS .RS
.B POSITION: (default: right) .B POSITION: (default: right)
@ -477,8 +479,10 @@ e.g.
* Cyclic scrolling is enabled with \fB:cycle\fR flag. * Cyclic scrolling is enabled with \fB:cycle\fR flag.
* To change the style of the border of the preview window, specify one of * To change the style of the border of the preview window, specify one of
\fBrounded\fR (border with rounded edges, default), \fBsharp\fR (border with the options for \fB--border\fR with \fBborder-\fR prefix.
sharp edges), or \fBnoborder\fR (no border). e.g. \fBborder-rounded\fR (border with rounded edges, default),
\fBborder-sharp\fR (border with sharp edges), \fBborder-left\fR,
\fBborder-none\fR, etc.
* \fB[:+SCROLL[OFFSETS][/DENOM]]\fR determines the initial scroll offset of the * \fB[:+SCROLL[OFFSETS][/DENOM]]\fR determines the initial scroll offset of the
preview window. preview window.

View File

@ -58,7 +58,7 @@ const usage = `usage: fzf [options]
--layout=LAYOUT Choose layout: [default|reverse|reverse-list] --layout=LAYOUT Choose layout: [default|reverse|reverse-list]
--border[=STYLE] Draw border around the finder --border[=STYLE] Draw border around the finder
[rounded|sharp|horizontal|vertical| [rounded|sharp|horizontal|vertical|
top|bottom|left|right] (default: rounded) top|bottom|left|right|none] (default: rounded)
--margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L) --margin=MARGIN Screen margin (TRBL | TB,RL | T,RL,B | T,R,B,L)
--padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L) --padding=PADDING Padding inside border (TRBL | TB,RL | T,RL,B | T,R,B,L)
--info=STYLE Finder info style [default|inline|hidden] --info=STYLE Finder info style [default|inline|hidden]
@ -83,7 +83,7 @@ const usage = `usage: fzf [options]
--preview-window=OPT Preview window layout (default: right:50%) --preview-window=OPT Preview window layout (default: right:50%)
[up|down|left|right][:SIZE[%]] [up|down|left|right][:SIZE[%]]
[:[no]wrap][:[no]cycle][:[no]follow][:[no]hidden] [:[no]wrap][:[no]cycle][:[no]follow][:[no]hidden]
[:rounded|sharp|noborder] [:border-BORDER_OPT]
[:+SCROLL[OFFSETS][/DENOM]][:~HEADER_LINES] [:+SCROLL[OFFSETS][/DENOM]][:~HEADER_LINES]
[:default] [:default]
@ -436,11 +436,13 @@ func parseBorder(str string, optional bool) tui.BorderShape {
return tui.BorderLeft return tui.BorderLeft
case "right": case "right":
return tui.BorderRight return tui.BorderRight
case "none":
return tui.BorderNone
default: default:
if optional && str == "" { if optional && str == "" {
return tui.BorderRounded return tui.BorderRounded
} }
errorExit("invalid border style (expected: rounded|sharp|horizontal|vertical|top|bottom|left|right)") errorExit("invalid border style (expected: rounded|sharp|horizontal|vertical|top|bottom|left|right|none)")
} }
return tui.BorderNone return tui.BorderNone
} }
@ -1105,12 +1107,24 @@ func parsePreviewWindow(opts *previewOpts, input string) {
opts.position = posLeft opts.position = posLeft
case "right": case "right":
opts.position = posRight opts.position = posRight
case "rounded", "border": case "rounded", "border", "border-rounded":
opts.border = tui.BorderRounded opts.border = tui.BorderRounded
case "sharp": case "sharp", "border-sharp":
opts.border = tui.BorderSharp opts.border = tui.BorderSharp
case "noborder": case "noborder", "border-none":
opts.border = tui.BorderNone opts.border = tui.BorderNone
case "border-horizontal":
opts.border = tui.BorderHorizontal
case "border-vertical":
opts.border = tui.BorderVertical
case "border-top":
opts.border = tui.BorderTop
case "border-bottom":
opts.border = tui.BorderBottom
case "border-left":
opts.border = tui.BorderLeft
case "border-right":
opts.border = tui.BorderRight
case "follow": case "follow":
opts.follow = true opts.follow = true
case "nofollow": case "nofollow":

View File

@ -831,16 +831,33 @@ func (t *Terminal) resizeWindows() {
createPreviewWindow := func(y int, x int, w int, h int) { createPreviewWindow := func(y int, x int, w int, h int) {
pwidth := w pwidth := w
pheight := h pheight := h
if t.previewOpts.border != tui.BorderNone { var previewBorder tui.BorderStyle
previewBorder := tui.MakeBorderStyle(t.previewOpts.border, t.unicode) if t.previewOpts.border == tui.BorderNone {
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder) previewBorder = tui.MakeTransparentBorder()
} else {
previewBorder = tui.MakeBorderStyle(t.previewOpts.border, t.unicode)
}
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
switch t.previewOpts.border {
case tui.BorderSharp, tui.BorderRounded:
pwidth -= 4 pwidth -= 4
pheight -= 2 pheight -= 2
x += 2 x += 2
y += 1 y += 1
} else { case tui.BorderLeft:
previewBorder := tui.MakeTransparentBorder() pwidth -= 2
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder) x += 2
case tui.BorderRight:
pwidth -= 2
case tui.BorderTop:
pheight -= 1
y += 1
case tui.BorderBottom:
pheight -= 1
case tui.BorderHorizontal:
pheight -= 2
y += 1
case tui.BorderVertical:
pwidth -= 4 pwidth -= 4
x += 2 x += 2
} }