summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-06-24 17:05:53 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-06-24 17:05:53 +0900
commit5b5283378571cca88a993630db3307319d2cb56d (patch)
tree65ab3b3c2cc5b01b93be50e5400c3f466be596db /src
parent15257680948bda849747465ac4edf5e9d90f2a52 (diff)
downloadfzf-5b5283378571cca88a993630db3307319d2cb56d.tar.gz
Do not start the initial reader if 'reload*' is bound to 'start'
Diffstat (limited to 'src')
-rw-r--r--src/constants.go1
-rw-r--r--src/core.go17
-rw-r--r--src/options.go15
3 files changed, 30 insertions, 3 deletions
diff --git a/src/constants.go b/src/constants.go
index 980e1583..29874b29 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -58,6 +58,7 @@ const (
const (
EvtReadNew util.EventType = iota
EvtReadFin
+ EvtReadNone
EvtSearchNew
EvtSearchProgress
EvtSearchFin
diff --git a/src/core.go b/src/core.go
index 87629b78..caada27c 100644
--- a/src/core.go
+++ b/src/core.go
@@ -147,13 +147,20 @@ func Run(opts *Options) (int, error) {
executor := util.NewExecutor(opts.WithShell)
// Reader
+ reloadOnStart := opts.reloadOnStart()
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
var reader *Reader
if !streamingFilter {
reader = NewReader(func(data []byte) bool {
return chunkList.Push(data)
}, eventBox, executor, opts.ReadZero, opts.Filter == nil)
- go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)
+
+ if reloadOnStart {
+ // reload or reload-sync action is bound to 'start' event, no need to start the reader
+ eventBox.Set(EvtReadNone, nil)
+ } else {
+ go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)
+ }
}
// Matcher
@@ -227,7 +234,8 @@ func Run(opts *Options) (int, error) {
}
// Synchronous search
- if opts.Sync {
+ sync := opts.Sync && !reloadOnStart
+ if sync {
eventBox.Unwatch(EvtReadNew)
eventBox.WaitFor(EvtReadFin)
}
@@ -247,7 +255,7 @@ func Run(opts *Options) (int, error) {
if heightUnknown {
maxFit, padHeight = terminal.MaxFitAndPad()
}
- deferred := opts.Select1 || opts.Exit0 || opts.Sync
+ deferred := opts.Select1 || opts.Exit0 || sync
go terminal.Loop()
if !deferred && !heightUnknown {
// Start right away
@@ -314,6 +322,9 @@ func Run(opts *Options) (int, error) {
err = quitSignal.err
stop = true
return
+ case EvtReadNone:
+ reading = false
+ terminal.UpdateCount(0, false, nil)
case EvtReadNew, EvtReadFin:
if evt == EvtReadFin && nextCommand != nil {
restart(*nextCommand, nextEnviron)
diff --git a/src/options.go b/src/options.go
index fdf5f8dd..d9121c34 100644
--- a/src/options.go
+++ b/src/options.go
@@ -2945,3 +2945,18 @@ func ParseOptions(useDefaults bool, args []string) (*Options, error) {
return opts, nil
}
+
+func (opts *Options) reloadOnStart() bool {
+ // Not compatible with --filter
+ if opts.Filter != nil {
+ return false
+ }
+ if actions, prs := opts.Keymap[tui.Start.AsEvent()]; prs {
+ for _, action := range actions {
+ if action.t == actReload || action.t == actReloadSync {
+ return true
+ }
+ }
+ }
+ return false
+}