Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix filter search #42

Closed
wants to merge 5 commits into from
Closed

Conversation

gbataille
Copy link

Fixes #33

Here is a first implementation

  • it is optional, off by default to not change current behavior
  • when active, vi-like navigation (j and k) is disabled
  • when active, typing any character will add this character to the search filter
  • when active, backspace is supported to remove the last input character. If the filter is empty, no filter is applied
  • when the filter changes, since the displayed elements change, the cursor goes back to the top, position 0

A possible alternative would be to activate the search only on a certain key, let's say / or Ctrl+F. Doing so, the select control could "change mode" like vi would, and any key type from then on, would go to the filter. Esc could clear the filter. Enter could either select the current entry or validate the filter and go back to navigation mode. Like that, we would not have to disable vi-like navigation.

WDYT?

Note: I'd like some tests on what is displayed. I tried with a prompt-toolkit Output but the string rendered is a bit messy and validation would be awkward. I think it might be worth adding tests directly to the InquirerControl and the tokens it returns or the prompt-toolkit Layout it calls.
I might have a look into it if/when we agree on the implementation for this feature

@gbataille gbataille requested a review from tmbo February 3, 2020 08:19
@gbataille
Copy link
Author

did not check black :(
will do later.

@boh717
Copy link

boh717 commented May 5, 2020

It would be cool having this merged!
Any blockers?

@kiancross
Copy link
Collaborator

@gbataille Do you have time to fix the code style? You just need to run black questionary over the code.

@kiancross kiancross added the Enhancement New feature or request label Sep 8, 2020
@gbataille
Copy link
Author

gbataille commented Sep 9, 2020 via email

from prompt_toolkit.layout import (
FormattedTextControl,
Layout,
HSplit,
ConditionalContainer,
Window,
)
from prompt_toolkit.layout.dimension import LayoutDimension as D
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better not to import as D and instead use the full LayoutDimension identifier.

@kiancross kiancross added the Awaiting response Additional information is required label Sep 15, 2020
@kiancross
Copy link
Collaborator

@gbataille If you are busy, do you mind if I finish off this PR so that we can get it merged?

@gbataille
Copy link
Author

gbataille commented Dec 21, 2020 via email

@kiancross kiancross removed the Awaiting response Additional information is required label Dec 24, 2020
@falko-apheris
Copy link

I would love to see this feature! Thanks for the effort @gbataille

@rajatm91
Copy link

rajatm91 commented Jul 18, 2023

Would love to see this feature. Any plans on merging this ?

@kiancross
Copy link
Collaborator

Would love to see this feature. Any plans on merging this ?

It would be good to get this merged, but there is a bit of work to do on the PR before that's possible. Unfortunately, I don't have time at the moment (but if anyone else does, feel free to work on it!).

@lucasrodes
Copy link

Hi, just here to say that your library is amazing, and this feature would make it just perfect.

Thanks!

mario-dg pushed a commit to mario-dg/questionary that referenced this pull request May 29, 2024
@mario-dg
Copy link
Contributor

I've just created a new PR to further address this issue by adding it to the checkbox prompt aswell. I really want to get this merged 😄

kiancross pushed a commit that referenced this pull request Jul 24, 2024
…#42 (#374)

* feat: add search functionality to select and checkbox prompt

This commit is heavily inspired by [gbataille's](https://github.com/gbataille) [PR](#42)

* chore: bump minor version, because of new feature

* chore: bump version in pyproject.toml

* feat: changed prefix filter to search filter, allow all/invert with ctrl

Instead of a prefix filter, the search filter is now searched within all entries. This seems to be more common than a prefix search.

Using the search functionality disabled the ability to select all options or invert the selection in the checkbox control. If the search filter is enabled, these two functionalities can now be used with the key modifier ctrl.

Updated the displayed instructions to match the changes made.

* fix: reverted version bump

---------

Co-authored-by: mario-dg <[email protected]>
@kiancross
Copy link
Collaborator

Closed by #374.

@kiancross kiancross closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add prefix filter search in select control
7 participants