unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
5.78k stars 165 forks source link

Enhance `consola.prompt` Select Options to Support Generic Values Matching Clack's Flexibility #282

Open shtse8 opened 3 months ago

shtse8 commented 3 months ago

Describe the feature

Description I've been utilizing Consola for logging and interacting with the console in my projects. Recently, I came across a scenario where I needed to use consola.prompt for a selection input. I noticed that Consola, which uses Clack for powering consola.prompt, restricts select options values to strings. However, Clack itself supports generic values for these options, offering enhanced flexibility and utility by allowing the return of objects or other types beyond just strings.

Issue The limitation to string values in select options within Consola's prompt functionality leads to additional parsing and handling when developers might need to associate selected options with complex objects or other non-string values. This constraint diverges from Clack's inherent flexibility and reduces the effectiveness of consola.prompt in scenarios where complex, associated data needs to be returned directly from a selection.

Proposed Enhancement I propose that Consola's implementation of consola.prompt for select options be enhanced to support generic values, aligning with Clack's capabilities. This change would allow developers to directly associate objects or other types with select options, significantly improving usability and reducing the need for workarounds or additional parsing logic.

Benefits

Example Scenario Consider a command-line application where a user selects from a list of configurations, each represented as an object with multiple properties. Under the current string-only constraint, developers must map selected strings back to the corresponding configuration objects. Allowing generic values directly as select options would streamline this process, enabling a more intuitive and efficient workflow.

I believe this enhancement would significantly benefit the Consola user community by providing a more flexible and powerful tool for interactive console applications. Thank you for considering this proposal.

Additional information