-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Keybinding system for global keys #135
Conversation
Hello, happy to hear you've been enjoying Amfora! Thanks for making this PR, keybindings is a good feature, and it's even better when it's not just on your fork :) I think your code is good, but I find the format you chose kind of ugly/unclear to write. Using Some other things:
|
Good point about the TOML parser... I feel dumb for not seeing that. I decided to go with And finally, I re-added |
Ok, I think this should be ready to merge. |
Oh! I just realized something that should probably go with this: the help screen is static. I'll take a shot at updating it to display the configured keys later tonight. (I'm also happy to update the wiki to add a keybindings page under the configuration page) |
Nice catch, thanks. I'll take a look at everything when I can, after you update the help page. |
Looks like maybe that part is done? Let me know and I'll take a look soon. |
Yes, I got the help page working, and I think it's ready. |
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.
Thank you for working on this! Overall it looks good, I've made some specific comments. Also:
- In general, put a space after the hashtag in the config file. So
#bind_whatever
becomes# bind_whatever
. - Add comments to document functions
Also, are you interested in writing a wiki page on this? It would be under the configuration section, like the Proxying page.
config/keybindings.go
Outdated
CmdInvalid = 0 | ||
CmdLink1 = 1 | ||
CmdLink2 = 2 | ||
CmdLink3 = 3 | ||
CmdLink4 = 4 | ||
CmdLink5 = 5 | ||
CmdLink6 = 6 | ||
CmdLink7 = 7 | ||
CmdLink8 = 8 | ||
CmdLink9 = 9 | ||
CmdLink0 = 10 | ||
CmdTab1 = 11 | ||
CmdTab2 = 12 | ||
CmdTab3 = 13 | ||
CmdTab4 = 14 | ||
CmdTab5 = 15 | ||
CmdTab6 = 16 | ||
CmdTab7 = 17 | ||
CmdTab8 = 18 | ||
CmdTab9 = 19 | ||
CmdTab0 = 20 | ||
CmdBottom = iota |
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.
Is there any reason why you did it like this? You can just specify = iota
at the start.
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.
It was meant as a semantic warning: there's some code that depends on these values being in this relation to each other. Essentially: CmdTab0 - CmdTab1 == 9, and CmdTab[N+1] == 1 + CmdTabN, thus rearranging these would break stuff. Basically, get future programmers to ask, wait, why does this break convention?
I'll add a comment to this effect.
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.
Alright, that makes sense. And yeah a comment is helpful, thanks.
k := e.Key() | ||
if k == tcell.KeyRune { | ||
cmd, ok = bindings[keyBinding{k, e.Modifiers(), e.Rune()}] | ||
} else { // Sometimes tcell sets e.Rune() on non-KeyRune events. |
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.
Where have you seen this? Just curious.
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.
Primarily on the Ctrl-Letter-Key events. The event will have e.Key() == KeyCtrlA
, e.Modifers() == 2
(for Control) and e.Rune() == 'A'
. I originally added a correction for this when generating the bindings table, but it felt awkward, and would break if tcell changed behavior.
Committing suggested changes with diffs Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
Just commited the suggestions that could be committed in the GitHub UI. I'll go work through the rest of the conversations in a bit here. (And fix the linter error) |
And I think I mentioned it, but I'm definitely happy to update the wiki and add a page for keybindings under the configuration page. |
I think I addressed all the comments and the linter is happy. It probably makes sense to hold off on trying to update the wiki until after the merge. |
Merge branch 'master' into key-remapping
Thanks for adding this! I'm having a little trouble grokking it but I think I'm just a bit tired right now. Overall it looks good. |
I've been really enjoying using amfora, but it has different keybindings from qutebrowser and my terminal translates ctrl-t to ctrl-a,c to get screen to create a new tab/view. Also, my compositor eats all F1 keypresses. Re-doing the hardcoding has been nice for a couple weeks, but that doesn't let me keep up to date with y'all.
I think this code is pretty straightforward, let me know what you think or if you wanted a totally different design. (I know I didn't ask, I just wrote something that worked for me :)