gum icon indicating copy to clipboard operation
gum copied to clipboard

choose with keyboard shortcut

Open SevereOverfl0w opened this issue 3 years ago • 7 comments

I'd love a way to make "quick menus" with gum where each item corresponds to a keyboard shortcut of some kind for it's selection. This way I could type "a" or "b" or "c" to quickly choose between 3 presented options. On inputting this character (no need to hit enter) it would be selected as the choice.

SevereOverfl0w avatar Aug 06 '22 16:08 SevereOverfl0w

I want to add my +1 here. I'm using gum choose in a script and can often get like 20 or more items in the choices. If I could see:

❯ gum choose "alpha" "beta" "gamma" "delta" ... "chi" "psi" "omega"
> 1. alpha
  2. beta
  3. gamma
  4. delta
...
  22. chi
  23. psi
  24. omega

or some such and type "22" to get to chi rather than scrolling allll the way down, that'd be great!

Of course, the "no need for enter" in @SevereOverfl0w's case wouldn't work for my case as if I want #22, it'd go to #2 and be done. Maybe a "more than 9 items means you have to type and press enter"?

(Though it still won't stop me from trying to select it with my mouse about once a week!)

mathomp4 avatar Aug 09 '22 16:08 mathomp4

This is a great idea @SevereOverfl0w!

I agree with @mathomp4, where if the options are > 10 then we should keep a small buffer of the number keys pressed and navigate to that option instead of selecting it.

Though it still won't stop me from trying to select it with my mouse about once a week

I believe mouse support is possible with Bubble Tea, this can also be something we add.

maaslalani avatar Sep 27 '22 15:09 maaslalani

+1, this would be very useful.

It'd be the alternative for a gum filter but give you more than the current choose. I'm thinking it would be nice to have it display the shortcuts at the bottom of the selection (similar to what gum pager does currently) image

I'm not sure if this approach would work as well for long lists that aren't triggered with a single character, such as @mathomp4's example. I would personally pick up gum filter in that example instead, along with an enhancement similar to this https://github.com/charmbracelet/gum/issues/128 but for filter elements.

keevan avatar Oct 12 '22 08:10 keevan

@keevan I think my gum filter version of my code might be fixed by #186 if it works. I am usually typing whole words in filter code anyway.

And, yes, I still try to use my mouse in both choose and filter like once a week. 😆

mathomp4 avatar Oct 12 '22 18:10 mathomp4

I'm interested in the use case of explicitly binding keys to a small number of items. I imagine it could look something like this:

cat | gum choose --keys
x$Exercise
c$Conglomerate
p$Profit
^d
> Exercise (x)
  Conglomerate (c)
  Profit (p)

(not sure what the most appropriate delimiter would be for inputs)

edrex avatar Mar 30 '23 15:03 edrex

I currently do this with bash scripts, it would be amazing if I could do the same with gum. I hope this feature is added in the future.

crvillanueva avatar Apr 16 '23 20:04 crvillanueva

I currently use tydra for this, but it's unmaintained.

edrex avatar Dec 09 '23 21:12 edrex