-
Notifications
You must be signed in to change notification settings - Fork 96
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
Added a search feature for List() #524
base: main
Are you sure you want to change the base?
Conversation
Thank you very much for this. This feature has been on the ToDo list for quite some time. However in the current example there is not way to correct or go back on the typed stuff. I think it would make sens if BACKSAPCE would work or something similar, in case someone makes a type. Also documentation would be nice, even if its not beeing deployed at the moment |
also some pre-commit stuff fails |
Hello, Actually I've implemented the backspace deletion. Did you test and didn't it work ? I'll check why nox fails tomorrow. |
Yes I tested the provided example on windows and it didn't seem to work. The its the |
Okay I fixed the backspace handling for windows, and i made it flake8 compliant. |
Hello, could you check my pr ? |
Sorry for the delay but I am on holiday until 24. Of February. But its on the todo list for when I am back |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this for a bit, I feel likie this adds a lot of complexity where it makes the howle thing quite unflexible. I think it should be up to the user/developer to implement the parsing logic that handles combining multile keypresses. That would give much more flexibility for different scenarios and make it much simpler and cleaner inside the libary. (for example, right now navigation via arrow keys and use of DEL, not BACKSPACE, is not implemendet. But is also probabyl overcomplication)
I would suggest we implement the matcher
with the following callback signature. passing in the full list of choices and the current key. The user can implment what he wants and returnes the index the list should jump to (current
).
def matcher(choices: list, pressedkey: str) -> int
What do you think?
also sidenote for the future: Rebasing onto the new state of main doesn't produce a bunch of merge-commits |
Sure that would cover more use cases. I'll try to implement that this week. |
Okay i changed the |
Hello,
This adds two features to the List():
matcher
function, the user can now select an entry by typing it, without keyboard arrows. Thematcher
function takes a "choice" and the "user query", and returns a boolean. On every keystroke (if the associated key is a letter), the first "choice" for which thematcher
function returned True will become the current selected one. If nothing matches, the current item remains the same.search=True
(False by default), if amatcher
function is defined, then the user search will be visible (using the already existing and unusedget_current_value
method)If the
choices
array contains tuples, it is the responsability of the user to provide amatcher
function that handles tuple instead on string.I've provided unit test and example in the commit. Hope this is clean enough. Please let me know if anything is unclear or if my implementation can be improved. If no
matcher
function is provided, the code behave exactly as before my commit.