golang-exercises/gocui-practice/main.go

51 lines
959 B
Go
Raw Normal View History

2024-04-04 09:39:37 +02:00
package main
import (
"fmt"
"log"
"github.com/jroimartin/gocui"
)
func main() {
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
g.SetManagerFunc(layout)
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}
}
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 {
2024-04-04 09:39:37 +02:00
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "This is a reaaaaaaaally long message")
fmt.Fprintln(v, "Hello!")
2024-04-04 09:39:37 +02:00
}
if v, err := g.SetView("anotherone", maxX/2-20, maxY/2, maxX/2+20, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "Hola!")
}
2024-04-04 09:39:37 +02:00
return nil
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}