reader.go
This file
Path
src/reader.go
80 lines · 1.6 KiB · Go
Last changed by
Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
History of this fileTake it
The walk stopped after 200 commits: lines older than 0541c0d point at it.
Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 1–19why, one step back1package fzf23import (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() {Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 20why, one step back20 var success boolUse relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 21–25why, one step back21 if util.IsTty() {22 cmd := os.Getenv("FZF_DEFAULT_COMMAND")23 if len(cmd) == 0 {24 cmd = defaultCommand25 }Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 26why, one step back26 success = r.readFromCommand(cmd)Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
line 27why, one step back27 } else {Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 28why, one step back28 success = r.readFromStdin()Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
line 29why, one step back29 }Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 30why, one step back30 r.eventBox.Set(EvtReadFin, success)Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 31–42why, one step back31}3233func (r *Reader) feed(src io.Reader) {34 delim := byte('\n')35 if r.delimNil {36 delim = '\000'37 }38 reader := bufio.NewReaderSize(src, readerBufferSize)39 for {40 // ReadBytes returns err != nil if and only if the returned data does not41 // end in delim.42 bytea, err := reader.ReadBytes(delim)Implement tcell-based rendererMichael Kelleybefore adoption26895da
line 43why, one step back43 byteaLen := len(bytea)Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 44–45why, one step back44 if len(bytea) > 0 {45 if err == nil {Implement tcell-based rendererMichael Kelleybefore adoption26895da
line 46why, one step back46 // get rid of carriage return if under Windows:Fix issues in tcell renderer and Windows buildJunegunn Choibefore adoption898d8d9
line 47why, one step back47 if util.IsWindows() && byteaLen >= 2 && bytea[byteaLen-2] == byte('\r') {Implement tcell-based rendererMichael Kelleybefore adoption26895da
lines 48–51why, one step back48 bytea = bytea[:byteaLen-2]49 } else {50 bytea = bytea[:byteaLen-1]51 }Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 52–53why, one step back52 }53 if r.pusher(bytea) {Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 54why, one step back54 r.eventBox.Set(EvtReadNew, true)Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 55–62why, one step back55 }56 }57 if err != nil {58 break59 }60 }61}62Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 63why, one step back63func (r *Reader) readFromStdin() bool {Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
line 64why, one step back64 r.feed(os.Stdin)Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 65why, one step back65 return trueUse relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 66–67why, one step back66}67Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 68why, one step back68func (r *Reader) readFromCommand(cmd string) bool {Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 69–71why, one step back69 listCommand := util.ExecCommand(cmd)70 out, err := listCommand.StdoutPipe()71 if err != nil {Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 72why, one step back72 return falseUse relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 73–75why, one step back73 }74 err = listCommand.Start()75 if err != nil {Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 76why, one step back76 return falseUse relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
lines 77–78why, one step back77 }78 r.feed(out)Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0
line 79why, one step back79 return listCommand.Wait() == nilUse relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d
line 80why, one step back80}