Add `--sync` option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent ff09c27 · Browse files · 5 files·+37 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+37 added−15 removed
- other:+37 added−15 removed
Provenance
- Commit
6c2ce28- Tree
2f146a8- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
ff09c27
5 files changed+37 added−15 removed
modified:src/util/eventbox.go+15 added
76 unmodified lines77 for _, event := range events {78 b.ignore[event] = true79 }80 }81+82+func (b *EventBox) WaitFor(event EventType) {83+ looping := true84+ for looping {85+ b.Wait(func(events *Events) {86+ for evt := range *events {87+ switch evt {88+ case event:89+ looping = false90+ return91+ }92+ }93+ })94+ }95+}modified:src/constants.go+1 added-1 removed
3 unmodified lines4 "github.com/junegunn/fzf/src/util"5 )6 7 // Current version8-const Version = "0.9.2"8+const Version = "0.9.3"9 10 // fzf events11 const (12 EvtReadNew util.EventType = iota6 unmodified linesmodified:src/core.go+7 added-12 removed
108 unmodified lines109 patternString = opts.Query110 }111 pattern := patternBuilder([]rune(patternString))112 113- looping := true113 eventBox.Unwatch(EvtReadNew)115- for looping {116- eventBox.Wait(func(events *util.Events) {117- for evt := range *events {118- switch evt {119- case EvtReadFin:120- looping = false121- return122- }123- }124- })125- }114+ eventBox.WaitFor(EvtReadFin)115 116 snapshot, _ := chunkList.Snapshot()117 merger, cancelled := matcher.scan(MatchRequest{118 chunks: snapshot,11 unmodified lines130 os.Exit(0)131 }132 }133 134+ // Synchronous search135+ if opts.Sync {136+ eventBox.Unwatch(EvtReadNew)137+ eventBox.WaitFor(EvtReadFin)138+ }139+140 // Go interactive141 go matcher.Loop()142 143 // Terminal I/O48 unmodified linesmodified:src/options.go+11 added-1 removed
39 unmodified lines40 -1, --select-1 Automatically select the only match41 -0, --exit-0 Exit immediately when there's no match42 -f, --filter=STR Filter mode. Do not start interactive finder.43 --print-query Print query as the first line44+ --sync Synchronous search for multi-staged filtering45+ (e.g. 'fzf --multi | fzf --sync')46 47 Environment variables48 FZF_DEFAULT_COMMAND Default command to use when input is tty47- FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m")49+ FZF_DEFAULT_OPTS Defaults options. (e.g. '-x -m')50 51 `52 53 // Mode denotes the current search mode35 unmodified lines89 Select1 bool90 Exit0 bool91 Filter *string92 PrintQuery bool93+ Sync bool94 Version bool95 }96 97 func defaultOptions() *Options {15 unmodified lines113 Select1: false,114 Exit0: false,115 Filter: nil,116 PrintQuery: false,117+ Sync: false,118 Version: false}119 }120 121 func help(ok int) {125 unmodified lines247 case "--no-print-query":248 opts.PrintQuery = false249 case "--prompt":250 opts.Prompt = nextString(allArgs, &i, "prompt string required")251+ case "--sync":252+ opts.Sync = true253+ case "--no-sync":254+ opts.Sync = false255+ case "--async":256+ opts.Sync = false257 case "--version":258 opts.Version = true259 default:260 if match, value := optString(arg, "-q|--query="); match {43 unmodified linesmodified:README.md+3 added-1 removed
87 unmodified lines88 -1, --select-1 Automatically select the only match89 -0, --exit-0 Exit immediately when there's no match90 -f, --filter=STR Filter mode. Do not start interactive finder.91 --print-query Print query as the first line92+ --sync Synchronous search for multi-staged filtering93+ (e.g. 'fzf --multi | fzf --sync')94 95 Environment variables96 FZF_DEFAULT_COMMAND Default command to use when input is tty95- FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m")97+ FZF_DEFAULT_OPTS Defaults options. (e.g. '-x -m')98 ```99 100 fzf will launch curses-based finder, read the list from STDIN, and write the101 selected item to STDOUT.445 unmodified lines