summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-10-11 01:51:39 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-10-11 01:54:39 +0900
commit3248153d9f928710103073de0752145ffb95a631 (patch)
tree5ea994a958e94b1859ed91e3067abf16f04d0e5e /src
parent246b9f313085fac4c9c84cf8bf55cc8a8fc29482 (diff)
downloadfzf-3248153d9f928710103073de0752145ffb95a631.tar.gz
Add --preview-window=default for resetting the options
Diffstat (limited to 'src')
-rw-r--r--src/options.go11
-rw-r--r--src/options_test.go7
2 files changed, 16 insertions, 2 deletions
diff --git a/src/options.go b/src/options.go
index 51e5001c..ea6e420e 100644
--- a/src/options.go
+++ b/src/options.go
@@ -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
@@ -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,
@@ -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) },
@@ -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":
@@ -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":
diff --git a/src/options_test.go b/src/options_test.go
index aae8eedc..78207275 100644
--- a/src/options_test.go
+++ b/src/options_test.go
@@ -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) {