summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-02-13 12:25:19 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-02-13 12:25:19 +0900
commit6c2ce28d0dca357195d267406b90e705c35312d5 (patch)
tree2f146a8b81b2fd1cb53fb512f3afb86ab948eae5 /src
parentff09c275d4abf21920526f3134869bda0a7464d5 (diff)
Add `--sync` option
Diffstat (limited to 'src')
-rw-r--r--src/constants.go2
-rw-r--r--src/core.go19
-rw-r--r--src/options.go12
-rw-r--r--src/util/eventbox.go15
4 files changed, 34 insertions, 14 deletions
diff --git a/src/constants.go b/src/constants.go
index 9b527431..7d542234 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -5,7 +5,7 @@ import (
)
// Current version
-const Version = "0.9.2"
+const Version = "0.9.3"
// fzf events
const (
diff --git a/src/core.go b/src/core.go
index ee904135..ab61a6e7 100644
--- a/src/core.go
+++ b/src/core.go
@@ -110,19 +110,8 @@ func Run(options *Options) {
}
pattern := patternBuilder([]rune(patternString))
- looping := true
eventBox.Unwatch(EvtReadNew)
- for looping {
- eventBox.Wait(func(events *util.Events) {
- for evt := range *events {
- switch evt {
- case EvtReadFin:
- looping = false
- return
- }
- }
- })
- }
+ eventBox.WaitFor(EvtReadFin)
snapshot, _ := chunkList.Snapshot()
merger, cancelled := matcher.scan(MatchRequest{
@@ -142,6 +131,12 @@ func Run(options *Options) {
}
}
+ // Synchronous search
+ if opts.Sync {
+ eventBox.Unwatch(EvtReadNew)
+ eventBox.WaitFor(EvtReadFin)
+ }
+
// Go interactive
go matcher.Loop()
diff --git a/src/options.go b/src/options.go
index b11328e5..c426e777 100644
--- a/src/options.go
+++ b/src/options.go
@@ -41,10 +41,12 @@ const usage = `usage: fzf [options]
-0, --exit-0 Exit immediately when there's no match
-f, --filter=STR Filter mode. Do not start interactive finder.
--print-query Print query as the first line
+ --sync Synchronous search for multi-staged filtering
+ (e.g. 'fzf --multi | fzf --sync')
Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty
- FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m")
+ FZF_DEFAULT_OPTS Defaults options. (e.g. '-x -m')
`
@@ -88,6 +90,7 @@ type Options struct {
Exit0 bool
Filter *string
PrintQuery bool
+ Sync bool
Version bool
}
@@ -111,6 +114,7 @@ func defaultOptions() *Options {
Exit0: false,
Filter: nil,
PrintQuery: false,
+ Sync: false,
Version: false}
}
@@ -244,6 +248,12 @@ func parseOptions(opts *Options, allArgs []string) {
opts.PrintQuery = false
case "--prompt":
opts.Prompt = nextString(allArgs, &i, "prompt string required")
+ case "--sync":
+ opts.Sync = true
+ case "--no-sync":
+ opts.Sync = false
+ case "--async":
+ opts.Sync = false
case "--version":
opts.Version = true
default:
diff --git a/src/util/eventbox.go b/src/util/eventbox.go
index 568ad9f7..a5821eab 100644
--- a/src/util/eventbox.go
+++ b/src/util/eventbox.go
@@ -78,3 +78,18 @@ func (b *EventBox) Unwatch(events ...EventType) {
b.ignore[event] = true
}
}
+
+func (b *EventBox) WaitFor(event EventType) {
+ looping := true
+ for looping {
+ b.Wait(func(events *Events) {
+ for evt := range *events {
+ switch evt {
+ case event:
+ looping = false
+ return
+ }
+ }
+ })
+ }
+}