prompts
prompts copied to clipboard
Add ability to set hotkeys for multiselect
I'd like the ability to customize the hotkey options available to the user for multiselect. My dream is to have something like git add -p
, where you get hotkeys like:
Stage this hunk [y,n,q,a,d,e,?]?
Example usage:
await prompts({
// ...
hotkeys: {
d: {
handle() {
/* handle user action */
},
instruction: 'Save current progress and stop answering questions.'
}
},
})
This PR is a draft. If you like the idea, I'll add tests / docs.
This is cool – I like the idea a lot. Wonder if this could be a completely new prompt type?
I think it could be a new prompt type, but at least for my use case, I'd also like to add it to multiselect. I'll add tests / docs to this PR next.
This PR currently isn't passing on Node 6. (And there are a few cases, most notable lack of async/await
support, that make supporting Node 6 make the code less readable.)
Node 6 is currently considered to be "end of life". It was released in 2016. How would you feel about dropping support for it?
@terkelg how does this look to you now?
@NickHeiner thank you for the PR! I'll have a look at this over the weekend. Quick note: You can use async/await. It's already used quite a few places
Ok @terkelg I addressed your comments. It's now passing in Node 6.
@terkelg I'm ready to move forward on this whenever you are. :smile:
Looks good. I wonder if we should pass some arguments to the handler callback? Like a reference to the prompts so that you can provide some sort of visual feedback?
Looks good. I wonder if we should pass some arguments to the handler callback? Like a reference to the prompts so that you can provide some sort of visual feedback?
Sounds interesting, but I'm not sure precisely what you have in mind. Can you elaborate?
Right now there's no feedback to the user to indicate a hotkey has been pressed/activated. I wonder if there could be a way to change selected
mode in the hotkey callbacks?
If a hotkey changes which answers are selected, that's reflected in the rendered output. In this gif, we can see that pressing a
(which is a "built in hotkey") and r
(which is a hotkey added by this PR) both provide the same type of feedback.
Does this address what you're looking for, or am I misunderstanding?
I'll have a look at it this weekend – I didn't get that for some reason
{
type: 'multiselect',
name: 'multicolor',
message: 'Pick colors',
hint: false,
hotkeys: {
d: {
handle(x, y) {
/* handle user action */
},
instruction: 'Save current progress and stop answering questions.'
}
},
choices: [
{ title: 'Red', description: 'This option has a description.', value: '#ff0000' },
{ title: 'Green', value: '#00ff00' },
{ title: 'Yellow', value: '#ffff00', disabled: true },
{ title: 'Blue', value: '#0000ff' }
]
},
When I run this I get no visual feedback as a user that I hit the hotkey?