mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-18 00:03:39 -05:00
Refactor the code so that fzf can be used as a library (#3769)
This commit is contained in:
@@ -93,11 +93,26 @@ func (r *Reader) restart(command string, environ []string) {
|
||||
r.fin(success)
|
||||
}
|
||||
|
||||
func (r *Reader) readChannel(inputChan chan string) bool {
|
||||
for {
|
||||
item, more := <-inputChan
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
if r.pusher([]byte(item)) {
|
||||
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ReadSource reads data from the default command or from standard input
|
||||
func (r *Reader) ReadSource(root string, opts walkerOpts, ignores []string) {
|
||||
func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string) {
|
||||
r.startEventPoller()
|
||||
var success bool
|
||||
if util.IsTty() {
|
||||
if inputChan != nil {
|
||||
success = r.readChannel(inputChan)
|
||||
} else if util.IsTty() {
|
||||
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
|
||||
if len(cmd) == 0 {
|
||||
success = r.readFiles(root, opts, ignores)
|
||||
|
||||
Reference in New Issue
Block a user