Skip to content
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

Overriding KeyMaps and KeyBinds #272

Open
DotoPototo opened this issue Jun 5, 2024 · 3 comments
Open

Overriding KeyMaps and KeyBinds #272

DotoPototo opened this issue Jun 5, 2024 · 3 comments
Labels
bug Something isn't working enhancement New feature or request filepicker

Comments

@DotoPototo
Copy link

KeyMap Issue

I'm aiming to customise the help keymap for the file picker when picking a file.

For me personally, I don't like that it shows and there's the ability to go back and forth between other form elements, while you're zoomed in picking a file, with shift+tab and tab.

If I set a custom keymap

var myCustomKeyMap = huh.KeyMap{
  FilePicker: huh.FilePickerKeyMap {
    ...
  }
}

huh.NewFilePicker().
  Title("File Picker").
  WithKeyMap(&myCustomKeyMap)

it then gets overwritten by the group and form setting the default keymaps.

I came across issue #73, so I set the keymap on the form instead but this removed all the keymaps for the other components.

Obviously the solution was to use the default keymap and only update the filepicker keymap but neither this nor the filepicker components keymap getting overridden is what I'd see as expected behaviour and the latter is not documented as far as I can find.

At this point though, I now have a keymap with prev and next removed when picking a file! Except it's also removed when not picking a file, so it doesn't give what I need and kind of breaks the form ☹️

KeyBind Issue

Additionally, I'd like to update the help to show going back in the filepicker, but there's no public function to update the help key binds.

Bonus Issue

If a file picker is the final component in a form, it shows enter to open (start picking a file) and enter to submit. Not only could this be confusing UX but it doesn't allow having an optionally filled in file picker component at the end of the form.

Potential Solution

Most of these issues could be handled by manually handling some key presses, doing a custom help instead of the built-in one etc but it would be nice if it was easier and certain aspects followed more expected behaviour.

I suggest;

  • To not have the form and group set default key maps if a custom one has already been applied
  • Now that components have a new zoom property, the ability to set a different key map when a component is zoomed, in this case when selecting a file with the file picker
  • The ability to change the help key binds of a component, i.e. adding back for the file picker

Let me know if anything isn't clear or if I've missed some obvious solution to the issues 🙂 thanks!

@nivanov-ati
Copy link

@mikecbone I'm also very curious about adding new key bindings to existing components. For example, I'd like to add the key "c" to the Select component to create a new list entry. I know I can use WithFilter to get access to ALL messages going to the form and catch the "c" keypress, but I'm not sure how I can add it to Help. You mention doing a custom help instead of the built-in one - could you please advise as to how to do that? Thanks!

@DotoPototo
Copy link
Author

@nivanov-ati Yeah, you can use the help bubble provided by charm to create your own

And then you disable the default help provided by the component you're changing.

Alternatively, I think a lot of components allow you to update their built in help too with custom key maps

@nivanov-ati
Copy link

Thank you!

NachE added a commit to Develatio/nebulant-cli that referenced this issue Aug 22, 2024
#96

to change keybinds and show "<- back" in help, we should waiting charmbracelet/huh#272
@caarlos0 caarlos0 added bug Something isn't working enhancement New feature or request filepicker labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request filepicker
Projects
None yet
Development

No branches or pull requests

3 participants