gocui/_demos/demo3.go

50 lines
927 B
Go
Raw Normal View History

2014-01-03 01:34:58 +08:00
package main
import (
"log"
"github.com/jroimartin/gocui"
)
2014-01-04 09:50:49 +08:00
func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if _, err := g.SetView("side", -1, -1, int(0.2*float32(maxX)), maxY-5); err != nil &&
err != gocui.ErrorUnkView {
2014-01-04 09:50:49 +08:00
return err
}
if _, err := g.SetView("main", int(0.2*float32(maxX)), -1, maxX, maxY-5); err != nil &&
err != gocui.ErrorUnkView {
2014-01-04 09:50:49 +08:00
return err
}
if _, err := g.SetView("cmdline", -1, maxY-5, maxX, maxY); err != nil &&
err != gocui.ErrorUnkView {
2014-01-04 09:50:49 +08:00
return err
}
return nil
}
2014-01-06 08:23:18 +08:00
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrorQuit
}
2014-01-03 01:34:58 +08:00
func main() {
var err error
g := gocui.NewGui()
if err := g.Init(); err != nil {
log.Panicln(err)
}
defer g.Close()
g.SetLayout(layout)
2014-01-03 01:34:58 +08:00
2014-01-06 08:23:18 +08:00
if err := g.SetKeybinding("", gocui.KeyCtrlC, 0, quit); err != nil {
log.Panicln(err)
}
2014-01-03 01:34:58 +08:00
err = g.MainLoop()
if err != nil && err != gocui.ErrorQuit {
log.Panicln(err)
}
}