2
0
mirror of https://github.com/junegunn/fzf synced 2024-11-18 09:28:40 +00:00

Add --preview-window noborder option to disable preview border

Close #1699
This commit is contained in:
Junegunn Choi 2019-11-15 11:37:52 +09:00
parent d2fa470165
commit e24299239e
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
4 changed files with 16 additions and 4 deletions

View File

@ -43,6 +43,8 @@ CHANGELOG
- `--info=default` - `--info=default`
- `--info=inline` (same as old `--inline-info`) - `--info=inline` (same as old `--inline-info`)
- `--info=hidden` - `--info=hidden`
- Preview window border can be disabled by adding `noborder` to
`--preview-window`.
- When you transform the input with `--with-nth`, the trailing white spaces - When you transform the input with `--with-nth`, the trailing white spaces
are removed. are removed.
- `ctrl-\`, `ctrl-]`, `ctrl-^`, and `ctrl-/` can now be used with `--bind` - `ctrl-\`, `ctrl-]`, `ctrl-^`, and `ctrl-/` can now be used with `--bind`

View File

@ -361,8 +361,8 @@ 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[%]][:wrap][:hidden]" .BI "--preview-window=" "[POSITION][:SIZE[%]][:noborder][:wrap][:hidden]"
Determine the layout of the preview window. If the argument ends with 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.
Line wrap can be enabled with \fB:wrap\fR flag. Line wrap can be enabled with \fB:wrap\fR flag.

View File

@ -156,6 +156,7 @@ type previewOpts struct {
size sizeSpec size sizeSpec
hidden bool hidden bool
wrap bool wrap bool
border bool
} }
// Options stores the values of command-line options // Options stores the values of command-line options
@ -248,7 +249,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}, Preview: previewOpts{"", posRight, sizeSpec{50, true}, false, false, true},
PrintQuery: false, PrintQuery: false,
ReadZero: false, ReadZero: false,
Printer: func(str string) { fmt.Println(str) }, Printer: func(str string) { fmt.Println(str) },
@ -937,6 +938,7 @@ func parsePreviewWindow(opts *previewOpts, input string) {
sizeRegex := regexp.MustCompile("^[0-9]+%?$") sizeRegex := regexp.MustCompile("^[0-9]+%?$")
for _, token := range tokens { for _, token := range tokens {
switch token { switch token {
case "":
case "hidden": case "hidden":
opts.hidden = true opts.hidden = true
case "wrap": case "wrap":
@ -949,6 +951,10 @@ func parsePreviewWindow(opts *previewOpts, input string) {
opts.position = posLeft opts.position = posLeft
case "right": case "right":
opts.position = posRight opts.position = posRight
case "border":
opts.border = true
case "noborder":
opts.border = false
default: default:
if sizeRegex.MatchString(token) { if sizeRegex.MatchString(token) {
opts.size = parseSize(token, 99, "window size") opts.size = parseSize(token, 99, "window size")

View File

@ -624,7 +624,11 @@ 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) {
t.pborder = t.tui.NewWindow(y, x, w, h, tui.MakeBorderStyle(tui.BorderAround, t.unicode)) previewBorder := noBorder
if t.preview.border {
previewBorder = tui.MakeBorderStyle(tui.BorderAround, t.unicode)
}
t.pborder = t.tui.NewWindow(y, x, w, h, previewBorder)
pwidth := w - 4 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