Skip to content
Myr

Add more preview window options and reduce vertical padding on noborder

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #2138 Fix #2029

authored by Junegunn Choi · committed by Junegunn Choi · parent 1cb19db · Browse files · 4 files+38 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+38 added−14 removed

  • other:+38 added−14 removed

4 files+38 added−14 removed

modified:man/man1/fzf.1+5 added-1 removed
379 unmodified lines
380Preview window will be updated even when there is no match for the current381query if any of the placeholder expressions evaluates to a non-empty string.382.RE383.TP384.BI "--preview-window=" "[POSITION][:SIZE[%]][:noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"384.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"385Determines the layout of the preview window. If the argument contains386\fB:hidden\fR, the preview window will be hidden by default until387\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.388Line wrap can be enabled with \fB:wrap\fR flag.389390If size is given as 0, preview window will not be visible, but fzf will still391execute the command in the background.392393To change the style of the border of the preview window, specify one of394\fBrounded\fR (border with rounded edges, default), \fBsharp\fR (border with395sharp edges), or \fBnoborder\fR (no border).396397\fB+SCROLL[-OFFSET]\fR determines the initial scroll offset of the preview398window. \fBSCROLL\fR can be either a numeric integer or a single-field index399expression that refers to a numeric integer. The optional \fB-OFFSET\fR part is400for adjusting the base offset so that you can see the text above it. It should
446 unmodified lines
modified:src/options.go+9 added-6 removed
79 unmodified lines
80 Preview81 --preview=COMMAND Command to preview highlighted line ({})82 --preview-window=OPT Preview window layout (default: right:50%)83 [up|down|left|right][:SIZE[%]][:wrap][:hidden][:+SCROLL[-OFFSET]]84 [:rounded|sharp|noborder]8586 Scripting87 -q, --query=STR Start the finder with the given query88 -1, --select-1 Automatically select the only match
73 unmodified lines
162 size sizeSpec163 scroll string164 hidden bool165 wrap bool165 border bool166 border tui.BorderShape167}168169// Options stores the values of command-line options170type Options struct {
90 unmodified lines
261 Filter: nil,262 ToggleSort: false,263 Expect: make(map[int]string),264 Keymap: make(map[int][]action),264 Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, true},265 Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, tui.BorderRounded},266 PrintQuery: false,267 ReadZero: false,268 Printer: func(str string) { fmt.Println(str) },269 PrintSep: "\n",
741 unmodified lines
1011 case "left":1012 opts.position = posLeft1013 case "right":1014 opts.position = posRight1014 case "border":1015 opts.border = true1015 case "rounded", "border":1016 opts.border = tui.BorderRounded1017 case "sharp":1018 opts.border = tui.BorderSharp1019 case "noborder":1017 opts.border = false1020 opts.border = tui.BorderNone1021 default:1022 if sizeRegex.MatchString(token) {1023 opts.size = parseSize(token, 99, "window size")1024 } else if offsetRegex.MatchString(token) {
251 unmodified lines
1276 case "--no-preview":1277 opts.Preview.command = ""1278 case "--preview-window":1279 parsePreviewWindow(&opts.Preview,1277 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"))1280 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:rounded|sharp|noborder][:wrap][:hidden][:+SCROLL[-OFFSET]]"))1281 case "--height":1282 opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))1283 case "--min-height":1284 opts.MinHeight = nextInt(allArgs, &i, "height required: HEIGHT")
206 unmodified lines
modified:src/terminal.go+21 added-7 removed
674 unmodified lines
675 t.window.Close()676 }677 if t.pborder != nil {678 t.pborder.Close()679 }680 if t.pwindow != nil {681 t.pwindow.Close()682 }683684 width := screenWidth - marginInt[1] - marginInt[3]
16 unmodified lines
701 }702 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)703 if previewVisible {704 createPreviewWindow := func(y int, x int, w int, h int) {703 previewBorder := tui.MakeBorderStyle(tui.BorderRounded, t.unicode)704 if !t.preview.border {705 previewBorder = tui.MakeTransparentBorder()705 pwidth := w706 pheight := h707 if t.preview.border != tui.BorderNone {708 previewBorder := tui.MakeBorderStyle(t.preview.border, t.unicode)709 t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)710 pwidth -= 4711 pheight -= 2712 x += 2713 y += 1714 } else {715 previewBorder := tui.MakeTransparentBorder()716 t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)717 pwidth -= 2718 x += 1719 }707 t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)708 pwidth := w - 4720 // ncurses auto-wraps the line when the cursor reaches the right-end of721 // the window. To prevent unintended line-wraps, we use the width one722 // column larger than the desired value.723 if !t.preview.wrap && t.tui.DoesAutoWrap() {724 pwidth += 1725 }715 t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, true, noBorder)726 t.pwindow = t.tui.NewWindow(y, x, pwidth, pheight, true, noBorder)727 }728 switch t.preview.position {729 case posUp:730 pheight := calculateSize(height, t.preview.size, minHeight, 3)
489 unmodified lines
1220 if t.borderShape != tui.BorderNone {1221 windows = append(windows, t.border)1222 }1223 if t.hasPreviewWindow() {1224 if t.pborder != nil {1213 windows = append(windows, t.pborder, t.pwindow)1225 windows = append(windows, t.pborder)1226 }1227 windows = append(windows, t.pwindow)1228 }1229 windows = append(windows, t.window)1230 t.tui.RefreshWindows(windows)1231 }
1127 unmodified lines
modified:CHANGELOG.md+3 added
8 unmodified lines
9 fzf --delimiter : \10 --preview 'bat --style=numbers --color=always --highlight-line {2} {1}' \11 --preview-window +{2}-/212 ```13- Added `--preview-window` option for sharp edges (`--preview-window sharp`)14- Reduced vertical padding around the preview window when `--preview-window15 noborder` is used16170.22.018------19- Added more options for `--bind`
907 unmodified lines