Skip to content
Myr

Merge branch 'devel'

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 · parents 16fc686, 2886f06 · Browse files · 15 files+591 added−173 removed
This commit

State

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

Diff stats

15 files+591 added−173 removed

  • tests:+29 added−1 removed
  • other:+562 added−172 removed

15 files+591 added−173 removed

modified:man/man1/fzf-tmux.1+2 added-2 removed
1.ig2The MIT License (MIT)34Copyright (c) 2017 Junegunn Choi4Copyright (c) 2019 Junegunn Choi56Permission is hereby granted, free of charge, to any person obtaining a copy7of this software and associated documentation files (the "Software"), to deal8in the Software without restriction, including without limitation the rights
11 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf-tmux 1 "Mar 2019" "fzf 0.18.0" "fzf-tmux - open fzf in tmux split pane"24.TH fzf-tmux 1 "Nov 2019" "fzf 0.19.0" "fzf-tmux - open fzf in tmux split pane"2526.SH NAME27fzf-tmux - open fzf in tmux split pane28
26 unmodified lines
modified:man/man1/fzf.1+197 added-74 removed
1.ig2The MIT License (MIT)34Copyright (c) 2017 Junegunn Choi4Copyright (c) 2019 Junegunn Choi56Permission is hereby granted, free of charge, to any person obtaining a copy7of this software and associated documentation files (the "Software"), to deal8in the Software without restriction, including without limitation the rights
11 unmodified lines
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN22THE SOFTWARE.23..24.TH fzf 1 "Mar 2019" "fzf 0.18.0" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Nov 2019" "fzf 0.19.0" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
40 unmodified lines
69Transform the presentation of each line using field index expressions70.TP71.BI "-d, --delimiter=" "STR"72Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)73.TP74.BI "--phony"75Do not perform search. With this option, fzf becomes a simple selector76interface rather than a "fuzzy finder".77.SS Search result78.TP79.B "+s, --no-sort"80Do not sort the result
1 unmodified line
82.B "--tac"83Reverse the order of the input8485.RS86e.g.82e.g. \fBhistory | fzf --tac --no-sort\fR87 \fBhistory | fzf --tac --no-sort\fR88.RE89.TP90.BI "--tiebreak=" "CRI[,..]"91Comma-separated list of sort criteria to apply when the scores are tied.
21 unmodified lines
113- If \fBend\fR is found in the list, fzf will scan each line backwards114.SS Interface115.TP116.B "-m, --multi"112Enable multi-select with tab/shift-tab117Enable multi-select with tab/shift-tab. It optionally takes an integer argument118which denotes the maximum number of items that can be selected.119.TP120.B "+m, --no-multi"121Disable multi-select122.TP123.B "--no-mouse"124Disable mouse125.TP126.BI "--bind=" "KEYBINDS"121Comma-separated list of custom key bindings. See \fBKEY BINDINGS\fR for the122details.127Comma-separated list of custom key bindings. See \fBKEY/EVENT BINDINGS\fR for128the details.129.TP130.B "--cycle"131Enable cyclic scroll132.TP
73 unmodified lines
206terminal size with \fB%\fR suffix.207.br208209.br204e.g. \fBfzf --margin 10%\fR205 \fBfzf --margin 1,5%\fR210e.g.211 \fBfzf --margin 10%212 fzf --margin 1,5%\fR213.RE214.TP208.B "--inline-info"209Display finder info inline with the query215.BI "--info=" "STYLE"216Determines the display style of finder info.217218.br219.BR default " Display on the next line to the prompt"220.br221.BR inline " Display on the same line"222.br223.BR hidden " Do not display finder info"224.br225226.TP227.B "--no-info"228A synonym for \fB--info=hidden\fB229230.TP231.BI "--prompt=" "STR"232Input prompt (default: '> ')233.TP234.BI "--header=" "STR"
20 unmodified lines
255foreground/background color. You can also specify 24-bit color in \fB#rrggbb\fR256format.257258.RS239e.g. \fBfzf --color=bg+:24\fR240 \fBfzf --color=light,fg:232,bg:255,bg+:116,info:27\fR241.RE242243.RS259.B BASE SCHEME:260 (default: dark on 256-color terminal, otherwise 16)261262 \fBdark \fRColor scheme for dark 256-color terminal
15 unmodified lines
278 \fBpointer \fRPointer to the current line279 \fBmarker \fRMulti-select marker280 \fBspinner \fRStreaming input indicator281 \fBheader \fRHeader282283.B EXAMPLES:284285 \fB# Seoul256 theme with 8-bit colors286 # (https://github.com/junegunn/seoul256.vim) 287 fzf --color='bg:237,bg+:236,info:143,border:240,spinner:108' \\288 --color='hl:65,fg:252,header:65,fg+:252' \\289 --color='pointer:161,marker:168,prompt:110,hl+:108'290291 # Seoul256 theme with 24-bit colors292 fzf --color='bg:#4B4B4B,bg+:#3F3F3F,info:#BDBB72,border:#6B6B6B,spinner:#98BC99' \\293 --color='hl:#719872,fg:#D9D9D9,header:#719872,fg+:#D9D9D9' \\294 --color='pointer:#E12672,marker:#E17899,prompt:#98BEDE,hl+:#98BC99'\fR295.RE296.TP297.B "--no-bold"298Do not use bold text
19 unmodified lines
318string, specify field index expressions between the braces (See \fBFIELD INDEX319EXPRESSION\fR for the details).320321.RS294e.g. \fBfzf --preview='head -$LINES {}'\fR295 \fBls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR322e.g.323 \fBfzf --preview='head -$LINES {}'324 ls -l | fzf --preview="echo user={3} when={-4..-2}; cat {-1}" --header-lines=1\fR325326fzf exports \fB$FZF_PREVIEW_LINES\fR and \fB$FZF_PREVIEW_COLUMNS\fR so that327they represent the exact size of the preview window. (It also overrides328\fB$LINES\fR and \fB$COLUMNS\fR with the same values but they can be reset
3 unmodified lines
332A placeholder expression starting with \fB+\fR flag will be replaced to the333space-separated list of the selected lines (or the current line if no selection334was made) individually quoted.335307e.g. \fBfzf --multi --preview='head -10 {+}'\fR308 \fBgit log --oneline | fzf --multi --preview 'git show {+1}'\fR336e.g.337 \fBfzf --multi --preview='head -10 {+}'338 git log --oneline | fzf --multi --preview 'git show {+1}'\fR339340When using a field index expression, leading and trailing whitespace is stripped341from the replacement string. To preserve the whitespace, use the \fBs\fR flag.342343Also, \fB{q}\fR is replaced to the current query string, and \fB{n}\fR is344replaced to zero-based ordinal index of the line. Use \fB{+n}\fR if you want345all index numbers when multiple lines are selected.346347A placeholder expression with \fBf\fR flag is replaced to the path of348a temporary file that holds the evaluated list. This is useful when you349multi-select a large number of items and the length of the evaluated string may350exceed \fBARG_MAX\fR.351352e.g.353 \fB# Press CTRL-A to select 100K items and see the sum of all the numbers.354 # This won't work properly without 'f' flag due to ARG_MAX limit.355 seq 100000 | fzf --multi --bind ctrl-a:select-all \\356 --preview "awk '{sum+=\$1} END {print sum}' {+f}"\fR357358Note that you can escape a placeholder pattern by prepending a backslash.359360Preview window will be updated even when there is no match for the current361query if any of the placeholder expressions evaluates to a non-empty string.362.RE363.TP323.BI "--preview-window=" "[POSITION][:SIZE[%]][:wrap][:hidden]"324Determine the layout of the preview window. If the argument ends with364.BI "--preview-window=" "[POSITION][:SIZE[%]][:noborder][:wrap][:hidden]"365Determines the layout of the preview window. If the argument contains366\fB:hidden\fR, the preview window will be hidden by default until367\fBtoggle-preview\fR action is triggered. Long lines are truncated by default.368Line wrap can be enabled with \fB:wrap\fR flag.369
8 unmodified lines
378 \fBright379.RE380381.RS341e.g. \fBfzf --preview="head {}" --preview-window=up:30%\fR342 \fBfzf --preview="file {}" --preview-window=down:1\fR382e.g.383 \fBfzf --preview="head {}" --preview-window=up:30%384 fzf --preview="file {}" --preview-window=down:1\fR385.RE386.SS Scripting387.TP388.BI "-q, --query=" "STR"
21 unmodified lines
410times, fzf will expect the union of the keys. \fB--no-expect\fR will clear the411list.412413.RS414e.g.372e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s --expect=f1,f2,~,@\fR415 \fBfzf --expect=ctrl-v,ctrl-t,alt-s --expect=f1,f2,~,@\fR416.RE417.TP418.B "--read0"419Read input delimited by ASCII NUL characters instead of newline characters
97 unmodified lines
517\fBrb\fR, or \fBpy\fR.518519e.g. \fB^core go$ | rb$ | py$\fR520478.SH KEY BINDINGS479You can customize key bindings of fzf with \fB--bind\fR option which takes480a comma-separated list of key binding expressions. Each key binding expression481follows the following format: \fBKEY:ACTION\fR521.SH KEY/EVENT BINDINGS522\fB--bind\fR option allows you to bind \fBa key\fR or \fBan event\fR to one or523more \fBactions\fR. You can use it to customize key bindings or implement524dynamic behaviors.525483e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR526\fB--bind\fR takes a comma-separated list of binding expressions. Each binding527expression is \fBKEY:ACTION\fR or \fBEVENT:ACTION\fR.528485.B AVAILABLE KEYS: (SYNONYMS)486 \fIctrl-[a-z]\fR487 \fIctrl-space\fR488 \fIctrl-alt-[a-z]\fR489 \fIalt-[a-z]\fR490 \fIalt-[0-9]\fR491 \fIf[1-12]\fR492 \fIenter\fR (\fIreturn\fR \fIctrl-m\fR)493 \fIspace\fR494 \fIbspace\fR (\fIbs\fR)495 \fIalt-up\fR496 \fIalt-down\fR497 \fIalt-left\fR498 \fIalt-right\fR499 \fIalt-enter\fR500 \fIalt-space\fR501 \fIalt-bspace\fR (\fIalt-bs\fR)502 \fIalt-/\fR503 \fItab\fR504 \fIbtab\fR (\fIshift-tab\fR)505 \fIesc\fR506 \fIdel\fR507 \fIup\fR508 \fIdown\fR509 \fIleft\fR510 \fIright\fR511 \fIhome\fR512 \fIend\fR513 \fIpgup\fR (\fIpage-up\fR)514 \fIpgdn\fR (\fIpage-down\fR)515 \fIshift-up\fR516 \fIshift-down\fR517 \fIshift-left\fR518 \fIshift-right\fR519 \fIleft-click\fR520 \fIright-click\fR521 \fIdouble-click\fR522 or any single character529e.g.530 \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR531524Additionally, a special event named \fIchange\fR is available which is525triggered whenever the query string is changed.532.SS AVAILABLE KEYS: (SYNONYMS)533\fIctrl-[a-z]\fR534.br535\fIctrl-space\fR536.br537\fIctrl-\\\fR538.br539\fIctrl-]\fR540.br541\fIctrl-^\fR (\fIctrl-6\fR)542.br543\fIctrl-/\fR (\fIctrl-_\fR)544.br545\fIctrl-alt-[a-z]\fR546.br547\fIalt-[a-z]\fR548.br549\fIalt-[0-9]\fR550.br551\fIf[1-12]\fR552.br553\fIenter\fR (\fIreturn\fR \fIctrl-m\fR)554.br555\fIspace\fR556.br557\fIbspace\fR (\fIbs\fR)558.br559\fIalt-up\fR560.br561\fIalt-down\fR562.br563\fIalt-left\fR564.br565\fIalt-right\fR566.br567\fIalt-enter\fR568.br569\fIalt-space\fR570.br571\fIalt-bspace\fR (\fIalt-bs\fR)572.br573\fIalt-/\fR574.br575\fItab\fR576.br577\fIbtab\fR (\fIshift-tab\fR)578.br579\fIesc\fR580.br581\fIdel\fR582.br583\fIup\fR584.br585\fIdown\fR586.br587\fIleft\fR588.br589\fIright\fR590.br591\fIhome\fR592.br593\fIend\fR594.br595\fIpgup\fR (\fIpage-up\fR)596.br597\fIpgdn\fR (\fIpage-down\fR)598.br599\fIshift-up\fR600.br601\fIshift-down\fR602.br603\fIshift-left\fR604.br605\fIshift-right\fR606.br607\fIleft-click\fR608.br609\fIright-click\fR610.br611\fIdouble-click\fR612.br613or any single character614527 e.g. \fBfzf --bind change:top\fR615.SS AVAILABLE EVENTS:616\fIchange\fR (triggered whenever the query string is changed)617.br618619 e.g.620 \fB# Moves cursor to the top (or bottom depending on --layout) whenever the query is changed621 fzf --bind change:top\fR622623.SS AVAILABLE ACTIONS:624A key or an event can be bound to one or more of the following actions.625626 \fBACTION: DEFAULT BINDINGS (NOTES):627 \fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR628 \fBaccept\fR \fIenter double-click\fR629 \fBaccept-non-empty\fR (same as \fBaccept\fR except that it prevents fzf from exiting without selection)
29 unmodified lines
659 \fBpreview-page-down\fR660 \fBpreview-page-up\fR661 \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)662 \fBprint-query\fR (print query and exit)663 \fBreload(...)\fR (see below for the details)664 \fBreplace-query\fR (replace query string with the current selection)665 \fBselect-all\fR666 \fBtoggle\fR (\fIright-click\fR)667 \fBtoggle-all\fR
9 unmodified lines
677 \fBunix-word-rubout\fR \fIctrl-w\fR678 \fBup\fR \fIctrl-k ctrl-p up\fR679 \fByank\fR \fIctrl-y\fR680681.SS ACTION COMPOSITION682683Multiple actions can be chained using \fB+\fR separator.684685e.g.585 \fBfzf --bind 'ctrl-a:select-all+accept'\fR686 \fBfzf --bind 'ctrl-a:select-all+accept'\fR687688.SS COMMAND EXECUTION689690With \fBexecute(...)\fR action, you can execute arbitrary commands without691leaving fzf. For example, you can turn fzf into a simple file browser by692binding \fBenter\fR key to \fBless\fR command like follows.693
19 unmodified lines
713 \fBexecute/.../\fR714 \fBexecute|...|\fR715 \fBexecute:...\fR716.RS614This is the special form that frees you from parse errors as it does not expect615the closing character. The catch is that it should be the last one in the616comma-separated list of key-action pairs.717The last one is the special form that frees you from parse errors as it does718not expect the closing character. The catch is that it should be the last one719in the comma-separated list of key-action pairs.720.RE721722fzf switches to the alternate screen when executing a command. However, if the723command is expected to complete quickly, and you are not interested in its
1 unmodified line
725executes the command without the switching. Note that fzf will not be726responsive until the command is complete. For asynchronous execution, start727your command as a background process (i.e. appending \fB&\fR).728729.SS RELOAD INPUT730731\fBreload(...)\fR action is used to dynamically update the input list732without restarting fzf. It takes the same command template with placeholder733expressions as \fBexecute(...)\fR.734735See \fIhttps://github.com/junegunn/fzf/issues/1750\fR for more info.736737e.g.738 \fB# Update the list of processes by pressing CTRL-R739 ps -ef | fzf --bind 'ctrl-r:reload(ps -ef)' --header 'Press CTRL-R to reload' \\740 --header-lines=1 --layout=reverse741742 # Integration with ripgrep743 RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "744 INITIAL_QUERY="foobar"745 FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \\746 fzf --bind "change:reload:$RG_PREFIX {q} || true" \\747 --ansi --phony --query "$INITIAL_QUERY"\fR748749.SH AUTHOR750Junegunn Choi (\fIjunegunn.c@gmail.com\fR)751752.SH SEE ALSO
14 unmodified lines
modified:src/tui/light.go+8 added
343 unmodified lines
344 case 127:345 return Event{BSpace, 0, nil}346 case 0:347 return Event{CtrlSpace, 0, nil}348 case 28:349 return Event{CtrlBackSlash, 0, nil}350 case 29:351 return Event{CtrlRightBracket, 0, nil}352 case 30:353 return Event{CtrlCaret, 0, nil}354 case 31:355 return Event{CtrlSlash, 0, nil}356 case ESC:357 ev := r.escSequence(&sz)358 // Second chance359 if ev.Type == Invalid {
592 unmodified lines
modified:src/tui/tcell.go+6 added
282 unmodified lines
283 case tcell.KeyCtrlZ:284 return Event{keyfn('z'), 0, nil}285 case tcell.KeyCtrlSpace:286 return Event{CtrlSpace, 0, nil}287 case tcell.KeyCtrlBackslash:288 return Event{CtrlBackSlash, 0, nil}289 case tcell.KeyCtrlRightSq:290 return Event{CtrlRightBracket, 0, nil}291 case tcell.KeyCtrlUnderscore:292 return Event{CtrlSlash, 0, nil}293 case tcell.KeyBackspace2:294 if alt {295 return Event{AltBS, 0, nil}296 }
312 unmodified lines
modified:src/tui/tui.go+19 added
38 unmodified lines
39 CtrlZ40 ESC41 CtrlSpace4243 // https://apple.stackexchange.com/questions/24261/how-do-i-send-c-that-is-control-slash-to-the-terminal44 CtrlBackSlash45 CtrlRightBracket46 CtrlCaret47 CtrlSlash4849 Invalid50 Resize51 Mouse52 DoubleClick
167 unmodified lines
220 bottomLeft rune221 bottomRight rune222}223224type BorderCharacter int225226func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {227 if unicode {228 return BorderStyle{229 shape: shape,
15 unmodified lines
245 bottomRight: '+',246 }247}248249func MakeTransparentBorder() BorderStyle {250 return BorderStyle{251 shape: BorderAround,252 horizontal: ' ',253 vertical: ' ',254 topLeft: ' ',255 topRight: ' ',256 bottomLeft: ' ',257 bottomRight: ' '}258}259260type Renderer interface {261 Init()262 Pause(clear bool)263 Resume(clear bool)
228 unmodified lines
modified:src/util/chars.go+5 added
140 unmodified lines
141 }142 return whitespaces143}144145func (chars *Chars) TrimTrailingWhitespaces() {146 whitespaces := chars.TrailingWhitespaces()147 chars.slice = chars.slice[0 : len(chars.slice)-whitespaces]148}149150func (chars *Chars) ToString() string {151 if runes := chars.optionalRunes(); runes != nil {152 return string(runes)153 }
33 unmodified lines
modified:src/chunklist.go+7 added
62 unmodified lines
63 cl.mutex.Unlock()64 return ret65}6667// Clear clears the data68func (cl *ChunkList) Clear() {69 cl.mutex.Lock()70 cl.chunks = nil71 cl.mutex.Unlock()72}7374// Snapshot returns immutable snapshot of the ChunkList75func (cl *ChunkList) Snapshot() ([]*Chunk, int) {76 cl.mutex.Lock()77
12 unmodified lines
modified:src/core.go+41 added-9 removed
124 unmodified lines
125 eventBox.Set(EvtHeader, header)126 return false127 }128 item.text, item.colors = ansiProcessor([]byte(transformed))129 item.text.TrimTrailingWhitespaces()130 item.text.Index = itemIndex131 item.origText = &data132 itemIndex++133 return true
1 unmodified line
135 }136137 // Reader138 streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync139 var reader *Reader140 if !streamingFilter {139 reader := NewReader(func(data []byte) bool {141 reader = NewReader(func(data []byte) bool {142 return chunkList.Push(data)141 }, eventBox, opts.ReadZero)143 }, eventBox, opts.ReadZero, opts.Filter == nil)144 go reader.ReadSource()145 }146147 // Matcher
35 unmodified lines
183 found = true184 }185 }186 return false185 }, eventBox, opts.ReadZero)187 }, eventBox, opts.ReadZero, false)188 reader.ReadSource()189 } else {190 eventBox.Unwatch(EvtReadNew)191 eventBox.WaitFor(EvtReadFin)
32 unmodified lines
224225 // Event coordination226 reading := true227 ticks := 0228 var nextCommand *string229 restart := func(command string) {230 reading = true231 chunkList.Clear()232 header = make([]string, 0, opts.HeaderLines)233 go reader.restart(command)234 }235 eventBox.Watch(EvtReadNew)236 for {237 delay := true238 ticks++239 input := func() []rune {240 if opts.Phony {241 return []rune{}242 }243 return []rune(terminal.Input())244 }245 eventBox.Wait(func(events *util.Events) {246 if _, fin := (*events)[EvtReadFin]; fin {247 delete(*events, EvtReadNew)248 }249 for evt, value := range *events {250 switch evt {251252 case EvtReadNew, EvtReadFin:253 clearCache := false254 if evt == EvtReadFin && nextCommand != nil {255 clearCache = true256 restart(*nextCommand)257 nextCommand = nil258 } else {238 reading = reading && evt == EvtReadNew259 reading = reading && evt == EvtReadNew260 }261 snapshot, count := chunkList.Snapshot()240 terminal.UpdateCount(count, !reading, value.(bool))262 terminal.UpdateCount(count, !reading, value.(*string))263 if opts.Sync {264 terminal.UpdateList(PassMerger(&snapshot, opts.Tac))265 }244 matcher.Reset(snapshot, terminal.Input(), false, !reading, sort)266 matcher.Reset(snapshot, input(), false, !reading, sort, clearCache)267268 case EvtSearchNew:269 var command *string270 switch val := value.(type) {248 case bool:249 sort = val271 case searchRequest:272 sort = val.sort273 command = val.command274 }275 if command != nil {276 if reading {277 reader.terminate()278 nextCommand = command279 } else {280 restart(*command)281 }282 }283 snapshot, _ := chunkList.Snapshot()252 matcher.Reset(snapshot, terminal.Input(), true, !reading, sort)284 matcher.Reset(snapshot, input(), true, !reading, sort, command != nil)285 delay = false286287 case EvtSearchProgress:288 switch val := value.(type) {
49 unmodified lines
modified:src/matcher.go+8 added-7 removed
10 unmodified lines
11)1213// MatchRequest represents a search request14type MatchRequest struct {15 chunks []*Chunk16 pattern *Pattern17 final bool18 sort bool15 chunks []*Chunk16 pattern *Pattern17 final bool18 sort bool19 clearCache bool20}2122// Matcher is responsible for performing search23type Matcher struct {
45 unmodified lines
69 }70 events.Clear()71 })7272 if request.sort != m.sort {73 if request.sort != m.sort || request.clearCache {74 m.sort = request.sort75 m.mergerCache = make(map[string]*Merger)76 clearChunkCache()77 }
143 unmodified lines
221 return NewMerger(pattern, partialResults, m.sort, m.tac), false222}223224// Reset is called to interrupt/signal the ongoing search224func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool) {225func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, clearCache bool) {226 pattern := m.patternBuilder(patternRunes)227228 var event util.EventType229 if cancel {230 event = reqReset231 } else {232 event = reqRetry233 }233 m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort && pattern.sortable})234 m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort && pattern.sortable, clearCache})235}
modified:src/options.go+65 added-9 removed
31 unmodified lines
32 field index expressions33 -d, --delimiter=STR Field delimiter regex (default: AWK-style)34 +s, --no-sort Do not sort the result35 --tac Reverse the order of the input36 --phony Do not perform search37 --tiebreak=CRI[,..] Comma-separated list of sort criteria to apply38 when the scores are tied [length|begin|end|index]39 (default: length)40
15 unmodified lines
56 (default: 10)57 --layout=LAYOUT Choose layout: [default|reverse|reverse-list]58 --border Draw border above and below the finder59 --margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)59 --inline-info Display finder info inline with the query60 --info=STYLE Finder info style [default|inline|hidden]61 --prompt=STR Input prompt (default: '> ')62 --header=STR String to print as header63 --header-lines=N The first N lines of the input are treated as header64
76 unmodified lines
141 layoutReverse142 layoutReverseList143)144145type infoStyle int146147const (148 infoDefault infoStyle = iota149 infoInline150 infoHidden151)152153type previewOpts struct {154 command string155 position windowPosition156 size sizeSpec157 hidden bool158 wrap bool159 border bool160}161162// Options stores the values of command-line options163type Options struct {164 Fuzzy bool165 FuzzyAlgo algo.Algo166 Extended bool167 Phony bool168 Case Case169 Normalize bool170 Nth []Range171 WithNth []Range
13 unmodified lines
185 Cycle bool186 Hscroll bool187 HscrollOff int188 FileWord bool178 InlineInfo bool189 InfoStyle infoStyle190 JumpLabels string191 Prompt string192 Query string193 Select1 bool
23 unmodified lines
217 return &Options{218 Fuzzy: true,219 FuzzyAlgo: algo.FuzzyMatchV2,220 Extended: true,221 Phony: false,222 Case: CaseSmart,223 Normalize: true,224 Nth: make([]Range, 0),225 WithNth: make([]Range, 0),
12 unmodified lines
238 Cycle: false,239 Hscroll: true,240 HscrollOff: 10,241 FileWord: false,230 InlineInfo: false,242 InfoStyle: infoDefault,243 JumpLabels: defaultJumpLabels,244 Prompt: "> ",245 Query: "",246 Select1: false,
1 unmodified line
248 Filter: nil,249 ToggleSort: false,250 Expect: make(map[int]string),251 Keymap: make(map[int][]action),240 Preview: previewOpts{"", posRight, sizeSpec{50, true}, false, false},252 Preview: previewOpts{"", posRight, sizeSpec{50, true}, false, false, true},253 PrintQuery: false,254 ReadZero: false,255 Printer: func(str string) { fmt.Println(str) },256 PrintSep: "\n",
168 unmodified lines
425 case "bspace", "bs":426 chord = tui.BSpace427 case "ctrl-space":428 chord = tui.CtrlSpace429 case "ctrl-^", "ctrl-6":430 chord = tui.CtrlCaret431 case "ctrl-/", "ctrl-_":432 chord = tui.CtrlSlash433 case "ctrl-\\":434 chord = tui.CtrlBackSlash435 case "ctrl-]":436 chord = tui.CtrlRightBracket437 case "change":438 chord = tui.Change439 case "alt-enter", "alt-return":440 chord = tui.CtrlAltM
206 unmodified lines
647func init() {648 // Backreferences are not supported.649 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')650 executeRegexp = regexp.MustCompile(631 `(?si):(execute(?:-multi|-silent)?):.+|:(execute(?:-multi|-silent)?)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)651 `(?si):(execute(?:-multi|-silent)?|reload):.+|:(execute(?:-multi|-silent)?|reload)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)652}653654func parseKeymap(keymap map[int][]action, str string) {655 masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {656 prefix := ":execute"657 if strings.HasPrefix(src, ":reload") {658 prefix = ":reload"637 if src[len(prefix)] == '-' {659 } else if src[len(prefix)] == '-' {660 c := src[len(prefix)+1]661 if c == 's' || c == 'S' {662 prefix += "-silent"663 } else {
144 unmodified lines
808 errorExit("unknown action: " + spec)809 } else {810 var offset int811 switch t {812 case actReload:813 offset = len("reload")814 case actExecuteSilent:815 offset = len("execute-silent")816 case actExecuteMulti:817 offset = len("execute-multi")
27 unmodified lines
845 if len(prefix) == 0 {846 prefix = matches[0][2]847 }848 switch prefix {849 case "reload":850 return actReload851 case "execute":852 return actExecute853 case "execute-silent":854 return actExecuteSilent
57 unmodified lines
912 }913 return layoutDefault914}915916func parseInfoStyle(str string) infoStyle {917 switch str {918 case "default":919 return infoDefault920 case "inline":921 return infoInline922 case "hidden":923 return infoHidden924 default:925 errorExit("invalid info style (expected: default / inline / hidden)")926 }927 return infoDefault928}929930func parsePreviewWindow(opts *previewOpts, input string) {931 // Default932 opts.position = posRight933 opts.size = sizeSpec{50, true}
3 unmodified lines
937 tokens := strings.Split(input, ":")938 sizeRegex := regexp.MustCompile("^[0-9]+%?$")939 for _, token := range tokens {940 switch token {941 case "":942 case "hidden":943 opts.hidden = true944 case "wrap":945 opts.wrap = true
4 unmodified lines
950 case "left":951 opts.position = posLeft952 case "right":953 opts.position = posRight954 case "border":955 opts.border = true956 case "noborder":957 opts.border = false958 default:959 if sizeRegex.MatchString(token) {960 opts.size = parseSize(token, 99, "window size")961 } else {
96 unmodified lines
1058 opts.Expect[k] = v1059 }1060 case "--no-expect":1061 opts.Expect = make(map[int]string)1062 case "--no-phony":1063 opts.Phony = false1064 case "--phony":1065 opts.Phony = true1066 case "--tiebreak":1067 opts.Criteria = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))1068 case "--bind":1069 parseKeymap(opts.Keymap, nextString(allArgs, &i, "bind expression required"))
66 unmodified lines
1136 case "--filepath-word":1137 opts.FileWord = true1138 case "--no-filepath-word":1139 opts.FileWord = false1140 case "--info":1141 opts.InfoStyle = parseInfoStyle(1142 nextString(allArgs, &i, "info style required"))1143 case "--no-info":1144 opts.InfoStyle = infoHidden1145 case "--inline-info":1092 opts.InlineInfo = true1146 opts.InfoStyle = infoInline1147 case "--no-inline-info":1094 opts.InlineInfo = false1148 opts.InfoStyle = infoDefault1149 case "--jump-labels":1150 opts.JumpLabels = nextString(allArgs, &i, "label characters required")1151 validateJumpLabels = true1152 case "-1", "--select-1":
46 unmodified lines
1199 case "--no-preview":1200 opts.Preview.command = ""1201 case "--preview-window":1202 parsePreviewWindow(&opts.Preview,1149 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:wrap][:hidden]"))1203 nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]][:noborder][:wrap][:hidden]"))1204 case "--height":1205 opts.Height = parseHeight(nextString(allArgs, &i, "height required: HEIGHT[%]"))1206 case "--min-height":1207 opts.MinHeight = nextInt(allArgs, &i, "height required: HEIGHT")
44 unmodified lines
1252 } else if match, value := optString(arg, "--min-height="); match {1253 opts.MinHeight = atoi(value)1254 } else if match, value := optString(arg, "--layout="); match {1255 opts.Layout = parseLayout(value)1256 } else if match, value := optString(arg, "--info="); match {1257 opts.InfoStyle = parseInfoStyle(value)1258 } else if match, value := optString(arg, "--toggle-sort="); match {1259 parseToggleSort(opts.Keymap, value)1260 } else if match, value := optString(arg, "--expect="); match {1261 for k, v := range parseKeyChords(value, "key names required") {
113 unmodified lines
modified:src/reader_test.go+5 added-6 removed
8 unmodified lines
910func TestReadFromCommand(t *testing.T) {11 strs := []string{}12 eb := util.NewEventBox()13 reader := Reader{14 pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },15 eventBox: eb,16 event: int32(EvtReady)}13 reader := NewReader(14 func(s []byte) bool { strs = append(strs, string(s)); return true },15 eb, false, true)1617 reader.startEventPoller()1819 // Check EventBox
1 unmodified line
21 t.Error("EvtReadNew should not be set yet")22 }2324 // Normal command26 reader.fin(reader.readFromCommand("sh", `echo abc && echo def`))25 reader.fin(reader.readFromCommand(nil, `echo abc && echo def`))26 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {27 t.Errorf("%s", strs)28 }29
16 unmodified lines
46 // Restart event poller47 reader.startEventPoller()4849 // Failing command51 reader.fin(reader.readFromCommand("sh", `no-such-command`))50 reader.fin(reader.readFromCommand(nil, `no-such-command`))51 strs = []string{}52 if len(strs) > 0 {53 t.Errorf("%s", strs)54 }
9 unmodified lines
modified:src/reader.go+63 added-12 removed
2 unmodified lines
3import (4 "bufio"5 "io"6 "os"7 "os/exec"8 "sync"9 "sync/atomic"10 "time"1112 "github.com/junegunn/fzf/src/util"
4 unmodified lines
17 pusher func([]byte) bool18 eventBox *util.EventBox19 delimNil bool20 event int3221 finChan chan bool22 mutex sync.Mutex23 exec *exec.Cmd24 command *string25 killed bool26 wait bool27}2829// NewReader returns new Reader object22func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool) *Reader {23 return &Reader{pusher, eventBox, delimNil, int32(EvtReady)}30func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool, wait bool) *Reader {31 return &Reader{pusher, eventBox, delimNil, int32(EvtReady), make(chan bool, 1), sync.Mutex{}, nil, nil, false, wait}32}3334func (r *Reader) startEventPoller() {35 go func() {36 ptr := &r.event37 pollInterval := readerPollIntervalMin38 for {39 if atomic.CompareAndSwapInt32(ptr, int32(EvtReadNew), int32(EvtReady)) {32 r.eventBox.Set(EvtReadNew, true)40 r.eventBox.Set(EvtReadNew, (*string)(nil))41 pollInterval = readerPollIntervalMin42 } else if atomic.LoadInt32(ptr) == int32(EvtReadFin) {43 if r.wait {44 r.finChan <- true45 }46 return47 } else {48 pollInterval += readerPollIntervalStep49 if pollInterval > readerPollIntervalMax {
6 unmodified lines
56}5758func (r *Reader) fin(success bool) {59 atomic.StoreInt32(&r.event, int32(EvtReadFin))60 if r.wait {61 <-r.finChan62 }6364 r.mutex.Lock()65 ret := r.command66 if success || r.killed {67 ret = nil68 }69 r.mutex.Unlock()7049 r.eventBox.Set(EvtReadFin, success)71 r.eventBox.Set(EvtReadFin, ret)72}7374func (r *Reader) terminate() {75 r.mutex.Lock()76 defer func() { r.mutex.Unlock() }()7778 r.killed = true79 if r.exec != nil && r.exec.Process != nil {80 util.KillCommand(r.exec)81 } else {82 os.Stdin.Close()83 }84}8586func (r *Reader) restart(command string) {87 r.event = int32(EvtReady)88 r.startEventPoller()89 success := r.readFromCommand(nil, command)90 r.fin(success)91}9293// ReadSource reads data from the default command or from standard input94func (r *Reader) ReadSource() {95 r.startEventPoller()96 var success bool97 if util.IsTty() {98 // The default command for *nix requires bash99 shell := "bash"100 cmd := os.Getenv("FZF_DEFAULT_COMMAND")101 if len(cmd) == 0 {59 // The default command for *nix requires bash60 success = r.readFromCommand("bash", defaultCommand)102 success = r.readFromCommand(&shell, defaultCommand)103 } else {62 success = r.readFromCommand("sh", cmd)104 success = r.readFromCommand(nil, cmd)105 }106 } else {107 success = r.readFromStdin()108 }
34 unmodified lines
143 r.feed(os.Stdin)144 return true145}146105func (r *Reader) readFromCommand(shell string, cmd string) bool {106 listCommand := util.ExecCommandWith(shell, cmd, false)107 out, err := listCommand.StdoutPipe()147func (r *Reader) readFromCommand(shell *string, command string) bool {148 r.mutex.Lock()149 r.killed = false150 r.command = &command151 if shell != nil {152 r.exec = util.ExecCommandWith(*shell, command, true)153 } else {154 r.exec = util.ExecCommand(command, true)155 }156 out, err := r.exec.StdoutPipe()157 if err != nil {158 r.mutex.Unlock()159 return false160 }111 err = listCommand.Start()161 err = r.exec.Start()162 r.mutex.Unlock()163 if err != nil {164 return false165 }166 r.feed(out)116 return listCommand.Wait() == nil167 return r.exec.Wait() == nil168}
modified:src/terminal.go+85 added-53 removed
58 unmodified lines
5960// Terminal represents terminal input/output61type Terminal struct {62 initDelay time.Duration63 inlineInfo bool63 infoStyle infoStyle64 prompt string65 promptLen int66 queryLen [2]int67 layout layoutType
33 unmodified lines
101 pwindow tui.Window102 count int103 progress int104 reading bool105 success bool105 failed *string106 jumping jumpMode107 jumpLabels string108 printer func(string)109 printsep string
117 unmodified lines
227 actExecuteSilent228 actExecuteMulti // Deprecated229 actSigStop230 actTop231 actReload232)233234type placeholderFlags struct {235 plus bool
2 unmodified lines
238 query bool239 file bool240}241242type searchRequest struct {243 sort bool244 command *string245}246247func toActions(types ...actionType) []action {248 actions := make([]action, len(types))249 for idx, t := range types {250 actions[idx] = action{t: t, a: ""}
109 unmodified lines
360 effectiveMinHeight := minHeight361 if previewBox != nil && (opts.Preview.position == posUp || opts.Preview.position == posDown) {362 effectiveMinHeight *= 2363 }358 if opts.InlineInfo {364 if opts.InfoStyle != infoDefault {365 effectiveMinHeight -= 1366 }367 if opts.Bordered {368 effectiveMinHeight += 2
10 unmodified lines
379 wordNext = fmt.Sprintf("[^%s]%s|(.$)", sep, sep)380 }381 t := Terminal{382 initDelay: delay,377 inlineInfo: opts.InlineInfo,383 infoStyle: opts.InfoStyle,384 queryLen: [2]int{0, 0},385 layout: opts.Layout,386 fullscreen: fullscreen,387 hscroll: opts.Hscroll,
25 unmodified lines
413 header0: header,414 ansi: opts.Ansi,415 tabstop: opts.Tabstop,416 reading: true,411 success: true,417 failed: nil,418 jumping: jumpDisabled,419 jumpLabels: opts.JumpLabels,420 printer: opts.Printer,421 printsep: opts.PrintSep,
15 unmodified lines
437 t.prompt, t.promptLen = t.processTabs([]rune(opts.Prompt), 0)438 return &t439}440441func (t *Terminal) noInfoLine() bool {442 return t.infoStyle != infoDefault443}444445// Input returns current query string446func (t *Terminal) Input() []rune {447 t.mutex.Lock()448 defer t.mutex.Unlock()449 return copySlice(t.input)450}451452// UpdateCount updates the count information443func (t *Terminal) UpdateCount(cnt int, final bool, success bool) {453func (t *Terminal) UpdateCount(cnt int, final bool, failedCommand *string) {454 t.mutex.Lock()455 t.count = cnt456 t.reading = !final447 t.success = success457 t.failed = failedCommand458 t.mutex.Unlock()459 t.reqBox.Set(reqInfo, nil)460 if final {461 t.reqBox.Set(reqRefresh, nil)
161 unmodified lines
623 }624 noBorder := tui.MakeBorderStyle(tui.BorderNone, t.unicode)625 if previewVisible {626 createPreviewWindow := func(y int, x int, w int, h int) {617 t.pborder = t.tui.NewWindow(y, x, w, h, tui.MakeBorderStyle(tui.BorderAround, t.unicode))627 previewBorder := tui.MakeBorderStyle(tui.BorderAround, t.unicode)628 if !t.preview.border {629 previewBorder = tui.MakeTransparentBorder()630 }631 t.pborder = t.tui.NewWindow(y, x, w, h, previewBorder)632 pwidth := w - 4633 // ncurses auto-wraps the line when the cursor reaches the right-end of634 // the window. To prevent unintended line-wraps, we use the width one635 // column larger than the desired value.
43 unmodified lines
679 case layoutDefault:680 y = h - y - 1681 case layoutReverseList:682 n := 2 + len(t.header)669 if t.inlineInfo {683 if t.noInfoLine() {684 n--685 }686 if y < n {687 y = h - y - 1
44 unmodified lines
732}733734func (t *Terminal) printInfo() {735 pos := 0722 if t.inlineInfo {736 switch t.infoStyle {737 case infoDefault:738 t.move(1, 0, true)739 if t.reading {740 duration := int64(spinnerDuration)741 idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration742 t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])743 }744 t.move(1, 2, false)745 pos = 2746 case infoInline:747 pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1748 if pos+len(" < ") > t.window.Width() {749 return750 }
3 unmodified lines
754 } else {755 t.window.CPrint(tui.ColPrompt, t.strong, " < ")756 }757 pos += len(" < ")734 } else {735 t.move(1, 0, true)736 if t.reading {737 duration := int64(spinnerDuration)738 idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration739 t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])740 }741 t.move(1, 2, false)742 pos = 2758 case infoHidden:759 return760 }761762 found := t.merger.Length()763 total := util.Max(found, t.count)745 output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count)764 output := fmt.Sprintf("%d/%d", found, total)765 if t.toggleSort {766 if t.sort {767 output += " +S"768 } else {
9 unmodified lines
778 }779 if t.progress > 0 && t.progress < 100 {780 output += fmt.Sprintf(" (%d%%)", t.progress)781 }763 if !t.success && t.count == 0 {764 if len(os.Getenv("FZF_DEFAULT_COMMAND")) > 0 {765 output = "[$FZF_DEFAULT_COMMAND failed]"766 } else {767 output = "[default command failed - $FZF_DEFAULT_COMMAND required]"768 }782 if t.failed != nil && t.count == 0 {783 output = fmt.Sprintf("[Command failed: %s]", *t.failed)784 }770 if pos+len(output) <= t.window.Width() {771 t.window.CPrint(tui.ColInfo, 0, output)785 maxWidth := t.window.Width() - pos786 if len(output) > maxWidth {787 outputRunes, _ := t.trimRight([]rune(output), maxWidth-2)788 output = string(outputRunes) + ".."789 }790 t.window.CPrint(tui.ColInfo, 0, output)791}792793func (t *Terminal) printHeader() {794 if len(t.header) == 0 {
2 unmodified lines
797 max := t.window.Height()798 var state *ansiState799 for idx, lineStr := range t.header {800 line := idx + 2783 if t.inlineInfo {801 if t.noInfoLine() {802 line--803 }804 if line >= max {805 continue
20 unmodified lines
826 if t.layout == layoutDefault {827 i = maxy - 1 - j828 }829 line := i + 2 + len(t.header)812 if t.inlineInfo {830 if t.noInfoLine() {831 line--832 }833 if i < count {834 t.printItem(t.merger.Get(i+t.offset), line, i, i == t.cy-t.offset)
565 unmodified lines
1400}14011402func (t *Terminal) currentItem() *Item {1403 cnt := t.merger.Length()1386 if cnt > 0 && cnt > t.cy {1404 if t.cy >= 0 && cnt > 0 && cnt > t.cy {1405 return t.merger.Get(t.cy).item1406 }1407 return nil1408}
30 unmodified lines
1439 if len(t.selected) >= t.multi {1440 return false1441 }1442 if _, found := t.selected[item.Index()]; found {1425 return false1443 return true1444 }14451446 t.selected[item.Index()] = selectedItem{time.Now(), item}1447 t.version++
77 unmodified lines
1525 for {1526 t.mutex.Lock()1527 reading := t.reading1528 t.mutex.Unlock()1511 if !reading {1512 break1513 }1529 time.Sleep(spinnerDuration)1530 if reading {1515 t.reqBox.Set(reqInfo, nil)1531 t.reqBox.Set(reqInfo, nil)1532 }1533 }1534 }()1535 }1536
12 unmodified lines
1549 })1550 // We don't display preview window if no match1551 if request[0] != nil {1552 command := replacePlaceholder(t.preview.command,1536 t.ansi, t.delimiter, t.printsep, false, string(t.input), request)1553 t.ansi, t.delimiter, t.printsep, false, string(t.Input()), request)1554 cmd := util.ExecCommand(command, true)1555 if t.pwindow != nil {1556 env := os.Environ()1557 lines := fmt.Sprintf("LINES=%d", t.pwindow.Height())
42 unmodified lines
1600 }()1601 }16021603 exit := func(getCode func() int) {1587 if !t.cleanExit && t.fullscreen && t.inlineInfo {1588 t.placeCursor()1589 }1604 t.tui.Close()1605 code := getCode()1606 if code <= exitNoMatch && t.history != nil {1607 t.history.append(string(t.input))
12 unmodified lines
1620 for req, value := range *events {1621 switch req {1622 case reqPrompt:1623 t.printPrompt()1610 if t.inlineInfo {1624 if t.noInfoLine() {1625 t.printInfo()1626 }1627 case reqInfo:1628 t.printInfo()
57 unmodified lines
1686 }()16871688 looping := true1689 for looping {1690 var newCommand *string1691 changed := false1692 queryChanged := false16931694 event := t.tui.GetChar()16951696 t.mutex.Lock()1697 previousInput := t.input
73 unmodified lines
1771 req(reqPreviewRefresh)1772 }1773 case actToggleSort:1774 t.sort = !t.sort1757 t.eventBox.Set(EvtSearchNew, t.sort)1758 t.mutex.Unlock()1759 return false1775 changed = true1776 case actPreviewUp:1777 if t.hasPreviewWindow() {1778 scrollPreview(-1)1779 }
222 unmodified lines
2002 mx -= t.window.Left()2003 my -= t.window.Top()2004 mx = util.Constrain(mx-t.promptLen, 0, len(t.input))2005 min := 2 + len(t.header)1990 if t.inlineInfo {2006 if t.noInfoLine() {2007 min--2008 }2009 h := t.window.Height()2010 switch t.layout {
29 unmodified lines
2040 return doActions(t.keymap[tui.RightClick], tui.RightClick)2041 }2042 }2043 }2044 case actReload:2045 t.failed = nil20462047 valid, list := t.buildPlusList(a.a, false)2048 // If the command template has {q}, we run the command even when the2049 // query string is empty.2050 if !valid {2051 _, query := hasPreviewFlags(a.a)2052 valid = query2053 }2054 if valid {2055 command := replacePlaceholder(a.a,2056 t.ansi, t.delimiter, t.printsep, false, string(t.input), list)2057 newCommand = &command2058 t.selected = make(map[int32]selectedItem)2059 }2060 }2061 return true2062 }2031 changed := false2063 mapkey := event.Type2064 if t.jumping == jumpDisabled {2065 actions := t.keymap[mapkey]2066 if mapkey == tui.Rune {
5 unmodified lines
2072 if !doActions(actions, mapkey) {2073 continue2074 }2075 t.truncateQuery()2045 changed = string(previousInput) != string(t.input)2046 if onChanges, prs := t.keymap[tui.Change]; changed && prs {2076 queryChanged = string(previousInput) != string(t.input)2077 changed = changed || queryChanged2078 if onChanges, prs := t.keymap[tui.Change]; queryChanged && prs {2079 if !doActions(onChanges, tui.Change) {2080 continue2081 }2082 }
9 unmodified lines
2092 t.jumping = jumpDisabled2093 req(reqList)2094 }20952064 if changed {2096 if queryChanged {2097 if t.isPreviewEnabled() {2098 _, q := hasPreviewFlags(t.preview.command)2099 if q {2100 t.version++2101 }2102 }2103 }21042073 if changed || t.cx != previousCx {2105 if queryChanged || t.cx != previousCx {2106 req(reqPrompt)2107 }21082109 t.mutex.Unlock() // Must be unlocked before touching reqBox21102079 if changed {2080 t.eventBox.Set(EvtSearchNew, t.sort)2111 if changed || newCommand != nil {2112 t.eventBox.Set(EvtSearchNew, searchRequest{sort: t.sort, command: newCommand})2113 }2114 for _, event := range events {2115 t.reqBox.Set(event, nil)2116 }
41 unmodified lines
2158}21592160func (t *Terminal) maxItems() int {2161 max := t.window.Height() - 2 - len(t.header)2130 if t.inlineInfo {2162 if t.noInfoLine() {2163 max++2164 }2165 return util.Max(max, 0)2166}
modified:test/test_go.rb+29 added-1 removed
275 unmodified lines
276 end277278 def test_fzf_default_command_failure279 tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter280 tmux.until { |lines| lines[-2].include?('FZF_DEFAULT_COMMAND failed') }280 tmux.until { |lines| lines[-2].include?('Command failed: false') }281 tmux.send_keys :Enter282 end283284 def test_key_bindings
1230 unmodified lines
1515 tmux.until { |_| %w[1] == File.readlines(tempname).map(&:chomp) }1516 tmux.until { |lines| lines[-1] == prompt }1517 end15181519 def test_info_hidden1520 tmux.send_keys 'seq 10 | fzf --info=hidden', :Enter1521 tmux.until { |lines| lines[-2] == '> 1' }1522 end15231524 def test_change_top1525 tmux.send_keys %(seq 1000 | #{FZF} --bind change:top), :Enter1526 tmux.until { |lines| lines.match_count == 1000 }1527 tmux.send_keys :Up
88 unmodified lines
1616 writelines tempname, ["\x1b[31m+\x1b[m\t\x1b[32mgreen"]1617 tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter1618 tmux.until { |lines| lines[1].include?('+ green') }1619 end16201621 def test_phony1622 tmux.send_keys %(seq 1000 | #{FZF} --query 333 --phony --preview 'echo {} {q}'), :Enter1623 tmux.until { |lines| lines.match_count == 1000 }1624 tmux.until { |lines| lines[1].include?('1 333') }1625 tmux.send_keys 'foo'1626 tmux.until { |lines| lines.match_count == 1000 }1627 tmux.until { |lines| lines[1].include?('1 333foo') }1628 end16291630 def test_reload1631 tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq {q}),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter1632 tmux.until { |lines| lines.match_count == 998 }1633 tmux.send_keys 'a'1634 tmux.until { |lines| lines.item_count == 98 && lines.match_count == 98 }1635 tmux.send_keys 'b'1636 tmux.until { |lines| lines.item_count == 198 && lines.match_count == 198 }1637 tmux.send_keys :Tab1638 tmux.until { |lines| lines[-2].include?('(1/2)') }1639 tmux.send_keys '555'1640 tmux.until { |lines| lines.item_count == 553 && lines.match_count == 1 }1641 tmux.until { |lines| !lines[-2].include?('(1/2)') }1642 end1643end16441645module TestShell1646 def setup
370 unmodified lines
modified:CHANGELOG.md+51 added
1CHANGELOG2=========340.19.05------67- Added "reload" action for dynamically updating the input list without8 restarting fzf. See https://github.com/junegunn/fzf/issues/1750 to learn9 more about it.10 ```sh11 # Using fzf as the selector interface for ripgrep12 RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "13 INITIAL_QUERY="foo"14 FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \15 fzf --bind "change:reload:$RG_PREFIX {q} || true" \16 --ansi --phony --query "$INITIAL_QUERY"17 ```18- `--multi` now takes an optional integer argument which indicates the maximum19 number of items that can be selected20 ```sh21 seq 100 | fzf --multi 3 --reverse --height 50%22 ```23- If a placeholder expression for `--preview` and `execute` action (and the24 new `reload` action) contains `f` flag, it is replaced to the25 path of a temporary file that holds the evaluated list. This is useful26 when you multi-select a large number of items and the length of the27 evaluated string may exceed [`ARG_MAX`][argmax].28 ```sh29 # Press CTRL-A to select 100K items and see the sum of all the numbers30 seq 100000 | fzf --multi --bind ctrl-a:select-all \31 --preview "awk '{sum+=\$1} END {print sum}' {+f}"32 ```33- `deselect-all` no longer deselects unmatched items. It is now consistent34 with `select-all` and `toggle-all` in that it only affects matched items.35- Due to the limitation of bash, fuzzy completion is enabled by default for36 a fixed set of commands. A helper function for easily setting up fuzzy37 completion for any command is now provided.38 ```sh39 # usage: _fzf_setup_completion path|dir COMMANDS...40 _fzf_setup_completion path git kubectl41 ```42- Info line style can be changed by `--info=STYLE`43 - `--info=default`44 - `--info=inline` (same as old `--inline-info`)45 - `--info=hidden`46- Preview window border can be disabled by adding `noborder` to47 `--preview-window`.48- When you transform the input with `--with-nth`, the trailing white spaces49 are removed.50- `ctrl-\`, `ctrl-]`, `ctrl-^`, and `ctrl-/` can now be used with `--bind`51- See https://github.com/junegunn/fzf/milestone/15?closed=1 for more details5253[argmax]: https://unix.stackexchange.com/questions/120642/what-defines-the-maximum-size-for-a-command-single-argument54550.18.056------5758- Added placeholder expression for zero-based item index: `{n}` and `{+n}`
707 unmodified lines