diff --git a/gocui-practice/main.go b/gocui-practice/main.go index 232e183..38d450d 100644 --- a/gocui-practice/main.go +++ b/gocui-practice/main.go @@ -3,10 +3,13 @@ package main import ( "fmt" "log" + "time" "github.com/jroimartin/gocui" ) +var input chan int + func main() { g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { @@ -16,18 +19,35 @@ func main() { g.SetManagerFunc(layout) + go counter() + + g.Mouse = true + if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) } + if err := g.SetKeybinding("WOW", gocui.MouseLeft, gocui.ModNone, quit); err != nil { + log.Panicln(err) + } + if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { log.Panicln(err) } } +var numToIncrease int + +func counter() { + for { + numToIncrease++ + time.Sleep(time.Second) + } +} + func layout(g *gocui.Gui) error { maxX, maxY := g.Size() - if v, err := g.SetView("hello", maxX/2-20, maxY/2-15, maxX/2+20, maxY/2-5); err != nil { + if v, err := g.SetView("hello", maxX/2-20, maxY/2-18, maxX/2+20, maxY/2-15); err != nil { if err != gocui.ErrUnknownView { return err } @@ -35,13 +55,32 @@ func layout(g *gocui.Gui) error { fmt.Fprintln(v, "Hello!") } - if v, err := g.SetView("anotherone", maxX/2-20, maxY/2, maxX/2+20, maxY/2+2); err != nil { + if v, err := g.SetView("anotherone", maxX/2-20, maxY/2-13, maxX/2+20, maxY/2-6); err != nil { if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, "Hola!") + for i := 0; i < 5; i++ { + fmt.Fprintln(v, "Hola!") + } } + if v, err := g.SetView("WOW", maxX/2-20, maxY/2, maxX/2+20, maxY/2+5); err != nil { + if err != gocui.ErrUnknownView { + return err + } + // var number int + // go func() { + // number = <-input + // }() + // fmt.Fprintln(v, number) + + fmt.Fprintln(v, "You should quit... NOW!", numToIncrease) + } + + // if err := g.SetKeybinding("WOW", gocui.MouseLeft, gocui.ModNone, fcn); err != nil { + // fmt.Fprintln(v, "Clicked") + // } + return nil }