Add more preview window options and reduce vertical padding on noborder

Fix #2138
Fix #2029
pull/2157/head
Junegunn Choi 4 years ago
parent 1cb19dbf65
commit 9dc4b40d7a
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -10,6 +10,9 @@ CHANGELOG
--preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \ --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \
--preview-window +{2}-/2 --preview-window +{2}-/2
``` ```
- Added `--preview-window` option for sharp edges (`--preview-window sharp`)
- Reduced vertical padding around the preview window when `--preview-window
noborder` is used
0.22.0 0.22.0
------ ------

@ -381,7 +381,7 @@ Preview window will be updated even when there is no match for the current
query if any of the placeholder expressions evaluates to a non-empty string. query if any of the placeholder expressions evaluates to a non-empty string.
.RE .RE
.TP .TP
.BI "--preview-window=" "[POSITION][:SIZE[%]][:noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]" .BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"
Determines the layout of the preview window. If the argument contains Determines the layout of the preview window. If the argument contains
\fB:hidden\fR, the preview window will be hidden by default until \fB:hidden\fR, the preview window will be hidden by default until
\fBtoggle-preview\fR action is triggered. Long lines are truncated by default. \fBtoggle-preview\fR action is triggered. Long lines are truncated by default.
@ -390,6 +390,10 @@ Line wrap can be enabled with \fB:wrap\fR flag.
If size is given as 0, preview window will not be visible, but fzf will still If size is given as 0, preview window will not be visible, but fzf will still
execute the command in the background. execute the command in the background.
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
sharp edges), or \fBnoborder\fR (no border).
\fB+SCROLL[-OFFSET]\fR determines the initial scroll offset of the preview \fB+SCROLL[-OFFSET]\fR determines the initial scroll offset of the preview
window. \fBSCROLL\fR can be either a numeric integer or a single-field index window. \fBSCROLL\fR can be either a numeric integer or a single-field index
expression that refers to a numeric integer. The optional \fB-OFFSET\fR part is expression that refers to a numeric integer. The optional \fB-OFFSET\fR part is

@ -81,6 +81,7 @@ const usage = `usage: fzf [options]
--preview=COMMAND Command to preview highlighted line ({}) --preview=COMMAND Command to preview highlighted line ({})
--preview-window=OPT Preview window layout (default: right:50%) --preview-window=OPT Preview window layout (default: right:50%)
[up|down|left|right][:SIZE[%]][:wrap][:hidden][:+SCROLL[-OFFSET]] [up|down|left|right][:SIZE[%]][:wrap][:hidden][:+SCROLL[-OFFSET]]
[:rounded|sharp|noborder]
Scripting Scripting
-q, --query=STR Start the finder with the given query -q, --query=STR Start the finder with the given query
@ -162,7 +163,7 @@ type previewOpts struct {
scroll string scroll string
hidden bool hidden bool
wrap bool wrap bool
border bool border tui.BorderShape
} }
// Options stores the values of command-line options // Options stores the values of command-line options
@ -261,7 +262,7 @@ func defaultOptions() *Options {
ToggleSort: false, ToggleSort: false,
Expect: make(map[int]string), Expect: make(map[int]string),
Keymap: make(map[int][]action), Keymap: make(map[int][]action),
Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, true}, Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, tui.BorderRounded},
PrintQuery: false, PrintQuery: false,
ReadZero: false, ReadZero: false,
Printer: func(str string) { fmt.Println(str) }, Printer: func(str string) { fmt.Println(str) },
@ -1011,10 +1012,12 @@ func parsePreviewWindow(opts *previewOpts, input string) {
opts.position = posLeft opts.position = posLeft
case "right": case "right":
opts.position = posRight opts.position = posRight
case "border": case "rounded", "border":
opts.border = true opts.border = tui.BorderRounded
case "sharp":
opts.border = tui.BorderSharp
case "noborder": case "noborder":
opts.border = false opts.border = tui.BorderNone
default: default:
if sizeRegex.MatchString(token) { if sizeRegex.MatchString(token) {
opts.size = parseSize(token, 99, "window size") opts.size = parseSize(token, 99, "window size")
@ -1274,7 +1277,7 @@ func parseOptions(opts *Options, allArgs []string) {
opts.Preview.command = "" opts.Preview.command = ""
case "--preview-window": case "--preview-window":
parsePreviewWindow(&opts.Preview, parsePreviewWindow(&opts.Preview,
nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]")) nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"))
case "--height": case "--height":
opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]")) opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))
case "--min-height": case "--min-height":

@ -676,6 +676,8 @@ func (t *Terminal) resizeWindows() {
} }
if t.pborder != nil { if t.pborder != nil {
t.pborder.Close() t.pborder.Close()
}
if t.pwindow != nil {
t.pwindow.Close() t.pwindow.Close()
} }
@ -700,19 +702,28 @@ func (t *Terminal) resizeWindows() {
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode) noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
if previewVisible { if previewVisible {
createPreviewWindow := func(y int, x int, w int, h int) { createPreviewWindow := func(y int, x int, w int, h int) {
previewBorder := tui.MakeBorderStyle(tui.BorderRounded, t.unicode) pwidth := w
if !t.preview.border { pheight := h
previewBorder = tui.MakeTransparentBorder() if t.preview.border != tui.BorderNone {
previewBorder := tui.MakeBorderStyle(t.preview.border, t.unicode)
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
pwidth -= 4
pheight -= 2
x += 2
y += 1
} else {
previewBorder := tui.MakeTransparentBorder()
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
pwidth -= 2
x += 1
} }
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
pwidth := w - 4
// ncurses auto-wraps the line when the cursor reaches the right-end of // ncurses auto-wraps the line when the cursor reaches the right-end of
// the window. To prevent unintended line-wraps, we use the width one // the window. To prevent unintended line-wraps, we use the width one
// column larger than the desired value. // column larger than the desired value.
if !t.preview.wrap && t.tui.DoesAutoWrap() { if !t.preview.wrap && t.tui.DoesAutoWrap() {
pwidth += 1 pwidth += 1
} }
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, true, noBorder) t.pwindow = t.tui.NewWindow(y, x, pwidth, pheight, true, noBorder)
} }
switch t.preview.position { switch t.preview.position {
case posUp: case posUp:
@ -1210,7 +1221,10 @@ func (t *Terminal) refresh() {
windows = append(windows, t.border) windows = append(windows, t.border)
} }
if t.hasPreviewWindow() { if t.hasPreviewWindow() {
windows = append(windows, t.pborder, t.pwindow) if t.pborder != nil {
windows = append(windows, t.pborder)
}
windows = append(windows, t.pwindow)
} }
windows = append(windows, t.window) windows = append(windows, t.window)
t.tui.RefreshWindows(windows) t.tui.RefreshWindows(windows)

Loading…
Cancel
Save