Skip to content

Support for multiline (custom height) validation (and bottom toolbar) messages #2048

@cbrown1234

Description

@cbrown1234

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions