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

Input completion suggestions #2604

Merged
merged 18 commits into from
May 29, 2023
Merged

Input completion suggestions #2604

merged 18 commits into from
May 29, 2023

Conversation

rodrigogiraoserrao
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao commented May 18, 2023

Adds suggested completions to the Input

  • Input accepts a parameter suggestions 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 class input--suggestion.
  • Keybinding right in Input is also used to accept a suggestion if the cursor is at the end of the input.

Closes #2330.

@rodrigogiraoserrao rodrigogiraoserrao changed the title Implement auto-completion. Input completion suggestions May 18, 2023
@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review May 18, 2023 13:51
@willmcgugan
Copy link
Collaborator

Video please!

Copy link
Collaborator

@willmcgugan willmcgugan left a 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?

src/textual/widgets/_input.py Outdated Show resolved Hide resolved
@rodrigogiraoserrao
Copy link
Contributor Author

Think we need to go over this one. Chat about it today?

Ping me when you're available.

@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as draft May 22, 2023 12:38
@rodrigogiraoserrao
Copy link
Contributor Author

Thanks for your guidance @willmcgugan.
This is ready for a second review.
I haven't written any docs yet. Should I add something to the Input reference, for example?

@willmcgugan
Copy link
Collaborator

Looking good so far! Will do a review post lunch. Can you add a video?

@rodrigogiraoserrao
Copy link
Contributor Author

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.mov
Example app
from 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)
@rodrigogiraoserrao rodrigogiraoserrao marked this pull request as ready for review May 23, 2023 14:33
Copy link
Collaborator

@willmcgugan willmcgugan left a 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.

cache: FIFOCache[str, str | None] | None
"""Suggestion cache, if used."""

def __init__(self, use_cache: bool = True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should have -> None

@rodrigogiraoserrao
Copy link
Contributor Author

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.

Sure. A suggester can do that, no problem...
We can chat later.

@rodrigogiraoserrao
Copy link
Contributor Author

@willmcgugan Case-insensitive logic has been added.

Copy link
Member

@darrenburns darrenburns left a 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.

Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

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

Nice work.

@rodrigogiraoserrao rodrigogiraoserrao merged commit 73d5572 into main May 29, 2023
@rodrigogiraoserrao rodrigogiraoserrao deleted the input-auto-completion branch May 29, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input auto-complete
3 participants