-
Notifications
You must be signed in to change notification settings - Fork 336
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
Adding key for quit in SelectKeys #155
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to emit a signal that can be caught by the calling code, as a sentinel value from Run()
in case there are multiple levels of promptui.
This PR does satisfy my needs as is though, but I can easily see random os.Exit(0)
(hard-coded 0
, uncatchable Exit
) being undesirable without overrides.
Perhaps even just a configurable function that handles the Keys.Exit.Code
, default Exit(0)
, optionally returning a sentinel value if the user doesn't want to exit.
@blast-hardcheese, thanks for your comment. I've added variable for an optional value that can be returned on exit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked as expected, thank you!
what's blocking this from getting merged? |
I like this feature and I hope this PR would be merged soon. :) thank you. Additionally, I want to leave some comments below. :) I doubt both
|
@HurSungYun, thanks for your comment.
There is an ExitValue. You can use it instead of exit, then intercept the value in your main module and emit whatever you want. I hope it'll help.
prompt := promptui.Select{
Label: "Select an item (or press \"Esc\" for exit)",
Items: items,
Templates: &templates,
Size: 20,
Searcher: searcher,
HideSelected: true,
Keys: &promptui.SelectKeys{
Next: promptui.Key{
Code: readline.CharNext,
Display: "↓",
},
Prev: promptui.Key{
Code: readline.CharPrev,
Display: "↑",
},
PageUp: promptui.Key{
Code: readline.CharForward,
Display: "→",
},
PageDown: promptui.Key{
Code: readline.CharBackward,
Display: "←",
},
Search: promptui.Key{
Code: '/',
Display: "/",
},
Exit: promptui.Key{
Code: readline.CharEsc,
Display: "Esc",
},
},
} |
Happy early first birthday for this PR! |
@LuciferInLove Thanks for replying!
As you said, ExitValue would be helpful if user want to intercept cancel signal, but I believe it could be a better interface to return some kind of error ( I think waiting for advice from reviewers is a good idea as well :)
Oh, I didn't consider that there are keyboards w/o escape key. I believe there are plenty of people having keyboard w/o escape key, so |
Hi Folks; Not sure if this project is active and/or maintained (over a year. This PR for example is super useful, but has been sitting here. I ended up forking the project and implementing a similar thing, before I stumbled upon this. Any ideas why PR velocity is slow. Thanks folks! |
@jbowes You seem to be the only person maintaining this project at the moment, is this an orphaned project that would better off be forked so that popular PRs like this that have been waiting for over a year can be merged, or is the project going to be maintained? |
this is a super useful feature which can improve the user experience a lot, hope it can be merged soon. |
I hope this project not be abandoned as well. 🙏 This project is really useful and helps lots of other CLI projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGT - Can we merge this!
Adding key for quit (default is 'q') in SelectKeys