[go: nahoru, domu]

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

[REQUEST] Prompt validated via Regex #2938

Open
antoniovazquezblanco opened this issue Apr 26, 2023 · 1 comment
Open

[REQUEST] Prompt validated via Regex #2938

antoniovazquezblanco opened this issue Apr 26, 2023 · 1 comment

Comments

@antoniovazquezblanco
Copy link

Consider posting in https://github.com/textualize/rich/discussions for feedback before raising a feature request.

Have you checked the issues for a similar suggestions? Yes. Have not found the request among open issues or PRs.

How would you improve Rich?

I would love to have a Prompt class that can validate string input based on a regex pattern :)

What problem does it solve for you?

It may be the fastest way to implement an string validated prompt.

** Code example **

Probably not the best example implementation but... :)

class RegexPrompt(PromptBase[str]):
    response_type = str

    def __init__(self, regex, validate_error_message, *kwargs):
        super().__init__(kwargs)
        self._regex = regex
        self.validate_error_message = "[prompt.invalid]"+validate_error_message

    def process_response(self, value: str) -> str:
        if not self._regex.fullmatch(value):
            raise InvalidResponse(self.validate_error_message)
        return value
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant