summaryrefslogtreecommitdiffstats
path: root/src/core.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2019-11-10 11:36:22 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2019-11-10 11:43:37 +0900
commit78da9287272a0bfa183498c5b2e9fde10a3663a0 (patch)
tree4318915c919024604777e16d49ae14a838564804 /src/core.go
parent11962dabba69e706246bfcd54fa42b1e1c6bee8b (diff)
Experimental implementation of "reload" action
# Reload input list with different sources seq 10 | fzf --bind 'ctrl-a:reload(seq 100),ctrl-b:reload(seq 1000)' # Reload as you type seq 10 | fzf --bind 'change:reload:seq {q}' --phony # Integration with ripgrep RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case " INITIAL_QUERY="" FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \ fzf --bind "change:reload:$RG_PREFIX {q} || true" \ --ansi --phony --query "$INITIAL_QUERY" Close #751 Close #965 Close #974 Close #1736 Related #1723
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/core.go b/src/core.go
index ae8c8ebe..d9d98d18 100644
--- a/src/core.go
+++ b/src/core.go
@@ -135,8 +135,9 @@ func Run(opts *Options, revision string) {
// Reader
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
+ var reader *Reader
if !streamingFilter {
- reader := NewReader(func(data []byte) bool {
+ reader = NewReader(func(data []byte) bool {
return chunkList.Push(data)
}, eventBox, opts.ReadZero)
go reader.ReadSource()
@@ -223,6 +224,7 @@ func Run(opts *Options, revision string) {
// Event coordination
reading := true
ticks := 0
+ var nextCommand *string
eventBox.Watch(EvtReadNew)
for {
delay := true
@@ -241,21 +243,41 @@ func Run(opts *Options, revision string) {
switch evt {
case EvtReadNew, EvtReadFin:
- reading = reading && evt == EvtReadNew
+ clearCache := false
+ if evt == EvtReadFin && nextCommand != nil {
+ chunkList.Clear()
+ clearCache = true
+ go reader.restart(*nextCommand)
+ nextCommand = nil
+ } else {
+ reading = reading && evt == EvtReadNew
+ }
snapshot, count := chunkList.Snapshot()
- terminal.UpdateCount(count, !reading, value.(bool))
+ terminal.UpdateCount(count, !reading, value.(*string))
if opts.Sync {
terminal.UpdateList(PassMerger(&snapshot, opts.Tac))
}
- matcher.Reset(snapshot, input(), false, !reading, sort)
+ matcher.Reset(snapshot, input(), false, !reading, sort, clearCache)
case EvtSearchNew:
+ var command *string
switch val := value.(type) {
- case bool:
- sort = val
+ case searchRequest:
+ sort = val.sort
+ command = val.command
+ }
+ if command != nil {
+ if reading {
+ reader.terminate()
+ nextCommand = command
+ } else {
+ reading = true
+ chunkList.Clear()
+ go reader.restart(*command)
+ }
}
snapshot, _ := chunkList.Snapshot()
- matcher.Reset(snapshot, input(), true, !reading, sort)
+ matcher.Reset(snapshot, input(), true, !reading, sort, command != nil)
delay = false
case EvtSearchProgress: