Added quit button widget to exercise
This commit is contained in:
parent
99c053115e
commit
faa95c2248
|
@ -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,12 +55,31 @@ 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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue