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

feat: transformChoice options for checkbox #1349

Closed
matthyk opened this issue Jan 17, 2024 · 5 comments · Fixed by #1360
Closed

feat: transformChoice options for checkbox #1349

matthyk opened this issue Jan 17, 2024 · 5 comments · Fixed by #1360

Comments

@matthyk
Copy link
Contributor

matthyk commented Jan 17, 2024

After the selection within the checkbox prompt is made, the selected values are printed to stdout. This can look very messy if the name of the choice is very long. The reason for this is this line:

.map((choice) => choice.name || choice.value);

An option like transformChoice could solve the problem. The line could then be updated to like this for example:

.map( transformChoice || (choice => choice.name || choice.value));

If I get the OK, I would also work on it right away.

@matthyk matthyk changed the title Feat: transformChoice options for checkbox feat: transformChoice options for checkbox Jan 17, 2024
@SBoudrias
Copy link
Owner

The older checkbox prompt had a short option to shorten long choices: https://github.com/SBoudrias/Inquirer.js/blob/master/packages/inquirer/lib/prompts/checkbox.js

I don't know we need to keep the same API, but it's an option. Also, if we want to shorten the display, maybe we're better with a rendering function receiving the whole option list (so you could custom format like "a, b and 3 others", etc)

@matthyk
Copy link
Contributor Author

matthyk commented Jan 17, 2024

@SBoudrias Are you open for a PR?

@SBoudrias
Copy link
Owner

Yes, happy to review and merge a PR.

I would recommend us aligning on the right approach to the problem though - want to make sure you don't waste your time if we end up feeling a different API would cover more cases!

@matthyk
Copy link
Contributor Author

matthyk commented Jan 17, 2024

I would go with your second option, to provide a rendering function. I think it is the most flexible option. We could provide the rendering function with the list of all options AND the list of all selected options. Something like:

type RenderFn = (choices: ReadonlyArray<Choice<Value> | Separator>, selectedChoices: ReadonlyArray<Choice<Value>>) => string

But I'm open to everything.

@SBoudrias
Copy link
Owner

Yeah, that works. I like it - it's probably the most flexible option.

Just a nit that I'd flip the function params for all choices and selected choices.

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