Closed lesovsky closed 6 years ago
Answer is found.
Hi. Do you mind showing how you solved it? Wondering the same.
@antonlindgren Hi, I built shortcuts management in such way:
type key struct {
viewname string
key interface{}
handler func(g *gocui.Gui, v *gocui.View) error
}
func keybindings(g *gocui.Gui) error { var keys = []key{ {"", gocui.KeyCtrlC, quit}, {"", 'd', funcExample("user_data")}, {"", gocui.KeyEsc, closeHelp}, }
g.InputEsc = true
for _, k := range keys {
if err := g.SetKeybinding(k.viewname, k.key, gocui.ModNone, k.handler); err != nil {
return fmt.Errorf("ERROR: failed to setup keybindings: %s", err)
}
}
return nil
}
func funcExample(c string) func(g gocui.Gui, v gocui.View) error {
return func(g gocui.Gui, v gocui.View) error {
switch c {
// your application logic here
}
return nil
}
}
Hope it helps )))
Hi,
I'd like to pass extra variables into my function which is used in SetKeybinding()
something like this
Is there any way to do this or I have to use global vars that visible from any funcs?