reader.go
This file
Path
src/reader.go
73 lines · 1.3 KiB · Go
Last changed by
Performance fix - unnecessary rune convertion on --ansiJunegunn Choibefore adoptione13bafc
History of this fileTake it
The walk stopped after 200 commits: lines older than ed8202e point at it.
[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
lines 1–13why, one step back1package fzf23import (4 "bufio"5 "io"6 "os"7 "os/exec"89 "github.com/junegunn/fzf/src/util"10)1112// Reader reads from command or standard input13type Reader struct {Performance fix - unnecessary rune convertion on --ansiJunegunn Choibefore adoptione13bafc
line 14why, one step back14 pusher func([]byte) bool[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
line 15why, one step back15 eventBox *util.EventBoxMerge branch 'dullgiulio-121-accept-nil-input'Junegunn Choibefore adoption97f433a
line 16why, one step back16 delimNil bool[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
lines 17–33why, one step back17}1819// ReadSource reads data from the default command or from standard input20func (r *Reader) ReadSource() {21 if util.IsTty() {22 cmd := os.Getenv("FZF_DEFAULT_COMMAND")23 if len(cmd) == 0 {24 cmd = defaultCommand25 }26 r.readFromCommand(cmd)27 } else {28 r.readFromStdin()29 }30 r.eventBox.Set(EvtReadFin, nil)31}3233func (r *Reader) feed(src io.Reader) {Merge branch 'dullgiulio-121-accept-nil-input'Junegunn Choibefore adoption97f433a
lines 34–37why, one step back34 delim := byte('\n')35 if r.delimNil {36 delim = '\000'37 }Fix #248 - Premature termination of Reader on long inputJunegunn Choibefore adoptionb00bcf5
line 38why, one step back38 reader := bufio.NewReader(src)Merge branch 'dullgiulio-121-accept-nil-input'Junegunn Choibefore adoption97f433a
line 39why, one step back39 for {Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
lines 40–43why, one step back40 // ReadBytes returns err != nil if and only if the returned data does not41 // end in delim.42 bytea, err := reader.ReadBytes(delim)43 if len(bytea) > 0 {Merge branch 'dullgiulio-121-accept-nil-input'Junegunn Choibefore adoption97f433a
line 44why, one step back44 if err == nil {Performance fix - unnecessary rune convertion on --ansiJunegunn Choibefore adoptione13bafc
line 45why, one step back45 bytea = bytea[:len(bytea)-1]Fix #248 - Premature termination of Reader on long inputJunegunn Choibefore adoptionb00bcf5
line 46why, one step back46 }Performance fix - unnecessary rune convertion on --ansiJunegunn Choibefore adoptione13bafc
line 47why, one step back47 if r.pusher(bytea) {Add --header-lines optionJunegunn Choibefore adoptionf469c25
lines 48–49why, one step back48 r.eventBox.Set(EvtReadNew, nil)49 }Merge branch 'dullgiulio-121-accept-nil-input'Junegunn Choibefore adoption97f433a
lines 50–52why, one step back50 }51 if err != nil {52 break[bash-completion] Ignore 0.0.0.0Junegunn Choibefore adoptioned8202e
lines 53–73why, one step back53 }54 }55}5657func (r *Reader) readFromStdin() {58 r.feed(os.Stdin)59}6061func (r *Reader) readFromCommand(cmd string) {62 listCommand := exec.Command("sh", "-c", cmd)63 out, err := listCommand.StdoutPipe()64 if err != nil {65 return66 }67 err = listCommand.Start()68 if err != nil {69 return70 }71 defer listCommand.Wait()72 r.feed(out)73}