mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 15:53:39 -05:00
Add more preview window options and reduce vertical padding on noborder
Fix #2138 Fix #2029
This commit is contained in:
@@ -81,6 +81,7 @@ const usage = `usage: fzf [options]
|
||||
--preview=COMMAND Command to preview highlighted line ({})
|
||||
--preview-window=OPT Preview window layout (default: right:50%)
|
||||
[up|down|left|right][:SIZE[%]][:wrap][:hidden][:+SCROLL[-OFFSET]]
|
||||
[:rounded|sharp|noborder]
|
||||
|
||||
Scripting
|
||||
-q, --query=STR Start the finder with the given query
|
||||
@@ -162,7 +163,7 @@ type previewOpts struct {
|
||||
scroll string
|
||||
hidden bool
|
||||
wrap bool
|
||||
border bool
|
||||
border tui.BorderShape
|
||||
}
|
||||
|
||||
// Options stores the values of command-line options
|
||||
@@ -261,7 +262,7 @@ func defaultOptions() *Options {
|
||||
ToggleSort: false,
|
||||
Expect: make(map[int]string),
|
||||
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,
|
||||
ReadZero: false,
|
||||
Printer: func(str string) { fmt.Println(str) },
|
||||
@@ -1011,10 +1012,12 @@ func parsePreviewWindow(opts *previewOpts, input string) {
|
||||
opts.position = posLeft
|
||||
case "right":
|
||||
opts.position = posRight
|
||||
case "border":
|
||||
opts.border = true
|
||||
case "rounded", "border":
|
||||
opts.border = tui.BorderRounded
|
||||
case "sharp":
|
||||
opts.border = tui.BorderSharp
|
||||
case "noborder":
|
||||
opts.border = false
|
||||
opts.border = tui.BorderNone
|
||||
default:
|
||||
if sizeRegex.MatchString(token) {
|
||||
opts.size = parseSize(token, 99, "window size")
|
||||
@@ -1274,7 +1277,7 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
opts.Preview.command = ""
|
||||
case "--preview-window":
|
||||
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":
|
||||
opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))
|
||||
case "--min-height":
|
||||
|
||||
@@ -676,6 +676,8 @@ func (t *Terminal) resizeWindows() {
|
||||
}
|
||||
if t.pborder != nil {
|
||||
t.pborder.Close()
|
||||
}
|
||||
if t.pwindow != nil {
|
||||
t.pwindow.Close()
|
||||
}
|
||||
|
||||
@@ -700,19 +702,28 @@ func (t *Terminal) resizeWindows() {
|
||||
noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)
|
||||
if previewVisible {
|
||||
createPreviewWindow := func(y int, x int, w int, h int) {
|
||||
previewBorder := tui.MakeBorderStyle(tui.BorderRounded, t.unicode)
|
||||
if !t.preview.border {
|
||||
previewBorder = tui.MakeTransparentBorder()
|
||||
pwidth := w
|
||||
pheight := h
|
||||
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
|
||||
// the window. To prevent unintended line-wraps, we use the width one
|
||||
// column larger than the desired value.
|
||||
if !t.preview.wrap && t.tui.DoesAutoWrap() {
|
||||
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 {
|
||||
case posUp:
|
||||
@@ -1210,7 +1221,10 @@ func (t *Terminal) refresh() {
|
||||
windows = append(windows, t.border)
|
||||
}
|
||||
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)
|
||||
t.tui.RefreshWindows(windows)
|
||||
|
||||
Reference in New Issue
Block a user