-
Notifications
You must be signed in to change notification settings - Fork 780
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
Input completion suggestions #2604
Conversation
Video please! |
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.
Think we need to go over this one. Chat about it today?
Ping me when you're available. |
Thanks for your guidance @willmcgugan. |
Looking good so far! Will do a review post lunch. Can you add a video? |
Short video showing the suggestions in action with an artificial sleep of 2s when computing the suggestion to show caching in action: Screen.Recording.2023-05-23.at.14.47.16.movExample appfrom textual.app import App, ComposeResult
from textual.suggester import SuggestFromList
from textual.widgets import Input
fruits = ["apple", "pear", "mango", "peach", "strawberry", "blueberry", "banana"]
class FruitsApp(App[None]):
def compose(self) -> ComposeResult:
yield Input(suggester=SuggestFromList(fruits))
if __name__ == "__main__":
app = FruitsApp()
app.run() |
Related comments: #2604 (comment)
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.
This is great! But we've had a discussion in the office, and I think we need to handle both case sensitive and case insensitive suggestions.
Let's have a chat about it tomorrow.
src/textual/suggester.py
Outdated
cache: FIFOCache[str, str | None] | None | ||
"""Suggestion cache, if used.""" | ||
|
||
def __init__(self, use_cache: bool = True): |
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.
Should have -> None
Sure. A suggester can do that, no problem... |
@willmcgugan Case-insensitive logic has been added. |
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.
I've had a play around with it and it feels good to use :) my only suggestion would be to have case_sensitive=False by default as I think that's more common.
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.
Nice work.
Adds suggested completions to the
Input
Input
accepts a parametersuggestions
with a list of suggestions that are shown while the user types.Input.suggestions
reactive can be used to change the possible suggestions for a given input.Input
has new component classinput--suggestion
.Input
is also used to accept a suggestion if the cursor is at the end of the input.Closes #2330.