Skip to content

Latest commit

 

History

History
138 lines (98 loc) · 2.88 KB

fuzzy.md

File metadata and controls

138 lines (98 loc) · 2.88 KB

fuzzy

A prompt that lists choices to select while also allowing fuzzy search like fzf.

Example

The following example will download a sample file and demos the performance of searching with 100k words.

demo

Classic Syntax (PyInquirer)
.. literalinclude :: ../../../examples/classic/fuzzy.py
   :language: python
Alternate Syntax
.. literalinclude :: ../../../examples/alternate/fuzzy.py
   :language: python

Choices

{ref}`pages/dynamic:choices`
This prompt does not accepts choices containing {ref}`pages/separator:Separator` instances.

Keybindings

{ref}`pages/kb:Keybindings`
This prompt does not enable `j/k` navigation when `vi_mode` is `True`. When `vi_mode` is `True` in fuzzy prompt, the input buffer
will become vim input mode, no other keybindings are altered.

The `space` key for toggle choice is also disabled since it blocks user from typing space in the input buffer.
:start-after: <!-- start kb -->
:end-before: <!-- end kb -->
:start-after: <!-- start list kb -->
:end-before: <!-- end list kb -->

Multiple Selection

{ref}`pages/prompts/list:Multiple Selection`

Default Value

{ref}`pages/dynamic:default`

The default parameter for this prompt will set the default search text in the input buffer (sort of replicate the behavior of fzf).

If you wish to pre-select certain choices, you can leverage the enabled parameter/key of each choice.

from InquirerPy.base import Choice

choices = [
    Choice(1, enabled=True),  # enabled by default
    Choice(2)  # not enabled
]

Exact Sub-String Match

This prompt uses the fzy fuzzy match algorithm by default. You can enable exact sub-string match by using the parameter match_exact.

Classic Syntax (PyInquirer)
from InquirerPy import prompt

questions = [
    {
        "type": "fuzzy",
        "message": "Select actions:",
        "choices": ["hello", "weather", "what", "whoa", "hey", "yo"],
        "match_exact": True,
        "exact_symbol": " E",   # indicator of exact match
    },
]

result = prompt(questions=questions)
Alternate Syntax
from InquirerPy import inquirer

result = inquirer.fuzzy(
    message="Select actions:",
    choices=["hello", "weather", "what", "whoa", "hey", "yo"],
    match_exact=True,
    exact_symbol=" E",  # indicator of exact match
).execute()

Reference

.. autoclass:: InquirerPy.prompts.fuzzy.FuzzyPrompt
    :noindex: