Skip to content
Myr

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 file

Take 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 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() {

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 20why, one step back
20 var success bool

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 21–25why, one step back
21 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 back
26 success = r.readFromCommand(cmd)

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

line 27why, one step back
27 } else {

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 28why, one step back
28 success = r.readFromStdin()

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

line 29why, one step back
29 }

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 30why, one step back
30 r.eventBox.Set(EvtReadFin, success)

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 31–42why, one step back
31}
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 back
43 byteaLen := len(bytea)

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 44–45why, one step back
44 if len(bytea) > 0 {
45 if err == nil {

Implement tcell-based rendererMichael Kelleybefore adoption26895da

line 46why, one step back
46 // get rid of carriage return if under Windows:

Fix issues in tcell renderer and Windows buildJunegunn Choibefore adoption898d8d9

line 47why, one step back
47 if util.IsWindows() && byteaLen >= 2 && bytea[byteaLen-2] == byte('\r') {

Implement tcell-based rendererMichael Kelleybefore adoption26895da

lines 48–51why, one step back
48 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 back
52 }
53 if r.pusher(bytea) {

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 54why, one step back
54 r.eventBox.Set(EvtReadNew, true)

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 55–62why, one step back
55 }
56 }57 if err != nil {58 break59 }60 }61}62

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 63why, one step back
63func (r *Reader) readFromStdin() bool {

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

line 64why, one step back
64 r.feed(os.Stdin)

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 65why, one step back
65 return true

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 66–67why, one step back
66}
67

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 68why, one step back
68func (r *Reader) readFromCommand(cmd string) bool {

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 69–71why, one step back
69 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 back
72 return false

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 73–75why, one step back
73 }
74 err = listCommand.Start()75 if err != nil {

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 76why, one step back
76 return false

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

lines 77–78why, one step back
77 }
78 r.feed(out)

Print [ERROR] on info line when the default command failedJunegunn Choibefore adoption07ef2b0

line 79why, one step back
79 return listCommand.Wait() == nil

Use relative position instead of absolute distance for --tiebreak=endJunegunn Choibefore adoption0541c0d

line 80why, one step back
80}