Add every(N) bind event and FZF_IDLE_TIME env var (#4797)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- every(N) fires every N seconds (fractional, floored to 0.01s) - Encoded as tui.Every with duration in Char as milliseconds, so every(1) and every(2) coexist as distinct keymap entries - FZF_IDLE_TIME exposes whole seconds since the last user activity (keystroke or mouse event); pair with every() for idle-based patterns like auto-accept/auto-quit Close #1211
authored by Junegunn Choi · committed by GitHub · parent e0d0819 · Browse files · 8 files·+248 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+248 added−26 removed
- tests:+79 added−0 removed
- other:+169 added−26 removed
Provenance
- Commit
fcc3c6a- Tree
afeda6f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
e0d0819
8 files changed+248 added−26 removed
modified:man/man1/fzf.1+28 added
1498 unmodified lines1499 .BR FZF_ACTION " The name of the last action performed"1500 .br1501 .BR FZF_KEY " The name of the last key pressed"1502 .br1503+.BR FZF_IDLE_TIME " Whole seconds since the last user activity"1504+.br1505+.BR FZF_IDLE_TIME_MS " Milliseconds since the last user activity"1506+.br1507 .BR FZF_PORT " Port number when \-\-listen option is used"1508 .br1509 .BR FZF_SOCK " Unix socket path when \-\-listen option is used"1510 .br431 unmodified lines1942 variables starting from 1. It optionally sets \fBFZF_CLICK_FOOTER_WORD\fR1943 if clicked on a word.1944 .RE1945 1946+\fIevery(N)\fR1947+.RS1948+Triggered every \fIN\fR seconds (\fIN\fR can be a fractional number, e.g.1949+\fB0.5\fR). The minimum interval is \fB0.01\fR seconds; values are floored1950+to that.1951+1952+Combine with the \fBFZF_IDLE_TIME\fR (whole seconds) and1953+\fBFZF_IDLE_TIME_MS\fR (milliseconds) environment variables to build1954+idle\-based behavior without a separate event.1955+1956+e.g.1957+ \fB# Live process list, refreshed every 2 seconds.1958+ # --track --id-nth 2 keeps the cursor on the same PID across reloads.1959+ fzf \-\-header\-lines 1 \-\-track \-\-id\-nth 2 \\1960+ \-\-bind 'start,every(2):reload\-sync:ps \-ef'1961+1962+ # Auto\-accept after 10 seconds of inactivity, with a countdown in the footer after 5s.1963+ fzf \-\-bind 'every(1):bg\-transform:1964+ if [[ $FZF_IDLE_TIME \-lt 5 ]]; then echo change\-footer:1965+ elif [[ $FZF_IDLE_TIME \-lt 10 ]]; then echo "change\-footer:auto\-accept in $((10 \- FZF_IDLE_TIME))s"1966+ else echo accept1967+ fi'\fR1968+.RE1969+1970 .SS AVAILABLE ACTIONS:1971 A key or an event can be bound to one or more of the following actions.1972 1973 \fBACTION: DEFAULT BINDINGS (NOTES):347 unmodified linesmodified:src/tui/eventtype_string.go+19 added-18 removed
131 unmodified lines132 _ = x[CtrlAltShiftEnd-121]133 _ = x[CtrlAltShiftDelete-122]134 _ = x[CtrlAltShiftPageUp-123]135 _ = x[CtrlAltShiftPageDown-124]136- _ = x[Invalid-125]137- _ = x[Fatal-126]138- _ = x[BracketedPasteBegin-127]139- _ = x[BracketedPasteEnd-128]140- _ = x[Mouse-129]141- _ = x[DoubleClick-130]142- _ = x[LeftClick-131]143- _ = x[RightClick-132]144- _ = x[SLeftClick-133]145- _ = x[SRightClick-134]146- _ = x[ScrollUp-135]147- _ = x[ScrollDown-136]148- _ = x[SScrollUp-137]149- _ = x[SScrollDown-138]150- _ = x[PreviewScrollUp-139]151- _ = x[PreviewScrollDown-140]136+ _ = x[Mouse-125]137+ _ = x[DoubleClick-126]138+ _ = x[LeftClick-127]139+ _ = x[RightClick-128]140+ _ = x[SLeftClick-129]141+ _ = x[SRightClick-130]142+ _ = x[ScrollUp-131]143+ _ = x[ScrollDown-132]144+ _ = x[SScrollUp-133]145+ _ = x[SScrollDown-134]146+ _ = x[PreviewScrollUp-135]147+ _ = x[PreviewScrollDown-136]148+ _ = x[Invalid-137]149+ _ = x[Fatal-138]150+ _ = x[BracketedPasteBegin-139]151+ _ = x[BracketedPasteEnd-140]152 _ = x[Resize-141]153 _ = x[Change-142]154 _ = x[BackwardEOF-143]155 _ = x[Start-144]6 unmodified lines162 _ = x[JumpCancel-151]163 _ = x[ClickHeader-152]164 _ = x[ClickFooter-153]165 _ = x[Multi-154]166+ _ = x[Every-155]167 }168 168-const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteShiftHomeShiftEndShiftPageUpShiftPageDownF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltDeleteAltHomeAltEndAltPageUpAltPageDownAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltShiftDeleteAltShiftHomeAltShiftEndAltShiftPageUpAltShiftPageDownCtrlUpCtrlDownCtrlLeftCtrlRightCtrlHomeCtrlEndCtrlBackspaceCtrlDeleteCtrlPageUpCtrlPageDownAltCtrlAltCtrlAltUpCtrlAltDownCtrlAltLeftCtrlAltRightCtrlAltHomeCtrlAltEndCtrlAltBackspaceCtrlAltDeleteCtrlAltPageUpCtrlAltPageDownCtrlShiftUpCtrlShiftDownCtrlShiftLeftCtrlShiftRightCtrlShiftHomeCtrlShiftEndCtrlShiftDeleteCtrlShiftPageUpCtrlShiftPageDownCtrlAltShiftUpCtrlAltShiftDownCtrlAltShiftLeftCtrlAltShiftRightCtrlAltShiftHomeCtrlAltShiftEndCtrlAltShiftDeleteCtrlAltShiftPageUpCtrlAltShiftPageDownInvalidFatalBracketedPasteBeginBracketedPasteEndMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMulti"169+const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLEnterCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteShiftHomeShiftEndShiftPageUpShiftPageDownF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltDeleteAltHomeAltEndAltPageUpAltPageDownAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltShiftDeleteAltShiftHomeAltShiftEndAltShiftPageUpAltShiftPageDownCtrlUpCtrlDownCtrlLeftCtrlRightCtrlHomeCtrlEndCtrlBackspaceCtrlDeleteCtrlPageUpCtrlPageDownAltCtrlAltCtrlAltUpCtrlAltDownCtrlAltLeftCtrlAltRightCtrlAltHomeCtrlAltEndCtrlAltBackspaceCtrlAltDeleteCtrlAltPageUpCtrlAltPageDownCtrlShiftUpCtrlShiftDownCtrlShiftLeftCtrlShiftRightCtrlShiftHomeCtrlShiftEndCtrlShiftDeleteCtrlShiftPageUpCtrlShiftPageDownCtrlAltShiftUpCtrlAltShiftDownCtrlAltShiftLeftCtrlAltShiftRightCtrlAltShiftHomeCtrlAltShiftEndCtrlAltShiftDeleteCtrlAltShiftPageUpCtrlAltShiftPageDownMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownInvalidFatalBracketedPasteBeginBracketedPasteEndResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeaderClickFooterMultiEvery"170 170-var _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, 1067, 1072, 1091, 1108, 1113, 1124, 1133, 1143, 1153, 1164, 1172, 1182, 1191, 1202, 1217, 1234, 1240, 1246, 1257, 1262, 1266, 1271, 1274, 1278, 1284, 1288, 1298, 1309, 1320, 1325}171+var _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}172 173 func (i EventType) String() string {174 if i < 0 || i >= EventType(len(_EventType_index)-1) {175 return "EventType(" + strconv.FormatInt(int64(i), 10) + ")"3 unmodified linesmodified:src/tui/tui.go+10 added-6 removed
194 unmodified lines195 CtrlAltShiftDelete196 CtrlAltShiftPageUp197 CtrlAltShiftPageDown198 199- Invalid200- Fatal201- BracketedPasteBegin202- BracketedPasteEnd203-199 Mouse200 DoubleClick201 LeftClick202 RightClick5 unmodified lines208 SScrollDown209 PreviewScrollUp210 PreviewScrollDown211 217- // Events212+ // Synthetic / non-user events. Everything from Invalid onward is213+ // either internally generated or a state-change notification, not214+ // direct user input. Use `>= Invalid` to gate activity tracking.215+ // BracketedPasteBegin/End sit here too: they enclose user input216+ // (which arrives as Rune events) and should not appear in FZF_KEY.217+ Invalid218+ Fatal219+ BracketedPasteBegin220+ BracketedPasteEnd221 Resize222 Change223 BackwardEOF224 Start6 unmodified lines231 JumpCancel232 ClickHeader233 ClickFooter234 Multi235+ Every236 )237 238 func (t EventType) AsEvent() Event {239 return Event{t, 0, nil}1275 unmodified linesmodified:src/options_test.go+33 added
297 unmodified lines298 parseKeymap(keymap, "f1:abort")299 check(tui.F1.AsEvent(), "", actAbort)300 }301 302+func TestParseEveryEvent(t *testing.T) {303+ pairs, _, err := parseKeyChords("every(2),every(0.5)", "")304+ if err != nil {305+ t.Fatalf("unexpected error: %v", err)306+ }307+ if len(pairs) != 2 {308+ t.Errorf("expected 2 distinct every events, got %d", len(pairs))309+ }310+ if pairs[(tui.Event{Type: tui.Every, Char: 2000})] != "every(2)" {311+ t.Errorf("every(2) not registered")312+ }313+ if pairs[(tui.Event{Type: tui.Every, Char: 500})] != "every(0.5)" {314+ t.Errorf("every(0.5) not registered")315+ }316+317+ // Floor at 0.01s -> 10ms318+ pairs, _, err = parseKeyChords("every(0.001)", "")319+ if err != nil {320+ t.Fatalf("unexpected error: %v", err)321+ }322+ if pairs[(tui.Event{Type: tui.Every, Char: 10})] != "every(0.001)" {323+ t.Errorf("every(0.001) should floor to 10ms")324+ }325+326+ // Reject zero, negatives, and overflow (>= 2^31 ms = ~24.85 days)327+ for _, bad := range []string{"every(0)", "every(-1)", "every(abc)", "every()", "every(2147484)"} {328+ if _, _, err := parseKeyChords(bad, ""); err == nil {329+ t.Errorf("%s should be rejected", bad)330+ }331+ }332+333+}334+335 func TestColorSpec(t *testing.T) {336 var base *tui.ColorTheme337 theme := tui.Dark256338 base, dark, _ := parseTheme(theme, "dark")266 unmodified linesmodified:src/options.go+24 added-1 removed
2 unmodified lines3 import (4 "errors"5 "fmt"6 "maps"7+ "math"8 "os"9 "regexp"10 "strconv"11 "strings"1245 unmodified lines1257 case "f12":1258 add(tui.F12)1259 default:1260 runes := []rune(key)1261+ if strings.HasPrefix(lkey, "every(") && strings.HasSuffix(lkey, ")") {1262+ evt, err := parseEveryEvent(key[6 : len(key)-1])1263+ if err != nil {1264+ return nil, list, err1265+ }1266+ chords[evt] = key1267+ list = append(list, evt)1260- if len(key) == 10 && strings.HasPrefix(lkey, "ctrl-alt-") && isAlphabet(lkey[9]) {1268+ } else if len(key) == 10 && strings.HasPrefix(lkey, "ctrl-alt-") && isAlphabet(lkey[9]) {1269 r := rune(lkey[9])1270 evt := tui.CtrlAltKey(r)1271 if r == 'h' && !util.IsWindows() {1272 evt = tui.CtrlAltBackspace.AsEvent()33 unmodified lines1306 }1307 return chords, list, nil1308 }1309 1310+func parseEveryEvent(arg string) (tui.Event, error) {1311+ secs, err := strconv.ParseFloat(strings.TrimSpace(arg), 64)1312+ if err != nil || math.IsNaN(secs) || math.IsInf(secs, 0) || secs <= 0 {1313+ return tui.Event{}, errors.New("every() requires a positive number of seconds")1314+ }1315+ if secs < 0.01 {1316+ secs = 0.011317+ }1318+ ms := math.Round(secs * 1000)1319+ if ms > math.MaxInt32 {1320+ return tui.Event{}, errors.New("every() interval is too large")1321+ }1322+ return tui.Event{Type: tui.Every, Char: rune(int32(ms))}, nil1323+}1324+1325 func parseScheme(str string) (string, []criterion, error) {1326 str = strings.ToLower(str)1327 switch str {1328 case "history":2648 unmodified linesmodified:src/terminal.go+42 added-1 removed
434 unmodified lines435 bgSemaphore chan struct{}436 bgSemaphores map[action]chan struct{}437 keyChan chan tui.Event438 eventChan chan tui.Event439+ timerChan chan tui.Event440 slab *util.Slab441 theme *tui.ColorTheme442 tui tui.Renderer443 ttyDefault string12 unmodified lines456 clickFooterColumn int457 proxyScript string458 numLinesCache map[int32]numLinesCacheValue459 raw bool460+ lastActivity time.Time461 }462 463 type numLinesCacheValue struct {464 atMost int687 unmodified lines1152 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)1156+ timerChan: make(chan tui.Event), // unbuffered: every() ticks coalesce when main loop is busy1157 tui: renderer,1158 ttyDefault: opts.TtyDefault,1159 ttyin: ttyin,1160 initFunc: func() error { return renderer.Init() },1161 executing: util.NewAtomicBool(false),1162 lastAction: actStart,1163 lastFocus: minItem.Index(),1164+ lastActivity: time.Now(),1165 numLinesCache: make(map[int32]numLinesCacheValue)}1166 if opts.AcceptNth != nil {1167 t.acceptNth = opts.AcceptNth(t.delimiter)1168 }219 unmodified lines1388 }1389 env = append(env, "FZF_QUERY="+string(t.input))1390 env = append(env, "FZF_ACTION="+t.lastAction.Name())1391 env = append(env, "FZF_KEY="+t.lastKey)1392+ idleMs := time.Since(t.lastActivity).Milliseconds()1393+ env = append(env, fmt.Sprintf("FZF_IDLE_TIME=%d", idleMs/1000))1394+ env = append(env, fmt.Sprintf("FZF_IDLE_TIME_MS=%d", idleMs))1395 env = append(env, "FZF_PROMPT="+string(t.promptString))1396 env = append(env, "FZF_GHOST="+string(t.ghost))1397 env = append(env, "FZF_POINTER="+string(t.pointer))1398 env = append(env, "FZF_PREVIEW_LABEL="+t.previewLabelOpts.label)4414 unmodified lines5813 }5814 return env5815 }5816 5817+// startTimers spawns a goroutine per every() bind event. Forwarding ticks5818+// onto the unbuffered timerChan lets the ticker drop overlapping ticks5819+// while the main loop is busy.5820+func (t *Terminal) startTimers(ctx context.Context) {5821+ for evt := range t.keymap {5822+ switch evt.Type {5823+ case tui.Every:5824+ d := time.Duration(evt.Char) * time.Millisecond5825+ evt := evt5826+ go func() {5827+ ticker := time.NewTicker(d)5828+ defer ticker.Stop()5829+ for {5830+ select {5831+ case <-ctx.Done():5832+ return5833+ case <-ticker.C:5834+ select {5835+ case <-ctx.Done():5836+ return5837+ case t.timerChan <- evt:5838+ }5839+ }5840+ }5841+ }()5842+ }5843+ }5844+}5845+5846 // Loop is called to start Terminal I/O5847 func (t *Terminal) Loop() error {5848 // prof := profile.Start(profile.ProfilePath("/tmp/"))5849 fitpad := <-t.startChan499 unmodified lines6349 case t.keyChan <- t.tui.GetChar(t.listenAddr != nil):6350 }6351 }6352 }()6353+ t.startTimers(ctx)6354 previewDraggingPos := -16355 barDragging := false6356 pbarDragging := false6357 pborderDragging := -151 unmodified lines6409 callbacks := []versionedCallback{}6410 select {6411 case event = <-t.keyChan:6412 needBarrier = true6413+ case event = <-t.timerChan:6414 case event = <-t.eventChan:6415 // Drain channel to process all queued events at once without rendering6416 // the intermediate states6417 Drain:56 unmodified lines6474 triggering := map[tui.Event]struct{}{}6475 previousInput := t.input6476 previousCx := t.cx6477 previousVersion := t.version6478+ if event.Type < tui.Invalid {6440- t.lastKey = event.KeyName()6479+ t.lastKey = event.KeyName()6480+ t.lastActivity = time.Now()6481+ }6482 updatePreviewWindow := func(forcePreview bool) {6483 t.resizeWindows(forcePreview, false)6484 req(reqPrompt, reqList, reqInfo, reqHeader, reqFooter)6485 }1765 unmodified linesmodified:test/test_core.rb+79 added
1385 unmodified lines1386 tmux.send_keys :BSpace1387 tmux.until { |lines| assert_includes lines, '> 1' }1388 end1389 1390+ def test_every_event1391+ tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-prompt(cat #{tempname})'), :Enter1392+ tmux.until { |lines| assert_equal 100, lines.match_count }1393+ # Trigger external state changes; the every() tick should pick them up.1394+ writelines(['AAA>'])1395+ tmux.until { |lines| assert_includes lines[-1], 'AAA>' }1396+ writelines(['BBB>'])1397+ tmux.until { |lines| assert_includes lines[-1], 'BBB>' }1398+ end1399+1400+ def test_every_event_multiple_independent_timers1401+ # Two timers with different durations should fire independently.1402+ fast = tempname + '.fast'1403+ slow = tempname + '.slow'1404+ FileUtils.rm_f(fast)1405+ FileUtils.rm_f(slow)1406+ tmux.send_keys %(seq 100 | fzf \\1407+ --bind 'every(0.1):execute-silent(printf . >> #{fast})' \\1408+ --bind 'every(0.5):execute-silent(printf . >> #{slow})'), :Enter1409+ tmux.until { |lines| assert_equal 100, lines.match_count }1410+ sleep 1.21411+ a = File.exist?(fast) ? File.size(fast) : 01412+ b = File.exist?(slow) ? File.size(slow) : 01413+ # Sanity: faster timer fired more times.1414+ assert a > b, "fast timer should fire more (#{a} vs #{b})"1415+ # Sanity: slow timer fired at least once.1416+ assert b >= 1, "slow timer should have fired at least once (#{b})"1417+ ensure1418+ FileUtils.rm_f(fast)1419+ FileUtils.rm_f(slow)1420+ end1421+1422+ def test_every_event_unbind1423+ tmux.send_keys %(seq 100 | fzf --bind 'every(0.1):transform-header(date +%S.%N)' --bind 'space:unbind(every(0.1))+change-header(STOPPED)'), :Enter1424+ tmux.until { |lines| assert_equal 100, lines.match_count }1425+ # Header should be ticking1426+ tmux.until { |lines| assert_match(/^ \d{2}\.\d+/, lines[-3]) }1427+ tmux.send_keys :Space1428+ tmux.until { |lines| assert_includes lines[-3], 'STOPPED' }1429+ sleep 0.41430+ # Header must stay STOPPED after the unbind1431+ assert_includes tmux.capture[-3], 'STOPPED'1432+ end1433+1434+ def test_fzf_idle_time_env1435+ # FZF_IDLE_TIME + FZF_IDLE_TIME_MS combined with every() implement idle-based behavior.1436+ tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-header(echo "s=$FZF_IDLE_TIME ms_ok=$((FZF_IDLE_TIME_MS / 1000 == FZF_IDLE_TIME))")'), :Enter1437+ tmux.until { |lines| assert_equal 100, lines.match_count }1438+ # Idle counter advances without any input; ms/1000 stays consistent with seconds.1439+ tmux.until { |lines| assert_includes lines[-3], 's=1 ms_ok=1' }1440+ tmux.until { |lines| assert_includes lines[-3], 's=2 ms_ok=1' }1441+ # Any keystroke resets the counter1442+ tmux.send_keys 'x'1443+ tmux.until { |lines| assert_includes lines[-3], 's=0 ms_ok=1' }1444+ tmux.send_keys :BSpace1445+ # And it advances again afterwards1446+ tmux.until { |lines| assert_includes lines[-3], 's=1 ms_ok=1' }1447+ end1448+1449+ def test_every_event_rejects_invalid_arg1450+ %w[every(0) every(-1) every(abc) every()].each do |spec|1451+ tmux.send_keys %(seq 1 | fzf --bind '#{spec}:abort' 2>&1; echo done=$?), :Enter1452+ tmux.until { |lines| assert(lines.any? { |l| l.include?('done=2') }) }1453+ tmux.send_keys 'clear', :Enter1454+ end1455+ end1456+1457+ def test_fzf_key_ignores_synthetic_events1458+ tmux.send_keys %(seq 100 | fzf --bind 'every(0.2):transform-prompt(echo "[$FZF_KEY]> ")'), :Enter1459+ tmux.until { |lines| assert_equal 100, lines.match_count }1460+ # No user input yet: prompt should show empty FZF_KEY1461+ tmux.until { |lines| assert_includes lines[-1], '[]>' }1462+ tmux.send_keys 'x'1463+ tmux.until { |lines| assert_includes lines[-1], '[x]>' }1464+ # every() ticks shouldn't overwrite FZF_KEY1465+ sleep 11466+ assert_includes tmux.capture[-1], '[x]>'1467+ end1468+1469 def test_labels_center1470 tmux.send_keys 'echo x | fzf --border --border-label foobar --preview : --preview-label barfoo --bind "space:change-border-label(foobarfoo)+change-preview-label(barfoobar),enter:transform-border-label(echo foo{}foo)+transform-preview-label(echo bar{}bar)"', :Enter1471 tmux.until do1472 assert_includes(it[0], '─foobar─')1293 unmodified linesmodified:CHANGELOG.md+13 added
1 unmodified line2 =========3 4 0.73.05 ------6+- Timer-driven `every(N)` event for `--bind`, where `N` is seconds (fractional, floored to `0.01`). Ticks that overlap an in-flight action are coalesced, so a slow `reload` cannot accumulate a backlog.7+- New `FZF_IDLE_TIME` (whole seconds) and `FZF_IDLE_TIME_MS` (milliseconds) environment variables exported to child processes, holding the elapsed time since the last user activity. Pair with `every(N)` to build idle-based behavior such as auto-accept or auto-quit (#1211).8+ ```sh9+ # Live process list; --track --id-nth 2 keeps the cursor on the same PID across reloads10+ fzf --header-lines 1 --track --id-nth 2 --bind 'start,every(2):reload-sync:ps -ef'11+12+ # Auto-accept after 10 seconds of inactivity, with a countdown in the footer after 5s13+ fzf --bind 'every(1):bg-transform:14+ if [[ $FZF_IDLE_TIME -lt 5 ]]; then echo change-footer:15+ elif [[ $FZF_IDLE_TIME -lt 10 ]]; then echo "change-footer:auto-accept in $((10 - FZF_IDLE_TIME))s"16+ else echo accept17+ fi'18+ ```19 - Bug fixes20 - `change-preview-window` no longer resets `wrap` / `wrap-word` state set via `toggle-preview-wrap` / `toggle-preview-wrap-word`. Layout fields still snap to the preset, so cycling and the empty-token reset behave as before. The new spec can still override by including `wrap` or `nowrap` explicitly. (#4791)21 22 0.72.03282 unmodified lines