mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-05-29 05:40:47 +00:00
Add 'result' event that is triggered when the result list is ready
Close #3560
This commit is contained in:
parent
e47dc758c9
commit
250496c953
|
@ -1,6 +1,11 @@
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.46.0 (WIP)
|
||||||
|
------
|
||||||
|
- Added `result` event that is triggered when the filtering for the current query is complete and the result list is ready.
|
||||||
|
- Bug fixes
|
||||||
|
|
||||||
0.45.0
|
0.45.0
|
||||||
------
|
------
|
||||||
- Added `transform` action to conditionally perform a series of actions
|
- Added `transform` action to conditionally perform a series of actions
|
||||||
|
|
|
@ -1075,6 +1075,15 @@ e.g.
|
||||||
\fB# Change the prompt to "loaded" when the input stream is complete
|
\fB# Change the prompt to "loaded" when the input stream is complete
|
||||||
(seq 10; sleep 1; seq 11 20) | fzf --prompt 'Loading> ' --bind 'load:change-prompt:Loaded> '\fR
|
(seq 10; sleep 1; seq 11 20) | fzf --prompt 'Loading> ' --bind 'load:change-prompt:Loaded> '\fR
|
||||||
.RE
|
.RE
|
||||||
|
\fIresult\fR
|
||||||
|
.RS
|
||||||
|
Triggered when the filtering for the current query is complete and the result list is ready.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fB# Put the cursor on the second item when the query string is empty
|
||||||
|
# * Note that you can't use 'change' event in this case because the second position may not be available
|
||||||
|
fzf --sync --bind 'result:transform:[[ -z {fzf:query} ]] && echo "pos(2)"'\fR
|
||||||
|
.RE
|
||||||
\fIchange\fR
|
\fIchange\fR
|
||||||
.RS
|
.RS
|
||||||
Triggered whenever the query string is changed
|
Triggered whenever the query string is changed
|
||||||
|
|
|
@ -650,6 +650,8 @@ func parseKeyChordsImpl(str string, message string, exit func(string)) map[tui.E
|
||||||
add(tui.Load)
|
add(tui.Load)
|
||||||
case "focus":
|
case "focus":
|
||||||
add(tui.Focus)
|
add(tui.Focus)
|
||||||
|
case "result":
|
||||||
|
add(tui.Result)
|
||||||
case "one":
|
case "one":
|
||||||
add(tui.One)
|
add(tui.One)
|
||||||
case "zero":
|
case "zero":
|
||||||
|
|
|
@ -251,6 +251,7 @@ type Terminal struct {
|
||||||
borderWidth int
|
borderWidth int
|
||||||
count int
|
count int
|
||||||
progress int
|
progress int
|
||||||
|
hasResultActions bool
|
||||||
hasFocusActions bool
|
hasFocusActions bool
|
||||||
hasLoadActions bool
|
hasLoadActions bool
|
||||||
triggerLoad bool
|
triggerLoad bool
|
||||||
|
@ -731,6 +732,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||||
ellipsis: opts.Ellipsis,
|
ellipsis: opts.Ellipsis,
|
||||||
ansi: opts.Ansi,
|
ansi: opts.Ansi,
|
||||||
tabstop: opts.Tabstop,
|
tabstop: opts.Tabstop,
|
||||||
|
hasResultActions: false,
|
||||||
hasFocusActions: false,
|
hasFocusActions: false,
|
||||||
hasLoadActions: false,
|
hasLoadActions: false,
|
||||||
triggerLoad: false,
|
triggerLoad: false,
|
||||||
|
@ -759,7 +761,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||||
killChan: make(chan int),
|
killChan: make(chan int),
|
||||||
serverInputChan: make(chan []*action, 10),
|
serverInputChan: make(chan []*action, 10),
|
||||||
serverOutputChan: make(chan string),
|
serverOutputChan: make(chan string),
|
||||||
eventChan: make(chan tui.Event, 4), // (load + zero|one) | (focus) | (GetChar)
|
eventChan: make(chan tui.Event, 5), // (load + result + zero|one) | (focus) | (GetChar)
|
||||||
tui: renderer,
|
tui: renderer,
|
||||||
initFunc: func() { renderer.Init() },
|
initFunc: func() { renderer.Init() },
|
||||||
executing: util.NewAtomicBool(false),
|
executing: util.NewAtomicBool(false),
|
||||||
|
@ -803,6 +805,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, t.hasResultActions = t.keymap[tui.Result.AsEvent()]
|
||||||
_, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]
|
_, t.hasFocusActions = t.keymap[tui.Focus.AsEvent()]
|
||||||
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
_, t.hasLoadActions = t.keymap[tui.Load.AsEvent()]
|
||||||
|
|
||||||
|
@ -1076,6 +1079,9 @@ func (t *Terminal) UpdateList(merger *Merger) {
|
||||||
t.eventChan <- one
|
t.eventChan <- one
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if t.hasResultActions {
|
||||||
|
t.eventChan <- tui.Result.AsEvent()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
t.reqBox.Set(reqInfo, nil)
|
t.reqBox.Set(reqInfo, nil)
|
||||||
|
@ -3189,7 +3195,7 @@ func (t *Terminal) Loop() {
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case event = <-t.eventChan:
|
case event = <-t.eventChan:
|
||||||
needBarrier = !event.Is(tui.Load, tui.Focus, tui.One, tui.Zero)
|
needBarrier = !event.Is(tui.Load, tui.Result, tui.Focus, tui.One, tui.Zero)
|
||||||
case serverActions := <-t.serverInputChan:
|
case serverActions := <-t.serverInputChan:
|
||||||
event = tui.Invalid.AsEvent()
|
event = tui.Invalid.AsEvent()
|
||||||
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
|
if t.listenAddr == nil || t.listenAddr.IsLocal() || t.listenUnsafe {
|
||||||
|
|
|
@ -105,6 +105,7 @@ const (
|
||||||
Focus
|
Focus
|
||||||
One
|
One
|
||||||
Zero
|
Zero
|
||||||
|
Result
|
||||||
|
|
||||||
AltBS
|
AltBS
|
||||||
|
|
||||||
|
|
|
@ -2721,6 +2721,16 @@ class TestGoFZF < TestBase
|
||||||
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }
|
tmux.until { |lines| refute_includes(lines[-1], '[[1]]') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_result_event
|
||||||
|
tmux.send_keys '(echo 0; seq 10) | fzf --bind "result:pos(2)"', :Enter
|
||||||
|
tmux.until { |lines| assert_equal 11, lines.item_count }
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||||
|
tmux.send_keys '9'
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 9' }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| assert_includes lines, '> 1' }
|
||||||
|
end
|
||||||
|
|
||||||
def test_labels_center
|
def test_labels_center
|
||||||
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)"', :Enter
|
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)"', :Enter
|
||||||
tmux.until do
|
tmux.until do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user