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

SetKeyBinding fails when called via a helper function #29

Closed
stephenwithav opened this issue Apr 26, 2015 · 2 comments
Closed

SetKeyBinding fails when called via a helper function #29

stephenwithav opened this issue Apr 26, 2015 · 2 comments
Assignees
Labels

Comments

@stephenwithav
Copy link

When defining my keybindings, I use this helper function:

    func setkey(g *gocui.Gui, key gocui.Key, fn gocui.KeybindingHandler) {
        if err := g.SetKeybinding("", key, gocui.ModNone, fn); err != nil {
            log.Panicln(err)
        }
    }

An example invocation that works is:

    setKey(g, gocui.KeyCtrlC, quit)

...but the following fails:

    setKey(g, 'q', quit)

...while the following correctly binds the q key:

        if err := g.SetKeybinding("", 'q', gocui.ModNone, quit); err != nil {
            log.Panicln(err)
        }

I'm pretty sure I'm missing something obvious here.

@jroimartin
Copy link
Owner

The signature of your helper function should be:

func setkey(g *gocui.Gui, key interface{}, fn gocui.KeybindingHandler)

Because key can be a gocui.Key or a rune. Try and let me know if it works ok for you :)

@jroimartin jroimartin self-assigned this Apr 26, 2015
@stephenwithav
Copy link
Author

Fantastic! Thank you, @jroimartin !

mattn pushed a commit to mattn/gocui that referenced this issue Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants