Do not start the initial reader if 'reload*' is bound to 'start'

This commit is contained in:
Junegunn Choi
2024-06-24 17:05:53 +09:00
parent 1525768094
commit 5b52833785
5 changed files with 51 additions and 7 deletions

View File

@@ -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)