Configure selecting buttons with enter and tab
This commit is contained in:
parent
313d22fd64
commit
84149fc850
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
@ -13,7 +14,6 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("test")
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
|
@ -39,6 +39,30 @@ func initKeybindings(g *gocui.Gui) error {
|
|||
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextView); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err := g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone, buttonSelect); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buttonSelect(g *gocui.Gui, v *gocui.View) error {
|
||||
exercise1, err := g.View("exercise1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exercise2, err := g.View("exercise2")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch v {
|
||||
case exercise1:
|
||||
g.Close()
|
||||
exer1()
|
||||
time.Sleep(time.Second)
|
||||
main()
|
||||
case exercise2:
|
||||
fmt.Fprintln(v, "BAR")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -49,6 +73,7 @@ func layout(g *gocui.Gui) error {
|
|||
return err
|
||||
}
|
||||
exercise1.Title = "Ex. 1"
|
||||
g.SetCurrentView("exercise1")
|
||||
fmt.Fprintln(exercise1, "Methods")
|
||||
}
|
||||
if exercise2, err := g.SetView("exercise2", 14, 1, 24, 4); err != nil {
|
||||
|
|
Loading…
Reference in New Issue