Skip to content

Commit

Permalink
Add --preview-window=default for resetting the options
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Oct 10, 2020
1 parent 246b9f3 commit 3248153
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
- `nocycle`
- `nohidden`
- `nowrap`
- `default`

0.23.0
------
Expand Down
4 changes: 3 additions & 1 deletion man/man1/fzf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.RE
.TP
.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:[no]wrap][:[no]cycle][:[no]hidden][:+SCROLL[-OFFSET]]"
.BI "--preview-window=" "[POSITION][:SIZE[%]][:rounded|sharp|noborder][:[no]wrap][:[no]cycle][:[no]hidden][:+SCROLL[-OFFSET]][:default]"

.RS
.B POSITION: (default: right)
Expand Down Expand Up @@ -411,6 +411,8 @@ for adjusting the base offset so that you can see the text above it. It should
be given as a numeric integer (\fB-INTEGER\fR), or as a denominator form
(\fB-/INTEGER\fR) for specifying a fraction of the preview window height.

\fBdefault\fR resets all options previously set to the default.

.RS
e.g.
\fB# Non-default scroll window positions and sizes
Expand Down
11 changes: 9 additions & 2 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const usage = `usage: fzf [options]
[:[no]wrap][:[no]cycle][:[no]hidden]
[:rounded|sharp|noborder]
[:+SCROLL[-OFFSET]]
[:default]
Scripting
-q, --query=STR Start the finder with the given query
Expand Down Expand Up @@ -226,6 +227,10 @@ type Options struct {
Version bool
}

func defaultPreviewOpts(command string) previewOpts {
return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, tui.BorderRounded}
}

func defaultOptions() *Options {
return &Options{
Fuzzy: true,
Expand Down Expand Up @@ -265,7 +270,7 @@ func defaultOptions() *Options {
ToggleSort: false,
Expect: make(map[int]string),
Keymap: make(map[int][]action),
Preview: previewOpts{"", posRight, sizeSpec{50, true}, "", false, false, false, tui.BorderRounded},
Preview: defaultPreviewOpts(""),
PrintQuery: false,
ReadZero: false,
Printer: func(str string) { fmt.Println(str) },
Expand Down Expand Up @@ -1001,6 +1006,8 @@ func parsePreviewWindow(opts *previewOpts, input string) {
for _, token := range tokens {
switch token {
case "":
case "default":
*opts = defaultPreviewOpts(opts.command)
case "hidden":
opts.hidden = true
case "nohidden":
Expand Down Expand Up @@ -1278,7 +1285,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[%]][:rounded|sharp|noborder][:wrap][:cycle][:hidden][:+SCROLL[-OFFSET]]"))
nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:rounded|sharp|noborder][:wrap][:cycle][:hidden][:+SCROLL[-OFFSET]][:default]"))
case "--height":
opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))
case "--min-height":
Expand Down
7 changes: 7 additions & 0 deletions src/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ func TestPreviewOpts(t *testing.T) {
opts.Preview.size.size == 15) {
t.Error(opts.Preview)
}
opts = optsFor("--preview=foo", "--preview-window=up", "--preview-window=default:70%")
if !(opts.Preview.command == "foo" &&
opts.Preview.position == posRight &&
opts.Preview.size.percent == true &&
opts.Preview.size.size == 70) {
t.Error(opts.Preview)
}
}

func TestAdditiveExpect(t *testing.T) {
Expand Down

0 comments on commit 3248153

Please sign in to comment.