Skip to content
Myr

reader.go

This file

Path

src/reader.go

72 lines · 1.3 KiB · Go

Last changed by

Increase read buffer size to 64KBJunegunn Choibefore adoption3a9532c

History of this file

Take it

The walk stopped after 200 commits: lines older than 7bcf4ef point at it.

Fix test failure - use absolute pathJunegunn Choibefore adoption7bcf4ef

lines 1–36why, one step back
1package fzf
23import (4 "bufio"5 "io"6 "os"78 "github.com/junegunn/fzf/src/util"9)1011// Reader reads from command or standard input12type Reader struct {13 pusher func([]byte) bool14 eventBox *util.EventBox15 delimNil bool16}1718// ReadSource reads data from the default command or from standard input19func (r *Reader) ReadSource() {20 if util.IsTty() {21 cmd := os.Getenv("FZF_DEFAULT_COMMAND")22 if len(cmd) == 0 {23 cmd = defaultCommand24 }25 r.readFromCommand(cmd)26 } else {27 r.readFromStdin()28 }29 r.eventBox.Set(EvtReadFin, nil)30}3132func (r *Reader) feed(src io.Reader) {33 delim := byte('\n')34 if r.delimNil {35 delim = '\000'36 }

Increase read buffer size to 64KBJunegunn Choibefore adoption3a9532c

line 37why, one step back
37 reader := bufio.NewReaderSize(src, readerBufferSize)

Fix test failure - use absolute pathJunegunn Choibefore adoption7bcf4ef

lines 38–60why, one step back
38 for {
39 // ReadBytes returns err != nil if and only if the returned data does not40 // end in delim.41 bytea, err := reader.ReadBytes(delim)42 if len(bytea) > 0 {43 if err == nil {44 bytea = bytea[:len(bytea)-1]45 }46 if r.pusher(bytea) {47 r.eventBox.Set(EvtReadNew, nil)48 }49 }50 if err != nil {51 break52 }53 }54}5556func (r *Reader) readFromStdin() {57 r.feed(os.Stdin)58}5960func (r *Reader) readFromCommand(cmd string) {

Use $SHELL to start $FZF_DEFAULT_COMMAND (#481)Junegunn Choibefore adoptione95d827

line 61why, one step back
61 listCommand := util.ExecCommand(cmd)

Fix test failure - use absolute pathJunegunn Choibefore adoption7bcf4ef

lines 62–72why, one step back
62 out, err := listCommand.StdoutPipe()
63 if err != nil {64 return65 }66 err = listCommand.Start()67 if err != nil {68 return69 }70 defer listCommand.Wait()71 r.feed(out)72}