summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-08-23 17:05:45 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-08-23 17:05:45 +0900
commit9dc4b40d7a185b0448a15f2e2c6f7c46be738550 (patch)
treef90de393c10d8cdafbb30f97cf478d029ce5f027 /src
parent1cb19dbf65590ffe44b60ac4d5ff7a957de0628f (diff)
Add more preview window options and reduce vertical padding on noborder
Fix #2138 Fix #2029
Diffstat (limited to 'src')
-rw-r--r--src/options.go15
-rw-r--r--src/terminal.go28
2 files changed, 30 insertions, 13 deletions
diff --git a/src/options.go b/src/options.go
index a916e806..38558771 100644
--- a/src/options.go
+++ b/src/options.go
@@ -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":
diff --git a/src/terminal.go b/src/terminal.go
index 2fa13984..b683c459 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -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)