Skip to content
Myr

Make search toggleable

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

- `--phony` renamed to `--disabled` for consistency - `--no-phony` is now `--enabled` - Added `enable-search`, `disable-search`, and `toggle-search` actions for `--bind` - Added `--color` options: `query` and `disabled` Close #2303

authored by Junegunn Choi · committed by Junegunn Choi · parent fd8858f · Browse files · 10 files+132 added−49 removed
This commit

State

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

Diff stats

10 files+132 added−49 removed

  • tests:+24 added−2 removed
  • other:+108 added−47 removed

10 files+132 added−49 removed

modified:doc/fzf.txt+20 added-16 removed
1fzf.txt fzf Last change: December 31 20201fzf.txt fzf Last change: January 2 20212FZF - TABLE OF CONTENTS *fzf* *fzf-toc*3==============================================================================45 FZF Vim integration |fzf-vim-integration|
193 unmodified lines
199 element: [ component, group1 [, group2, ...] ]200<201 - `element` is an fzf element to apply a color to:202203 ----------------------+------------------------------------------------------204 Element | Description ~205 ----------------------+------------------------------------------------------206 `fg` / `bg` / `hl` | Item (foreground / background / highlight)207 `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight)208 `hl` / `hl+` | Highlighted substrings (normal / current)209 `gutter` | Background of the gutter on the left210 `pointer` | Pointer to the current line ( `>` )211 `marker` | Multi-select marker ( `>` )212 `border` | Border around the window ( `--border` and `--preview` )213 `header` | Header ( `--header` or `--header-lines` )214 `info` | Info line (match counters)215 `spinner` | Streaming input indicator216 `prompt` | Prompt before query ( `> ` )217 ----------------------+------------------------------------------------------203 ----------------------------+------------------------------------------------------204 Element | Description ~205 ----------------------------+------------------------------------------------------206 `fg` / `bg` / `hl` | Item (foreground / background / highlight)207 `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight)208 `preview-fg` / `preview-bg` | Preview window text and background209 `hl` / `hl+` | Highlighted substrings (normal / current)210 `gutter` | Background of the gutter on the left211 `pointer` | Pointer to the current line ( `>` )212 `marker` | Multi-select marker ( `>` )213 `border` | Border around the window ( `--border` and `--preview` )214 `header` | Header ( `--header` or `--header-lines` )215 `info` | Info line (match counters)216 `spinner` | Streaming input indicator217 `query` | Query string218 `disabled` | Query string when search is disabled219 `prompt` | Prompt before query ( `> ` )220 `pointer` | Pointer to the current line ( `>` )221 ----------------------------+------------------------------------------------------222 - `component` specifies the component (`fg` / `bg`) from which to extract the223 color when considering each of the following highlight groups224 - `group1 [, group2, ...]` is a list of highlight groups that are searched (in225 order) for a matching color definition
241 unmodified lines
modified:man/man1/fzf-tmux.1+1 added-1 removed
19 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 "Dec 2020" "fzf 0.24.4" "fzf-tmux - open fzf in tmux split pane"24.TH fzf-tmux 1 "Jan 2021" "fzf 0.25.0" "fzf-tmux - open fzf in tmux split pane"2526.SH NAME27fzf-tmux - open fzf in tmux split pane28
40 unmodified lines
modified:man/man1/fzf.1+10 added-4 removed
19 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 "Dec 2020" "fzf 0.24.5" "fzf - a command-line fuzzy finder"24.TH fzf 1 "Jan 2021" "fzf 0.25.0" "fzf - a command-line fuzzy finder"2526.SH NAME27fzf - a command-line fuzzy finder28
41 unmodified lines
70.TP71.BI "-d, --delimiter=" "STR"72Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)73.TP74.BI "--phony"74.BI "--disabled"75Do not perform search. With this option, fzf becomes a simple selector76interface rather than a "fuzzy finder".76interface rather than a "fuzzy finder". You can later enable the search using77\fBenable-search\fR or `\fBtoggle-search\R action.78.SS Search result79.TP80.B "+s, --no-sort"81Do not sort the result
241 unmodified lines
323 \fBfg+ \fRText (current line)324 \fBbg+ \fRBackground (current line)325 \fBgutter \fRGutter on the left (defaults to \fBbg+\fR)326 \fBhl+ \fRHighlighted substrings (current line)327 \fBquery \fRQuery string328 \fBdisabled \fRQuery string when search is disabled329 \fBinfo \fRInfo line (match counters)330 \fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR)331 \fBprompt \fRPrompt332 \fBpointer \fRPointer to the current line
449 unmodified lines
782 \fBclear-query\fR (clear query string)783 \fBdelete-char\fR \fIdel\fR784 \fBdelete-char/eof\fR \fIctrl-d\fR (same as \fBdelete-char\fR except aborts fzf if query is empty)785 \fBdeselect-all\fR (deselect all matches)786 \fBdisable-search\fR (disable search functionality)787 \fBdown\fR \fIctrl-j ctrl-n down\fR788 \fBenable-search\fR (enable search functionality)789 \fBend-of-line\fR \fIctrl-e end\fR790 \fBexecute(...)\fR (see below for the details)791 \fBexecute-silent(...)\fR (see below for the details)792 \fBfirst\fR (move to the first match)
31 unmodified lines
824 \fBtoggle-in\fR (\fB--layout=reverse*\fR ? \fBtoggle+up\fR : \fBtoggle+down\fR)825 \fBtoggle-out\fR (\fB--layout=reverse*\fR ? \fBtoggle+down\fR : \fBtoggle+up\fR)826 \fBtoggle-preview\fR827 \fBtoggle-preview-wrap\fR828 \fBtoggle-search\fR (toggle search functionality)829 \fBtoggle-sort\fR830 \fBtoggle+up\fR \fIbtab (shift-tab)\fR831 \fBunix-line-discard\fR \fIctrl-u\fR832 \fBunix-word-rubout\fR \fIctrl-w\fR
74 unmodified lines
907 RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "908 INITIAL_QUERY="foobar"909 FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \\910 fzf --bind "change:reload:$RG_PREFIX {q} || true" \\905 --ansi --phony --query "$INITIAL_QUERY"\fR911 --ansi --disabled --query "$INITIAL_QUERY"\fR912913.SS PREVIEW BINDING914915With \fBpreview(...)\fR action, you can specify multiple different preview
33 unmodified lines
modified:src/tui/tui.go+9 added
248 unmodified lines
249250type ColorTheme struct {251 Colored bool252 Input ColorAttr253 Disabled ColorAttr254 Fg ColorAttr255 Bg ColorAttr256 PreviewFg ColorAttr257 PreviewBg ColorAttr
163 unmodified lines
421422 ColPrompt ColorPair423 ColNormal ColorPair424 ColInput ColorPair425 ColDisabled ColorPair426 ColMatch ColorPair427 ColCursor ColorPair428 ColCursorEmpty ColorPair429 ColSelected ColorPair
14 unmodified lines
444func EmptyTheme() *ColorTheme {445 return &ColorTheme{446 Colored: true,447 Input: ColorAttr{colUndefined, AttrUndefined},448 Disabled: ColorAttr{colUndefined, AttrUndefined},449 Fg: ColorAttr{colUndefined, AttrUndefined},450 Bg: ColorAttr{colUndefined, AttrUndefined},451 PreviewFg: ColorAttr{colUndefined, AttrUndefined},452 PreviewBg: ColorAttr{colUndefined, AttrUndefined},
14 unmodified lines
467func NoColorTheme() *ColorTheme {468 return &ColorTheme{469 Colored: false,470 Input: ColorAttr{colDefault, AttrRegular},471 Disabled: ColorAttr{colDefault, AttrRegular},472 Fg: ColorAttr{colDefault, AttrRegular},473 Bg: ColorAttr{colDefault, AttrRegular},474 PreviewFg: ColorAttr{colDefault, AttrRegular},475 PreviewBg: ColorAttr{colDefault, AttrRegular},
19 unmodified lines
495func init() {496 Default16 = &ColorTheme{497 Colored: true,498 Input: ColorAttr{colDefault, AttrUndefined},499 Disabled: ColorAttr{colUndefined, AttrUndefined},500 Fg: ColorAttr{colDefault, AttrUndefined},501 Bg: ColorAttr{colDefault, AttrUndefined},502 PreviewFg: ColorAttr{colUndefined, AttrUndefined},503 PreviewBg: ColorAttr{colUndefined, AttrUndefined},
11 unmodified lines
515 Border: ColorAttr{colBlack, AttrUndefined}}516 Dark256 = &ColorTheme{517 Colored: true,518 Input: ColorAttr{colDefault, AttrUndefined},519 Disabled: ColorAttr{colUndefined, AttrUndefined},520 Fg: ColorAttr{colDefault, AttrUndefined},521 Bg: ColorAttr{colDefault, AttrUndefined},522 PreviewFg: ColorAttr{colUndefined, AttrUndefined},523 PreviewBg: ColorAttr{colUndefined, AttrUndefined},
11 unmodified lines
535 Border: ColorAttr{59, AttrUndefined}}536 Light256 = &ColorTheme{537 Colored: true,538 Input: ColorAttr{colDefault, AttrUndefined},539 Disabled: ColorAttr{colUndefined, AttrUndefined},540 Fg: ColorAttr{colDefault, AttrUndefined},541 Bg: ColorAttr{colDefault, AttrUndefined},542 PreviewFg: ColorAttr{colUndefined, AttrUndefined},543 PreviewBg: ColorAttr{colUndefined, AttrUndefined},
26 unmodified lines
570 }571 return c572 }573 theme.Input = o(baseTheme.Input, theme.Input)574 theme.Disabled = o(theme.Input, o(baseTheme.Disabled, theme.Disabled))575 theme.Fg = o(baseTheme.Fg, theme.Fg)576 theme.Bg = o(baseTheme.Bg, theme.Bg)577 theme.PreviewFg = o(theme.Fg, o(baseTheme.PreviewFg, theme.PreviewFg))578 theme.PreviewBg = o(theme.Bg, o(baseTheme.PreviewBg, theme.PreviewBg))
25 unmodified lines
604605 ColPrompt = pair(theme.Prompt, theme.Bg)606 ColNormal = pair(theme.Fg, theme.Bg)607 ColInput = pair(theme.Input, theme.Bg)608 ColDisabled = pair(theme.Disabled, theme.Bg)609 ColMatch = pair(theme.Match, theme.Bg)610 ColCursor = pair(theme.Cursor, theme.Gutter)611 ColCursorEmpty = pair(blank, theme.Gutter)612 ColSelected = pair(theme.Selected, theme.Gutter)
13 unmodified lines
modified:src/core.go+5 added-3 removed
235 unmodified lines
236 header = make([]string, 0, opts.HeaderLines)237 go reader.restart(command)238 }239 eventBox.Watch(EvtReadNew)240 query := []rune{}241 for {242 delay := true243 ticks++244 input := func() []rune {244 if opts.Phony {245 return []rune{}245 paused, input := terminal.Input()246 if !paused {247 query = input248 }247 return []rune(terminal.Input())249 return query250 }251 eventBox.Wait(func(events *util.Events) {252 if _, fin := (*events)[EvtReadFin]; fin {253 delete(*events, EvtReadNew)
93 unmodified lines
modified:src/options.go+12 added-4 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 search36 --disabled 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
640 unmodified lines
681 }682 }683 }684 switch components[0] {685 case "input":685 case "query", "input":686 mergeAttr(&theme.Input)687 case "disabled":688 mergeAttr(&theme.Disabled)689 case "fg":690 mergeAttr(&theme.Fg)691 case "bg":692 mergeAttr(&theme.Bg)
183 unmodified lines
876 case "toggle-out":877 appendAction(actToggleOut)878 case "toggle-all":879 appendAction(actToggleAll)880 case "toggle-search":881 appendAction(actToggleSearch)882 case "select-all":883 appendAction(actSelectAll)884 case "deselect-all":885 appendAction(actDeselectAll)
40 unmodified lines
926 case "preview-half-page-up":927 appendAction(actPreviewHalfPageUp)928 case "preview-half-page-down":929 appendAction(actPreviewHalfPageDown)930 case "enable-search":931 appendAction(actEnableSearch)932 case "disable-search":933 appendAction(actDisableSearch)934 default:935 t := isExecuteAction(specLower)936 if t == actIgnore {937 if specIndex == 0 && specLower == "" {
268 unmodified lines
1206 opts.Expect[k] = v1207 }1208 case "--no-expect":1209 opts.Expect = make(map[tui.Event]string)1202 case "--no-phony":1210 case "--enabled", "--no-phony":1211 opts.Phony = false1204 case "--phony":1212 case "--disabled", "--phony":1213 opts.Phony = true1214 case "--tiebreak":1215 opts.Criteria = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))1216 case "--bind":
383 unmodified lines
modified:src/terminal.go+26 added-5 removed
123 unmodified lines
124 strong tui.Attr125 unicode bool126 borderShape tui.BorderShape127 cleanExit bool128 paused bool129 border tui.Window130 window tui.Window131 pborder tui.Window132 pwindow tui.Window
100 unmodified lines
233 actBackwardKillWord234 actSelectAll235 actDeselectAll236 actToggle237 actToggleSearch238 actToggleAll239 actToggleDown240 actToggleUp241 actToggleIn
29 unmodified lines
271 actSigStop272 actFirst273 actLast274 actReload275 actDisableSearch276 actEnableSearch277)278279type placeholderFlags struct {280 plus bool
210 unmodified lines
491 padding: opts.Padding,492 unicode: opts.Unicode,493 borderShape: opts.BorderShape,494 cleanExit: opts.ClearOnExit,495 paused: opts.Phony,496 strong: strongAttr,497 cycle: opts.Cycle,498 header: header,499 header0: header,
67 unmodified lines
567 return t.infoStyle != infoDefault568}569570// Input returns current query string566func (t *Terminal) Input() []rune {571func (t *Terminal) Input() (bool, []rune) {572 t.mutex.Lock()573 defer t.mutex.Unlock()569 return copySlice(t.input)574 return t.paused, copySlice(t.input)575}576577// UpdateCount updates the count information578func (t *Terminal) UpdateCount(cnt int, final bool, failedCommand *string) {
350 unmodified lines
929 t.move(0, 0, true)930 t.prompt()931932 before, after := t.updatePromptOffset()933 color := tui.ColInput934 if t.paused {935 color = tui.ColDisabled936 }928 t.window.CPrint(tui.ColInput, string(before))929 t.window.CPrint(tui.ColInput, string(after))937 t.window.CPrint(color, string(before))938 t.window.CPrint(color, string(after))939}940941func (t *Terminal) trimMessage(message string, maxWidth int) string {942 if len(message) <= maxWidth {
945 unmodified lines
1888 })1889 version++1890 // We don't display preview window if no match1891 if items[0] != nil {1892 _, query := t.Input()1883 command := t.replacePlaceholder(commandTemplate, false, string(t.Input()), items)1893 command := t.replacePlaceholder(commandTemplate, false, string(query), items)1894 initialOffset := 01895 cmd := util.ExecCommand(command, true)1896 if pwindow != nil {1897 height := pwindow.Height()
576 unmodified lines
2474 t.history.override(string(t.input))2475 t.input = trimQuery(t.history.next())2476 t.cx = len(t.input)2477 }2478 case actToggleSearch:2479 t.paused = !t.paused2480 changed = !t.paused2481 req(reqPrompt)2482 case actEnableSearch:2483 t.paused = false2484 changed = true2485 req(reqPrompt)2486 case actDisableSearch:2487 t.paused = true2488 req(reqPrompt)2489 case actSigStop:2490 p, err := os.FindProcess(os.Getpid())2491 if err == nil {2492 t.tui.Clear()
185 unmodified lines
modified:test/test_go.rb+24 added-2 removed
1656 unmodified lines
1657 tmux.send_keys "#{FZF} --preview 'cat #{tempname}'", :Enter1658 tmux.until { |lines| assert_includes lines[1], ' + green ' }1659 end16601661 def test_phony1662 tmux.send_keys %(seq 1000 | #{FZF} --query 333 --phony --preview 'echo {} {q}'), :Enter1661 def test_disabled1662 tmux.send_keys %(seq 1000 | #{FZF} --query 333 --disabled --bind a:enable-search,b:disable-search,c:toggle-search --preview 'echo {} {q}'), :Enter1663 tmux.until { |lines| assert_equal 1000, lines.match_count }1664 tmux.until { |lines| assert_includes lines[1], ' 1 333 ' }1665 tmux.send_keys 'foo'1666 tmux.until { |lines| assert_equal 1000, lines.match_count }1667 tmux.until { |lines| assert_includes lines[1], ' 1 333foo ' }16681669 # Already disabled, no change1670 tmux.send_keys 'b'1671 tmux.until { |lines| assert_equal 1000, lines.match_count }16721673 # Enable search1674 tmux.send_keys 'a'1675 tmux.until { |lines| assert_equal 0, lines.match_count }1676 tmux.send_keys :BSpace, :BSpace, :BSpace1677 tmux.until { |lines| assert_equal 1, lines.match_count }1678 tmux.until { |lines| assert_includes lines[1], ' 333 333 ' }16791680 # Toggle search -> disabled again, but retains the previous result1681 tmux.send_keys 'c'1682 tmux.send_keys 'foo'1683 tmux.until { |lines| assert_includes lines[1], ' 333 333foo ' }1684 tmux.until { |lines| assert_equal 1, lines.match_count }16851686 # Enabled, no match1687 tmux.send_keys 'c'1688 tmux.until { |lines| assert_equal 0, lines.match_count }1689 tmux.until { |lines| assert_includes lines[1], ' 333foo ' }1690 end16911692 def test_reload1693 tmux.send_keys %(seq 1000 | #{FZF} --bind 'change:reload(seq {q}),a:reload(seq 100),b:reload:seq 200' --header-lines 2 --multi 2), :Enter
654 unmodified lines
modified:CHANGELOG.md+8 added-1 removed
1CHANGELOG2=========340.24.540.25.05------6- Text attributes set in `--color` are not reset when fzf sees another7 `--color` option for the same element. This allows you to put custom text8 attributes in your `$FZF_DEFAULT_OPTS` and still have those attributes
13 unmodified lines
2223 # Write "regular" if you want to clear the attributes24 fzf --color hl:176:regular,hl+:177:regular25 ```26- Renamed `--phony` to `--disabled`27- You can dynamically enable and disable the search functionality using the28 new `enable-search`, `disable-search`, and `toggle-search` actions29- You can assign a different color to the query string for when search is disabled30 ```sh31 fzf --color query:#ffffff,disabled:#999999 --bind space:toggle-search32 ```33- Added `last` action to move the cursor to the last match34 - The opposite action `top` is renamed to `first`, but `top` is still35 recognized as a synonym for backward compatibility36- Added `preview-top` and `preview-bottom` actions
1040 unmodified lines
modified:README-VIM.md+17 added-13 removed
169 unmodified lines
170 element: [ component, group1 [, group2, ...] ]171172- `element` is an fzf element to apply a color to:173174 | Element | Description |175 | --- | --- |176 | `fg` / `bg` / `hl` | Item (foreground / background / highlight) |177 | `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight) |178 | `hl` / `hl+` | Highlighted substrings (normal / current) |179 | `gutter` | Background of the gutter on the left |180 | `pointer` | Pointer to the current line (`>`) |181 | `marker` | Multi-select marker (`>`) |182 | `border` | Border around the window (`--border` and `--preview`) |183 | `header` | Header (`--header` or `--header-lines`) |184 | `info` | Info line (match counters) |185 | `spinner` | Streaming input indicator |186 | `prompt` | Prompt before query (`> `) |174 | Element | Description |175 | --- | --- |176 | `fg` / `bg` / `hl` | Item (foreground / background / highlight) |177 | `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight) |178 | `preview-fg` / `preview-bg` | Preview window text and background |179 | `hl` / `hl+` | Highlighted substrings (normal / current) |180 | `gutter` | Background of the gutter on the left |181 | `pointer` | Pointer to the current line (`>`) |182 | `marker` | Multi-select marker (`>`) |183 | `border` | Border around the window (`--border` and `--preview`) |184 | `header` | Header (`--header` or `--header-lines`) |185 | `info` | Info line (match counters) |186 | `spinner` | Streaming input indicator |187 | `query` | Query string |188 | `disabled` | Query string when search is disabled |189 | `prompt` | Prompt before query (`> `) |190 | `pointer` | Pointer to the current line (`>`) |191192- `component` specifies the component (`fg` / `bg`) from which to extract the193 color when considering each of the following highlight groups194
258 unmodified lines