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

Adding single key as a shortcut #1

Open
abitrolly opened this issue Dec 25, 2019 · 2 comments
Open

Adding single key as a shortcut #1

abitrolly opened this issue Dec 25, 2019 · 2 comments

Comments

@abitrolly
Copy link

Apparently, single key bindings are not supported, and no error is reported for them.

wagoodman/dive#129 (comment)

@abitrolly
Copy link
Author

To get to the root of the problem, I had to explore the code a bit. keybinding.Key object is a struct which includes gocui.Key object.

Value gocui.Key

gocui.Key is just an alias to termbox.Key

https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L44

termbox.Key is uint16.

https://github.com/nsf/termbox-go/blob/93860e16131719fa9722e7c448dbf8c0e3210a0d/api_common.go#L11

Now termbox.Key is used in termbox.Event struct with the interesting comment

type Event struct {
	Type   EventType // one of Event* constants
	Mod    Modifier  // one of Mod* constants or 0
	Key    Key       // one of Key* constants, invalid if 'Ch' is not 0
	Ch     rune      // a unicode character
...

https://github.com/nsf/termbox-go/blob/93860e16131719fa9722e7c448dbf8c0e3210a0d/api_common.go#L21-L22

There is only one event - EventKey - related to keyboard input. When parsing events, if input stream contains a simple character (not prefixed with escape sequence) , termbox doesn't assign event.Key field, and the character goes into event.Ch.

@abitrolly
Copy link
Author

termbox examples process event.Key for key combinations and event.Ch for letters separately.
gocui.newKeybinding also accepts key Key, ch rune as separate parameters.

https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L19

keybinding.Key struct however, has no placeholder for ch rune. keybinding.Parse method which should return Key doesn't handle chars and doesn't map them to any Key values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant