Add --sync option

This commit is contained in:
Junegunn Choi 2015-02-13 12:25:19 +09:00
parent ff09c275d4
commit 6c2ce28d0d
5 changed files with 37 additions and 15 deletions

View File

@ -89,10 +89,12 @@ usage: fzf [options]
-0, --exit-0 Exit immediately when there's no match -0, --exit-0 Exit immediately when there's no match
-f, --filter=STR Filter mode. Do not start interactive finder. -f, --filter=STR Filter mode. Do not start interactive finder.
--print-query Print query as the first line --print-query Print query as the first line
--sync Synchronous search for multi-staged filtering
(e.g. 'fzf --multi | fzf --sync')
Environment variables Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty 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')
``` ```
fzf will launch curses-based finder, read the list from STDIN, and write the fzf will launch curses-based finder, read the list from STDIN, and write the

View File

@ -5,7 +5,7 @@ import (
) )
// Current version // Current version
const Version = "0.9.2" const Version = "0.9.3"
// fzf events // fzf events
const ( const (

View File

@ -110,19 +110,8 @@ func Run(options *Options) {
} }
pattern := patternBuilder([]rune(patternString)) pattern := patternBuilder([]rune(patternString))
looping := true
eventBox.Unwatch(EvtReadNew) eventBox.Unwatch(EvtReadNew)
for looping { eventBox.WaitFor(EvtReadFin)
eventBox.Wait(func(events *util.Events) {
for evt := range *events {
switch evt {
case EvtReadFin:
looping = false
return
}
}
})
}
snapshot, _ := chunkList.Snapshot() snapshot, _ := chunkList.Snapshot()
merger, cancelled := matcher.scan(MatchRequest{ 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 interactive
go matcher.Loop() go matcher.Loop()

View File

@ -41,10 +41,12 @@ const usage = `usage: fzf [options]
-0, --exit-0 Exit immediately when there's no match -0, --exit-0 Exit immediately when there's no match
-f, --filter=STR Filter mode. Do not start interactive finder. -f, --filter=STR Filter mode. Do not start interactive finder.
--print-query Print query as the first line --print-query Print query as the first line
--sync Synchronous search for multi-staged filtering
(e.g. 'fzf --multi | fzf --sync')
Environment variables Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty 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 Exit0 bool
Filter *string Filter *string
PrintQuery bool PrintQuery bool
Sync bool
Version bool Version bool
} }
@ -111,6 +114,7 @@ func defaultOptions() *Options {
Exit0: false, Exit0: false,
Filter: nil, Filter: nil,
PrintQuery: false, PrintQuery: false,
Sync: false,
Version: false} Version: false}
} }
@ -244,6 +248,12 @@ func parseOptions(opts *Options, allArgs []string) {
opts.PrintQuery = false opts.PrintQuery = false
case "--prompt": case "--prompt":
opts.Prompt = nextString(allArgs, &i, "prompt string required") 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": case "--version":
opts.Version = true opts.Version = true
default: default:

View File

@ -78,3 +78,18 @@ func (b *EventBox) Unwatch(events ...EventType) {
b.ignore[event] = true 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
}
}
})
}
}