90 lines
1.6 KiB
Go
90 lines
1.6 KiB
Go
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 {
|
|
log.Panicln(err)
|
|
}
|
|
defer g.Close()
|
|
|
|
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-18, maxX/2+20, maxY/2-15); err != nil {
|
|
if err != gocui.ErrUnknownView {
|
|
return err
|
|
}
|
|
fmt.Fprintln(v, "This is a reaaaaaaaally long message")
|
|
fmt.Fprintln(v, "Hello!")
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func quit(g *gocui.Gui, v *gocui.View) error {
|
|
return gocui.ErrQuit
|
|
}
|