summaryrefslogtreecommitdiff
path: root/src/reader.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-05-07 01:06:42 +0900
committerGitHub <noreply@github.com>2024-05-07 01:06:42 +0900
commite8405f40fe2eb3675f1cb4f69e825eff5f13f269 (patch)
treec917367f1f0098939f9cdf7376a2a135907024fc /src/reader.go
parent065b9e6fb2ce3e6e50ff423c3786989afa04ee14 (diff)
downloadfzf-e8405f40fe2eb3675f1cb4f69e825eff5f13f269.tar.gz
Refactor the code so that fzf can be used as a library (#3769)
Diffstat (limited to 'src/reader.go')
-rw-r--r--src/reader.go19
1 files changed, 17 insertions, 2 deletions
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)