-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Listen to custom key events on list item #1208
Comments
Hi, this isn't something we support in the base API. I would recommend you to create a custom prompt to handle this use case. I'd recommend you to use the new API to do so. Maybe replicating the new select prompt code and looking into Hope this helps! |
@SBoudrias I have a similar question, not sure if the useKeyPress will work for this or not, but do let me know. I have this as my output list: ? Choose an option: I want it such that the user can either use the arrow keys + Enter to make a selection, or just hit the key corresponding to the option. Is there a way to achieve this with the new API? |
@pgibler if you want something out of the box, the I think there might be an option to expand the default prompt by default (but I wrote that years ago, so I'm not 100% sure anymore 😅) |
I've followed your instructions and I almost have it done, but I've run into one bug that I'm wondering if you may remember the code well enough to know a solution. I'm going to try and figure it out myself so if I discover the fix I'll followup to help out anyone else who runs into the same thing. It occurs when the prompt constructor is picked based on the Here's what I'm seeing for the data that's being set in the And indeed on moving to the next line, the Prompt field is assigned to the value at the customList prompt key. But when These were the parameters passed into it: Would you know what might be causing this? I can make a repo to allow you to reproduce if it would help. Ultimately, I get this error: Extra information below: This is the getCustomMenuChoice function I have:
This is my customListPrompt.mjs
I appreciate the help with this! I'm really liking this library. |
Figured it out myself after going through your code again @SBoudrias Here's a working implementation of a list prompt controllable by both up/down + Enter & keypress. quickSelectPrompt.mjs
Then to use it
How can I best share this in case other's want to use it? I figure someone else may want this functionality too. |
You could put the code in a Github repo, and release it as a new package to npm 😄 |
Just got a repo up with the code now. Thanks for all the help getting this going @SBoudrias. |
@pgibler you can add your prompt here https://github.com/SBoudrias/Inquirer.js/blob/master/packages/prompts/README.md#community-prompts if you want to advertise it! I'm planning to switch this README to the repo homepage next weekend (more on that). |
How would I go about listening for a custom key press while the user is selecting a list item, for example say I prompt the user to select a file like such:
Now how do I make it so that when selecting if the user presses "o" on the active file it will open the file (similar to how
Press <i> to invert selection
works):![image](https://user-images.githubusercontent.com/61319150/230736553-fcf17d10-59a7-45f5-b251-c9de9e18d495.png)
(`obsidian_notes` is the selected item here, I want to be able to press "o" while selecting it to run some function, such as opening it in finder)The text was updated successfully, but these errors were encountered: