68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
//"time"
|
|
|
|
"github.com/jroimartin/gocui"
|
|
//"github.com/nsf/termbox-go"
|
|
)
|
|
|
|
func main() {
|
|
g, err := gocui.NewGui(gocui.OutputNormal)
|
|
if err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
defer g.Close()
|
|
g.SetManagerFunc(layout)
|
|
g.Mouse = true
|
|
g.Cursor = true
|
|
initKeybindings(g)
|
|
|
|
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
|
|
log.Panicln(err)
|
|
}
|
|
}
|
|
|
|
func quit(*gocui.Gui, *gocui.View) error {
|
|
return gocui.ErrQuit
|
|
}
|
|
|
|
func sendmsg(g *gocui.Gui, v *gocui.View) error {
|
|
fmt.Fprintln(v, "HEEEE")
|
|
return nil
|
|
}
|
|
|
|
func initKeybindings(g *gocui.Gui) error {
|
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
if err := g.SetKeybinding("button", gocui.MouseLeft, gocui.ModNone, sendmsg); err != nil {
|
|
log.Panicln(err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func layout(g *gocui.Gui) error {
|
|
maxX, maxY := g.Size()
|
|
|
|
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY/2-2); err != nil {
|
|
if err != gocui.ErrUnknownView {
|
|
return err
|
|
}
|
|
fmt.Fprintln(chatbox, "Hello!")
|
|
}
|
|
|
|
if button, err := g.SetView("button", 20, 20, 30, 30); err != nil {
|
|
if err != gocui.ErrUnknownView {
|
|
return err
|
|
}
|
|
button.BgColor = gocui.ColorRed
|
|
button.Wrap = true
|
|
button.Frame = false
|
|
fmt.Fprintln(button, "BUTTON")
|
|
}
|
|
return nil
|
|
}
|