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]Provide a way to change the choices separator when passing choices arg to Prompt.ask. #3552

Open
vivekkeshore opened this issue Nov 8, 2024 · 2 comments

Comments

@vivekkeshore
Copy link

vivekkeshore commented Nov 8, 2024

The default choices separator is "/", and there is no way to customise it.

Example

from rich.prompt import Prompt

predicate = Prompt.ask(
	f"[green]Enter the animal name[/green]",
	choices=["Lion", "Tiger", "Bear", "Giraffe", "Elephant"],
	case_sensitive=False,
	show_choices=True
)

Otutput

Enter the animal name [Lion/Tiger/Bear/Giraffe/Elephant]:

I would like to customise the separator, for example.

Enter the animal name [Lion, Tiger, Bear, Giraffe, Elephant]:

Or

Enter the animal name [Lion | Tiger | Bear | Giraffe | Elephant]:

Copy link

github-actions bot commented Nov 8, 2024

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

@RafaelWO
Copy link

RafaelWO commented Jan 12, 2025

I would also like to change the choice separator 🙂 However, I need more customization for choices and thus I created a class deriving from PromptBase to override how the choices are created (among other things).

Currently, the choices are created within PromptBase.make_prompt() which creates the prompt including choices and default values. If you want to change the rendering of the choices, one needs to override the complete function.

Therefore, I propose extracting the choice logic into another function e.g. make_choices to improve the developer experience if you want to customize this. Regarding the separator, I could also imagine adding a class variable (similar to prompt_suffix) to allow users to customize it easily through a custom class - if for some reason you don't want a new option in the Prompt.ask function.

I am happy to add my changes to the already opened PR #3553 if maintainers agree 🙃

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

2 participants