Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 1525768 · Browse files · 5 files+51 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+51 added−7 removed

  • tests:+12 added−4 removed
  • other:+39 added−3 removed

5 files+51 added−7 removed

modified:src/constants.go+1 added
56 unmodified lines
57// fzf events58const (59 EvtReadNew util.EventType = iota60 EvtReadFin61 EvtReadNone62 EvtSearchNew63 EvtSearchProgress64 EvtSearchFin65 EvtHeader
11 unmodified lines
modified:src/core.go+14 added-3 removed
145 unmodified lines
146 // Process executor147 executor := util.NewExecutor(opts.WithShell)148149 // Reader150 reloadOnStart := opts.reloadOnStart()151 streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync152 var reader *Reader153 if !streamingFilter {154 reader = NewReader(func(data []byte) bool {155 return chunkList.Push(data)156 }, eventBox, executor, opts.ReadZero, opts.Filter == nil)157158 if reloadOnStart {159 // reload or reload-sync action is bound to 'start' event, no need to start the reader160 eventBox.Set(EvtReadNone, nil)161 } else {156 go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)162 go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)163 }164 }165166 // Matcher167 forward := true
65 unmodified lines
233 return ExitNoMatch, nil234 }235236 // Synchronous search230 if opts.Sync {237 sync := opts.Sync && !reloadOnStart238 if sync {239 eventBox.Unwatch(EvtReadNew)240 eventBox.WaitFor(EvtReadFin)241 }242
11 unmodified lines
254 heightUnknown := opts.Height.auto255 if heightUnknown {256 maxFit, padHeight = terminal.MaxFitAndPad()257 }250 deferred := opts.Select1 || opts.Exit0 || opts.Sync258 deferred := opts.Select1 || opts.Exit0 || sync259 go terminal.Loop()260 if !deferred && !heightUnknown {261 // Start right away262 terminal.startChan <- fitpad{-1, -1}
58 unmodified lines
321 exitCode = quitSignal.code322 err = quitSignal.err323 stop = true324 return325 case EvtReadNone:326 reading = false327 terminal.UpdateCount(0, false, nil)328 case EvtReadNew, EvtReadFin:329 if evt == EvtReadFin && nextCommand != nil {330 restart(*nextCommand, nextEnviron)331 nextCommand = nil
126 unmodified lines
modified:src/options.go+15 added
2943 unmodified lines
2944 }29452946 return opts, nil2947}29482949func (opts *Options) reloadOnStart() bool {2950 // Not compatible with --filter2951 if opts.Filter != nil {2952 return false2953 }2954 if actions, prs := opts.Keymap[tui.Start.AsEvent()]; prs {2955 for _, action := range actions {2956 if action.t == actReload || action.t == actReloadSync {2957 return true2958 }2959 }2960 }2961 return false2962}
modified:test/test_go.rb+12 added-4 removed
24 unmodified lines
25BASE = File.expand_path('..', __dir__)26Dir.chdir(BASE)27FZF = "FZF_DEFAULT_OPTS=\"--no-scrollbar --pointer \\> --marker \\>\" FZF_DEFAULT_COMMAND= #{BASE}/bin/fzf"2829def wait29def wait(timeout = DEFAULT_TIMEOUT)30 since = Time.now31 begin32 yield or raise Minitest::Assertion, 'Assertion failure'33 rescue Minitest::Assertion34 raise if Time.now - since > DEFAULT_TIMEOUT34 raise if Time.now - since > timeout3536 sleep(0.05)37 retry38 end
63 unmodified lines
102 def capture103 go(%W[capture-pane -p -J -t #{win}]).map(&:rstrip).reverse.drop_while(&:empty?).reverse104 end105106 def until(refresh = false)106 def until(refresh = false, timeout: DEFAULT_TIMEOUT)107 lines = nil108 begin109 wait do109 wait(timeout) do110 lines = capture111 class << lines112 def counts113 lazy
3241 unmodified lines
3355 │ 33356 BLOCK3357 tmux.until { assert_block(block, _1) }3358 end33593360 def test_start_on_reload3361 tmux.send_keys %[echo foo | #{FZF} --header Loading --header-lines 1 --bind 'start:reload:sleep 2; echo bar' --bind 'load:change-header:Loaded'], :Enter3362 tmux.until(timeout: 1) { |lines| assert_includes lines[-3], 'Loading' }3363 tmux.until(timeout: 1) { |lines| refute_includes lines[-4], 'foo' }3364 tmux.until { |lines| assert_includes lines[-3], 'Loaded' }3365 tmux.until { |lines| assert_includes lines[-4], 'bar' }3366 end3367end33683369module TestShell3370 def setup
520 unmodified lines
modified:CHANGELOG.md+9 added
30 unmodified lines
31 ```sh32 fzf --listen --sync --bind 'focus:transform-header:curl -s localhost:$FZF_PORT?limit=0 | jq .'33 ```34- Added `offset-middle` action to place the current item is in the middle of the screen35- fzf will not start the initial reader when `reload` or `reload-sync` is bound to `start` event. `fzf < /dev/null` or `: | fzf` are no longer required and extraneous `load` event will not fire due to the empty list.36 ```sh37 # Now this will work as expected. Previously, this would print an invalid header line.38 # `fzf < /dev/null` or `: | fzf` would fix the problem, but then an extraneous 39 # `load` event would fire and the header would be prematurely updated.40 fzf --header 'Loading ...' --header-lines 1 \41 --bind 'start:reload:sleep 1; ps -ef' \42 --bind 'load:change-header:Loaded!'43 ```44- Fixed mouse support on Windows45- Fixed crash when using `--tiebreak=end` with very long items46- zsh 5.0 compatibility (thanks to @LangLangBart)47- Fixed `--walker-skip` to also skip symlinks to directories
2150 unmodified lines