2024-04-10 08:38:44 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
//"time"
|
|
|
|
|
|
|
|
"github.com/jroimartin/gocui"
|
|
|
|
//"github.com/nsf/termbox-go"
|
|
|
|
)
|
|
|
|
|
2024-04-10 16:02:38 +02:00
|
|
|
var input chan string
|
|
|
|
|
2024-04-10 08:38:44 +02:00
|
|
|
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 {
|
2024-04-10 16:02:38 +02:00
|
|
|
v.Clear()
|
|
|
|
v.SetCursor(0, 0)
|
2024-04-10 08:38:44 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func initKeybindings(g *gocui.Gui) error {
|
|
|
|
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
2024-04-10 16:02:38 +02:00
|
|
|
|
2024-04-10 08:38:44 +02:00
|
|
|
if err := g.SetKeybinding("button", gocui.MouseLeft, gocui.ModNone, sendmsg); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
2024-04-10 16:02:38 +02:00
|
|
|
|
|
|
|
if err := g.SetKeybinding("button", gocui.MouseLeft, gocui.ModNone,
|
|
|
|
func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
texter, err := g.View("chatbox")
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
fmt.Fprintln(texter, "wow")
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := g.SetKeybinding("textarea", gocui.KeyEnter, gocui.ModNone, sendmsg); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
2024-04-10 08:38:44 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func layout(g *gocui.Gui) error {
|
|
|
|
maxX, maxY := g.Size()
|
|
|
|
|
2024-04-10 16:02:38 +02:00
|
|
|
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY/2+6); err != nil {
|
2024-04-10 08:38:44 +02:00
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Fprintln(chatbox, "Hello!")
|
|
|
|
}
|
|
|
|
|
2024-04-10 16:02:38 +02:00
|
|
|
if button, err := g.SetView("button", maxX/2+32, maxY/2+9, maxX/2+40, maxY/2+11); err != nil {
|
2024-04-10 08:38:44 +02:00
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
2024-04-10 16:02:38 +02:00
|
|
|
//button.BgColor = gocui.ColorRed
|
2024-04-10 08:38:44 +02:00
|
|
|
button.Wrap = true
|
2024-04-10 16:02:38 +02:00
|
|
|
button.Frame = true
|
|
|
|
fmt.Fprintln(button, "Send it")
|
2024-04-10 08:38:44 +02:00
|
|
|
}
|
2024-04-10 16:02:38 +02:00
|
|
|
|
|
|
|
if textarea, err := g.SetView("textarea", 2, maxY/2+9, maxX/2+25, maxY/2+11); err != nil {
|
|
|
|
if err != gocui.ErrUnknownView {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := g.SetCurrentView("textarea"); err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
textarea.Title = "Send message"
|
|
|
|
textarea.Wrap = true
|
|
|
|
textarea.Editable = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-04-10 08:38:44 +02:00
|
|
|
return nil
|
|
|
|
}
|