Merge branch 'dullgiulio-121-accept-nil-input'
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 · parents 0be4cea, 45a3655 · Browse files · 4 files·+29 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+29 added−23 removed
- tests:+7 added−0 removed
- other:+22 added−23 removed
Provenance
- Commit
97f433a- Tree
dd4f6fd- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent 1
0be4cea- Parent 2
45a3655
4 files changed+29 added−23 removed
modified:src/core.go+2 added-2 removed
111 unmodified lines112 113 // Reader114 streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync115 if !streamingFilter {116- reader := Reader{func(str string) { chunkList.Push(str) }, eventBox}116+ reader := Reader{func(str string) { chunkList.Push(str) }, eventBox, opts.ReadZero}117 go reader.ReadSource()118 }119 120 // Matcher17 unmodified lines138 item := chunkList.trans(&str, 0)139 if pattern.MatchItem(item) {140 fmt.Println(*item.text)141 }142- }, eventBox}142+ }, eventBox, opts.ReadZero}143 reader.ReadSource()144 } else {145 eventBox.Unwatch(EvtReadNew)146 eventBox.WaitFor(EvtReadFin)100 unmodified linesmodified:src/options.go+5 added
48 unmodified lines49 -q, --query=STR Start the finder with the given query50 -1, --select-1 Automatically select the only match51 -0, --exit-0 Exit immediately when there's no match52 -f, --filter=STR Filter mode. Do not start interactive finder.53+ --null Read null-byte separated strings from input54 --print-query Print query as the first line55 --expect=KEYS Comma-separated list of keys to complete fzf56 --sync Synchronous search for multi-staged filtering57 59 unmodified lines117 ToggleSort bool118 Expect []int119 Keymap map[int]actionType120 PrintQuery bool121+ ReadZero bool122 Sync bool123 Version bool124 }125 30 unmodified lines156 ToggleSort: false,157 Expect: []int{},158 Keymap: defaultKeymap(),159 PrintQuery: false,160+ ReadZero: false,161 Sync: false,162 Version: false}163 }164 362 unmodified lines527 case "-0", "--exit-0":528 opts.Exit0 = true529 case "+0", "--no-exit-0":530 opts.Exit0 = false531+ case "--null":532+ opts.ReadZero = true533 case "--print-query":534 opts.PrintQuery = true535 case "--no-print-query":536 opts.PrintQuery = false66 unmodified linesmodified:src/reader.go+15 added-21 removed
11 unmodified lines12 // Reader reads from command or standard input13 type Reader struct {14 pusher func(string)15 eventBox *util.EventBox16+ delimNil bool17 }18 19 // ReadSource reads data from the default command or from standard input20 func (r *Reader) ReadSource() {9 unmodified lines30 r.eventBox.Set(EvtReadFin, nil)31 }32 33 func (r *Reader) feed(src io.Reader) {34+ delim := byte('\n')35+ if r.delimNil {36+ delim = '\000'37+ }38 reader := bufio.NewReader(src)34- eof := false35-Loop:36- for !eof {37- buf := []byte{}38- iter := 0 // TODO: max size?39- for {40- // "ReadLine either returns a non-nil line or it returns an error, never both"41- line, isPrefix, err := reader.ReadLine()42- eof = err == io.EOF43- if eof {44- break45- } else if err != nil {46- break Loop39+ for {40+ line, err := reader.ReadString(delim)41+ if line != "" {42+ // "ReadString returns err != nil if and only if the returned data does not end in delim."43+ if err == nil {44+ line = line[:len(line)-1]45 }48- iter++49- buf = append(buf, line...)50- if !isPrefix {51- break52- }53- }54- if iter > 0 {55- r.pusher(string(buf))46+ r.pusher(line)47 r.eventBox.Set(EvtReadNew, nil)48 }49+ if err != nil {50+ break51+ }52 }53 }54 55 func (r *Reader) readFromStdin() {16 unmodified linesmodified:test/test_go.rb+7 added
534 unmodified lines535 assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp536 ensure537 File.unlink tempname538 end539+540+ def test_null541+ lines = `find .`.split($/)542+ assert_equal lines.last, `find . | #{FZF} -e -f "^#{lines.last}$"`.chomp543+ assert_equal lines.last, `find . -print0 | #{FZF} --null -e -f "^#{lines.last}$"`.chomp544+ end545+546 private547 def writelines path, lines548 File.unlink path while File.exists? path549 File.open(path, 'w') { |f| f << lines.join($/) }208 unmodified lines