A prompt that lists choices to select while also allowing fuzzy search like fzf.
The following example will download a sample file and demos the performance of searching with 100k words.
Classic Syntax (PyInquirer)
.. literalinclude :: ../../../examples/classic/fuzzy.py
:language: python
Alternate Syntax
.. literalinclude :: ../../../examples/alternate/fuzzy.py
:language: python
{ref}`pages/dynamic:choices`
This prompt does not accepts choices containing {ref}`pages/separator:Separator` instances.
{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 -->
{ref}`pages/prompts/list:Multiple Selection`
{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
]
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()
.. autoclass:: InquirerPy.prompts.fuzzy.FuzzyPrompt
:noindex: