-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add custom keybindings #325
Conversation
This is a well-needed feature so this PR is much appreciated and it looks like a promising start. One thought I have, though, is that this is a new system completely separate from the existing shortcuts in https://docs.mau.fi/gomuks/shortcuts.html like Line 183 in 0a493d6
So it only adds new shortcuts, it can not disable or change. Is thee a way to have a unified config that (as far as reasonable) keeps current keybinding behavior as default but allows rebinding anything? One thing to consider is that some keybindings are contextual. Maybe the simple thing to do is just to have that e.g. a s a prefix in the property name instead of adding complexity for that. Or it could be nice as toml. |
@3nprob thanks for the encouraging feedback!
I'm not sure if that's considered a clean way, but the way I've implemented this shortcut system, it looks up key events in the custom keybindings map before any key events are handled in the original function. If a custom keybinding is found, the key event is not forwarded, otherwise the default is used. So effectively, the new keybindings overwrite the existing default, but with no specified keybinding, default is always there as fallback. So unbind existing defaults, I would probably ad a noop function to map it in the custom keybindings file.
Right, so far I haven't thought about contextual bindings at all. I could very well imagine prefix or toml or more nested yaml as options to implement that. |
@Schubisu I made my own attempt according to the above at #328 . overall very similar to what you have here, but replacing current behavior fully. If it turns out to be better starting point we should bring over your added functionality there as well. Hopefully together we can get through something good ^^ |
The unified keybinding system in #328 does sound preferable |
Hi and thanks for doing gomuks!
This PR is an approach to add customizable keybindings; this has been discussed in several related issues like #69 #70 #112 and #128. This is just a proposal, I'd love to improve this PR if you have any suggestions.
I've never written much golang code before and was mainly adapting what I already saw, so please let me know if you spot anything that's just bad practice.
This PR
$HOME/.config/gomuks/keybindings.yaml
cbind
'sEncode
to translate key(combination)s to stringsui/view-main.go
Also
go-runewidth
, though I'm not particularly happy I had to addtcell/v2
, not sure if that's a problem. To me, the convenience of usingEncode
seemed to be worth it.ui/view-main.go
or if there would be a more suitable place. I could also imagine a separate keybindings struct that the main view "registers" to.Would be happy to hear your thoughts. My
keybindings.yaml
looks like this: