Skip to content
Myr

Add --print0 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 401a5fd · Browse files · 5 files+27 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Related: #660

Diff stats

5 files+27 added−11 removed

  • other:+27 added−11 removed

5 files+27 added−11 removed

modified:man/man1/fzf.1+6 added
283 unmodified lines
284.RS285e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR286.RE287.TP288.B "--read0"289Read input delimited by ASCII NUL character instead of newline character290.TP291.B "--print0"292Print output delimited by ASCII NUL character instead of newline character293.TP294.B "--sync"295Synchronous search for multi-staged filtering. If specified, fzf will launch296ncurses finder only after the input stream is complete.297
208 unmodified lines
modified:src/core.go+6 added-6 removed
149 unmodified lines
150151 // Filtering mode152 if opts.Filter != nil {153 if opts.PrintQuery {154 fmt.Println(*opts.Filter)154 opts.Printer(*opts.Filter)155 }156157 pattern := patternBuilder([]rune(*opts.Filter))158
4 unmodified lines
163 func(runes []byte) bool {164 item := chunkList.trans(runes, 0)165 if item != nil {166 if result, _, _ := pattern.MatchItem(item, false, slab); result != nil {167 fmt.Println(item.text.ToString())167 opts.Printer(item.text.ToString())168 found = true169 }170 }171 return false
7 unmodified lines
179 merger, _ := matcher.scan(MatchRequest{180 chunks: snapshot,181 pattern: pattern})182 for i := 0; i < merger.Length(); i++ {183 fmt.Println(merger.Get(i).item.AsString(opts.Ansi))183 opts.Printer(merger.Get(i).item.AsString(opts.Ansi))184 found = true185 }186 }187 if found {
65 unmodified lines
253 terminal.startChan <- true254 } else if val.final {255 if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {256 if opts.PrintQuery {257 fmt.Println(opts.Query)257 opts.Printer(opts.Query)258 }259 if len(opts.Expect) > 0 {260 fmt.Println()260 opts.Printer("")261 }262 for i := 0; i < count; i++ {263 fmt.Println(val.Get(i).item.AsString(opts.Ansi))263 opts.Printer(val.Get(i).item.AsString(opts.Ansi))264 }265 if count > 0 {266 os.Exit(exitOk)267 }
19 unmodified lines
modified:src/options.go+6 added
160 unmodified lines
161 Execmap map[int]string162 Preview previewOpts163 PrintQuery bool164 ReadZero bool165 Printer func(string)166 Sync bool167 History *History168 Header []string169 HeaderLines int
36 unmodified lines
206 Execmap: make(map[int]string),207 Preview: previewOpts{"", posRight, sizeSpec{50, true}, false},208 PrintQuery: false,209 ReadZero: false,210 Printer: func(str string) { fmt.Println(str) },211 Sync: false,212 History: nil,213 Header: make([]string, 0),214 HeaderLines: 0,
721 unmodified lines
936 case "--read0":937 opts.ReadZero = true938 case "--no-read0":939 opts.ReadZero = false940 case "--print0":941 opts.Printer = func(str string) { fmt.Print(str, "\x00") }942 case "--no-print0":943 opts.Printer = func(str string) { fmt.Println(str) }944 case "--print-query":945 opts.PrintQuery = true946 case "--no-print-query":947 opts.PrintQuery = false
166 unmodified lines
modified:src/terminal.go+7 added-5 removed
61 unmodified lines
62 progress int63 reading bool64 jumping jumpMode65 jumpLabels string66 printer func(string)67 merger *Merger68 selected map[int32]selectedItem69 reqBox *util.EventBox70 preview previewOpts
198 unmodified lines
269 ansi: opts.Ansi,270 reading: true,271 jumping: jumpDisabled,272 jumpLabels: opts.JumpLabels,273 printer: opts.Printer,274 merger: EmptyMerger,275 selected: make(map[int32]selectedItem),276 reqBox: util.NewEventBox(),277 preview: opts.Preview,
70 unmodified lines
348}349350func (t *Terminal) output() bool {351 if t.printQuery {350 fmt.Println(string(t.input))352 t.printer(string(t.input))353 }354 if len(t.expect) > 0 {353 fmt.Println(t.pressed)355 t.printer(t.pressed)356 }357 found := len(t.selected) > 0358 if !found {359 cnt := t.merger.Length()360 if cnt > 0 && cnt > t.cy {359 fmt.Println(t.current())361 t.printer(t.current())362 found = true363 }364 } else {365 for _, sel := range t.sortSelected() {364 fmt.Println(sel.text)366 t.printer(sel.text)367 }368 }369 return found370}
658 unmodified lines
1029 t.previewTxt = value.(string)1030 t.printPreview()1031 case reqPrintQuery:1032 C.Close()1031 fmt.Println(string(t.input))1033 t.printer(string(t.input))1034 exit(exitOk)1035 case reqQuit:1036 C.Close()1037 exit(exitInterrupt)
381 unmodified lines
modified:CHANGELOG.md+2 added
5 unmodified lines
6- Improved fuzzy search algorithm7 - Added `--algo=[v1|v2]` option so one can still choose the old algorithm8 which values the search performance over the quality of the result9- Advanced scoring criteria10- `--read0` to read input delimited by ASCII NUL character11- `--print0` to print output delimited by ASCII NUL character12130.13.514------15- Memory and performance optimization
433 unmodified lines