gocui/_examples/layout.go

54 lines
1.1 KiB
Go
Raw Normal View History

2014-01-15 03:11:12 +08:00
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
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 {
2015-01-31 00:19:11 +08:00
return gocui.Quit
2014-01-06 08:23:18 +08:00
}
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
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
2014-01-06 08:23:18 +08:00
log.Panicln(err)
}
2014-01-03 01:34:58 +08:00
err = g.MainLoop()
2015-01-31 00:19:11 +08:00
if err != nil && err != gocui.Quit {
2014-01-03 01:34:58 +08:00
log.Panicln(err)
}
}