From e8405f40fe2eb3675f1cb4f69e825eff5f13f269 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 7 May 2024 01:06:42 +0900 Subject: Refactor the code so that fzf can be used as a library (#3769) --- src/reader.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/reader.go') diff --git a/src/reader.go b/src/reader.go index 8fa864e7..6092087e 100644 --- a/src/reader.go +++ b/src/reader.go @@ -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) -- cgit v1.2.3