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.19k stars 772 forks source link

Input templates #4581

Open amottola opened 4 months ago

amottola commented 4 months ago

Hi all,

I see templates are on the roadmap for Input widget, and since I need them on one of my projects, I'd like to give it a try. I'm opening this issue for discussion with the goal of making my first contribution to textual.

I propose to add a template reactive attribute to Input that emulates the behavior of Qt input masks, since this is what I'm used to and I think it allows enough freedom to cover all the use cases mentioned in the roadmap (I see IP address, physical units, currency, credit card) and more. Since Qt input masks are well documented, I'm not going to copy the docs here; just have a look at the link above. They are also effective as they are used in many production environments.

As an extension however, I'd like to add the possibility to specify more than a single blank character after the optional final ;: for this I propose to reuse the placeholder text, which when used in conjunction with template is always made visible even if Input value is not empty. The placeholder covers untyped content only and is dimmed of course. If blank character is specified in the template string, it has a precedence over placeholder.

This should allow for templates suitable to help in the development of the date picker widget (#3576), something like:

date_input = Input(template='0000-00-00', placeholder='YYYY-MM-DD')

Thoughts?

github-actions[bot] commented 4 months ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory