Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
25.58k stars 787 forks source link

Document Suggester in Input #4934

Open willmcgugan opened 2 months ago

willmcgugan commented 2 months ago

The Input widget docs don't cover Suggesters, other than a reference in the API. It is such a useful feature I think it deserves a section with a simple demo.

carloshm91 commented 2 months ago

Yes this is very useful. Also some screenshots with visual examples will be great.

merriam commented 2 months ago

Could I suggest that something more simple and more generic be considered?

A watcher on input should be able to fire on one of two conditions: any change (key press, paste, cut) or any completion (blur or enter). A watcher should be able to be boolean (just disallow the changes) or return a pair with (optional new value, optional new renderable instead of just rendering the value). This allows for suggesters, regex validation, type ahead, complex highlighting like different parts of a url, complex validation like being sure the part number is in stock, and pretty much every use case.

A Suggester just becomes one of the watchers.

darrenburns commented 2 months ago

Could you share a quick code snippet of what that might look like in a new discussion @merriam? I'm struggling to visualize it.