prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Support for multiline (custom height) validation (and bottom toolbar) messages
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
I would like to be able to add multiline error messages at the bottom of prompts to enable more detailed feedback (e.g. pydantic validation for users inputting more complex data structures (e.g. yaml, json)
Context: I've followed the path upstream with the aim off adding multiline error messages to https://github.com/copier-org/copier, which uses https://github.com/tmbo/questionary, which in turn uses this prompt toolkit.
Current workaround for this is an extension that monkey patches prompt toolkit: https://gitlab.com/cbrown1234/copier-pydantic, which is a fairly dirty hack.
import prompt_toolkit
_validation_toolbar_init = prompt_toolkit.widgets.ValidationToolbar.__init__
def _validation_toolbar_init_patched(
self: prompt_toolkit.widgets.ValidationToolbar,
*args: tuple,
**kwargs: dict,
) -> None:
"""Wrap ValidationToolbar __init__ for patching."""
_validation_toolbar_init(self, *args, **kwargs)
# Uncap validation message length to enable multiline error messages
self.container.content.height = None
I'm hoping to contribute proper support by updating the interface of PromptSession (because questionary already passes through extra **kwargs to PromptSession to enable customisation, e.g. https://github.com/tmbo/questionary/blob/f28b2d1f0c0d4a37e2a08c1627834366be6d1c17/questionary/prompts/text.py#L97)
I've explored a little how this could work, and will raise a draft MR, but given the number of other toolbars you might be looking for a more scalable design
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ValidationToolbar and PromptSession interfaces in prompt-toolkit, then compare how questionary's prompts/text.py passes customization through. Trace the other toolbar implementations to determine a scalable configuration approach, and consider the work complete when multiline validation and bottom-toolbar messages can be configured without monkey patching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100