Skip to content
Myr

Add result-final event

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

- Fires like result, but only after the input stream closes - Use for one-shot per-query actions that would otherwise re-fire on every intermediate snapshot during loading Close #4835

authored by Junegunn Choi · committed by Junegunn Choi · parent f5fbfd8 · Browse files · 7 files+59 added−6 removed
This commit

State

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

Diff stats

7 files+59 added−6 removed

  • tests:+11 added−0 removed
  • other:+48 added−6 removed

7 files+59 added−6 removed

modified:man/man1/fzf.1+15 added-1 removed
224 unmodified lines
225.B "\-\-sync"226Synchronous search for multi-staged filtering. If specified, fzf will launch227the finder only after the input stream is complete and the initial filtering228and the associated actions (bound to any of \fBstart\fR, \fBload\fR,229\fBresult\fR, or \fBfocus\fR) are complete.229\fBresult\fR, \fBresult\-final\fR, or \fBfocus\fR) are complete.230231.RS232e.g. \fB# Avoid rendering both fzf instances at the same time233 fzf \-\-multi | fzf \-\-sync
1620 unmodified lines
1854 \fB# Put the cursor on the second item when the query string is empty1855 # * Note that you can't use 'change' event in this case because the second position may not be available1856 fzf \-\-sync \-\-bind 'result:transform:[[ \-z {q} ]] && echo "pos(2)"'\fR1857.RE18581859\fIresult\-final\fR1860.RS1861Same as \fIresult\fR, but suppressed while the input stream is still open. Use1862this when you want a one-shot action per query instead of one per intermediate1863snapshot during loading.18641865e.g.1866 \fB# 'result' fires per intermediate snapshot (header keeps updating during load);1867 # 'result-final' fires once after the stream closes (footer shows the final count)1868 (seq 100; sleep 1; seq 100) | fzf \-\-query 1 \\1869 \-\-bind 'result:transform\-header(echo result: $FZF_MATCH_COUNT),result\-final:transform\-footer(echo final: $FZF_MATCH_COUNT)'\fR1870.RE18711872\fIchange\fR1873.RS1874Triggered whenever the query string is changed1875
476 unmodified lines
modified:src/tui/eventtype_string.go+3 added-2 removed
162 unmodified lines
163 _ = x[ClickHeader-152]164 _ = x[ClickFooter-153]165 _ = x[Multi-154]166 _ = x[Every-155]167 _ = x[ResultFinal-156]168}169169const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteShiftHomeShiftEndShiftPageUpShiftPageDownF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltDeleteAltHomeAltEndAltPageUpAltPageDownAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltShiftDeleteAltShiftHomeAltShiftEndAltShiftPageUpAltShiftPageDownCtrlUpCtrlDownCtrlLeftCtrlRightCtrlHomeCtrlEndCtrlBackspaceCtrlDeleteCtrlPageUpCtrlPageDownAltCtrlAltCtrlAltUpCtrlAltDownCtrlAltLeftCtrlAltRightCtrlAltHomeCtrlAltEndCtrlAltBackspaceCtrlAltDeleteCtrlAltPageUpCtrlAltPageDownCtrlShiftUpCtrlShiftDownCtrlShiftLeftCtrlShiftRightCtrlShiftHomeCtrlShiftEndCtrlShiftDeleteCtrlShiftPageUpCtrlShiftPageDownCtrlAltShiftUpCtrlAltShiftDownCtrlAltShiftLeftCtrlAltShiftRightCtrlAltShiftHomeCtrlAltShiftEndCtrlAltShiftDeleteCtrlAltShiftPageUpCtrlAltShiftPageDownMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownInvalidFatalBracketedPasteBeginBracketedPasteEndResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMultiEvery"170const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteShiftHomeShiftEndShiftPageUpShiftPageDownF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltDeleteAltHomeAltEndAltPageUpAltPageDownAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltShiftDeleteAltShiftHomeAltShiftEndAltShiftPageUpAltShiftPageDownCtrlUpCtrlDownCtrlLeftCtrlRightCtrlHomeCtrlEndCtrlBackspaceCtrlDeleteCtrlPageUpCtrlPageDownAltCtrlAltCtrlAltUpCtrlAltDownCtrlAltLeftCtrlAltRightCtrlAltHomeCtrlAltEndCtrlAltBackspaceCtrlAltDeleteCtrlAltPageUpCtrlAltPageDownCtrlShiftUpCtrlShiftDownCtrlShiftLeftCtrlShiftRightCtrlShiftHomeCtrlShiftEndCtrlShiftDeleteCtrlShiftPageUpCtrlShiftPageDownCtrlAltShiftUpCtrlAltShiftDownCtrlAltShiftLeftCtrlAltShiftRightCtrlAltShiftHomeCtrlAltShiftEndCtrlAltShiftDeleteCtrlAltShiftPageUpCtrlAltShiftPageDownMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownInvalidFatalBracketedPasteBeginBracketedPasteEndResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMultiEveryResultFinal"171171var _EventType_index = [...]uint16{0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, 117, 122, 127, 132, 135, 144, 157, 173, 182, 191, 199, 208, 214, 220, 228, 230, 234, 238, 243, 247, 250, 256, 263, 272, 281, 291, 302, 311, 319, 330, 343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 364, 367, 370, 382, 387, 394, 401, 409, 418, 425, 431, 440, 451, 461, 473, 485, 498, 512, 524, 535, 549, 565, 571, 579, 587, 596, 604, 611, 624, 634, 644, 656, 659, 666, 675, 686, 697, 709, 720, 730, 746, 759, 772, 787, 798, 811, 824, 838, 851, 863, 878, 893, 910, 924, 940, 956, 973, 989, 1004, 1022, 1040, 1060, 1065, 1076, 1085, 1095, 1105, 1116, 1124, 1134, 1143, 1154, 1169, 1186, 1193, 1198, 1217, 1234, 1240, 1246, 1257, 1262, 1266, 1271, 1274, 1278, 1284, 1288, 1298, 1309, 1320, 1325, 1330}172var _EventType_index = [...]uint16{0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, 117, 122, 127, 132, 135, 144, 157, 173, 182, 191, 199, 208, 214, 220, 228, 230, 234, 238, 243, 247, 250, 256, 263, 272, 281, 291, 302, 311, 319, 330, 343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 364, 367, 370, 382, 387, 394, 401, 409, 418, 425, 431, 440, 451, 461, 473, 485, 498, 512, 524, 535, 549, 565, 571, 579, 587, 596, 604, 611, 624, 634, 644, 656, 659, 666, 675, 686, 697, 709, 720, 730, 746, 759, 772, 787, 798, 811, 824, 838, 851, 863, 878, 893, 910, 924, 940, 956, 973, 989, 1004, 1022, 1040, 1060, 1065, 1076, 1085, 1095, 1105, 1116, 1124, 1134, 1143, 1154, 1169, 1186, 1193, 1198, 1217, 1234, 1240, 1246, 1257, 1262, 1266, 1271, 1274, 1278, 1284, 1288, 1298, 1309, 1320, 1325, 1330, 1341}173174func (i EventType) String() string {175 if i < 0 || i >= EventType(len(_EventType_index)-1) {176 return "EventType(" + strconv.FormatInt(int64(i), 10) + ")"
3 unmodified lines
modified:src/tui/tui.go+1 added
232 unmodified lines
233 ClickHeader234 ClickFooter235 Multi236 Every237 ResultFinal238)239240func (t EventType) AsEvent() Event {241 return Event{t, 0, nil}
1286 unmodified lines
modified:src/options.go+2 added
1061 unmodified lines
1062 case "focus":1063 add(tui.Focus)1064 case "result":1065 add(tui.Result)1066 case "result-final":1067 add(tui.ResultFinal)1068 case "resize":1069 add(tui.Resize)1070 case "one":1071 add(tui.One)
2921 unmodified lines
modified:src/terminal.go+16 added-3 removed
1150 unmodified lines
1151 bgQueue: make(map[action][]func(bool)),1152 bgSemaphore: make(chan struct{}, maxBgProcesses),1153 bgSemaphores: make(map[action]chan struct{}),1154 keyChan: make(chan tui.Event),1155 eventChan: make(chan tui.Event, 6), // start | (load + result + zero|one) | (focus) | (resize)1155 eventChan: make(chan tui.Event, 7), // start | (load + result + result-final + zero|one) | (focus) | (resize)1156 timerChan: make(chan tui.Event), // unbuffered: every() ticks coalesce when main loop is busy1157 tui: renderer,1158 ttyDefault: opts.TtyDefault,1159 ttyin: ttyin,
184 unmodified lines
1344 t.keymap[tui.Resize.AsEvent()] = append(toActions(actClearScreen), resizeActions...)1345 }1346 _, t.hasStartActions = t.keymap[tui.Start.AsEvent()]1347 _, t.hasResultActions = t.keymap[tui.Result.AsEvent()]1348 if _, prs := t.keymap[tui.ResultFinal.AsEvent()]; prs {1349 t.hasResultActions = true1350 }1351 _, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]1352 _, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]13531354 if t.listenAddr != nil {
669 unmodified lines
2024 }2025 }2026 }2027 if t.hasResultActions {2028 result := tui.Result.AsEvent()2029 if _, prs := t.keymap[result]; prs {2025 t.pendingReqList = true2026 t.eventChan <- tui.Result.AsEvent()2030 t.pendingReqList = true2031 t.eventChan <- result2032 }2033 if !t.reading {2034 resultFinal := tui.ResultFinal.AsEvent()2035 if _, prs := t.keymap[resultFinal]; prs {2036 t.pendingReqList = true2037 t.eventChan <- resultFinal2038 }2039 }2040 }2041 updateList := !t.trackBlocked && !t.pendingReqList2042 updatePrompt := trackWasBlocked && !t.trackBlocked2043 t.mutex.Unlock()
6336 unmodified lines
modified:test/test_core.rb+11 added
1403 unmodified lines
1404 tmux.send_keys :BSpace1405 tmux.until { |lines| assert_includes lines, '> 1' }1406 end14071408 def test_result_final_event1409 tmux.send_keys %[(seq 100; sleep 1; seq 100) | #{FZF} \\1410 --query 1 \\1411 --bind 'result:transform-header(echo "R=$FZF_MATCH_COUNT")' \\1412 --bind 'result-final:transform-footer(echo "F=$FZF_MATCH_COUNT")'], :Enter1413 tmux.until { |lines| assert lines.any_include?('R=20') }1414 tmux.until { |lines| refute lines.any_include?('F=20') }1415 tmux.until { |lines| assert lines.any_include?('R=40') }1416 tmux.until { |lines| assert lines.any_include?('F=40') }1417 end14181419 def test_every_event1420 tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-prompt(cat #{tempname})'), :Enter1421 tmux.until { |lines| assert_equal 100, lines.match_count }1422 # Trigger external state changes; the every() tick should pick them up.
1391 unmodified lines
modified:CHANGELOG.md+11 added
1CHANGELOG2=========340.74.0 (WIP)5------------6- Added `result-final` event, a variant of `result` that is not triggered while the input stream is still open (#4835)7 - Use it for one-shot, per-query actions that would otherwise re-fire on every intermediate snapshot during loading8 ```sh9 # 'result' fires per intermediate snapshot (header keeps updating during load);10 # 'result-final' fires once after the stream closes (footer shows the final count)11 (seq 100; sleep 1; seq 100) | fzf --query 1 \12 --bind 'result:transform-header(echo result: $FZF_MATCH_COUNT),result-final:transform-footer(echo final: $FZF_MATCH_COUNT)'13 ```14150.73.116------17- Bug fixes18 - Skip `$FZF_CURRENT_ITEM` export when the item contains a NUL byte; `exec(2)` rejects the env, breaking preview and other child commands (#4806)
3314 unmodified lines