termui/render.go
2015-03-20 08:24:48 -04:00

47 lines
767 B
Go

package termui
import tm "github.com/nsf/termbox-go"
// all renderable components should implement this
type Bufferer interface {
Buffer() []Point
}
func Init() error {
Body = NewGrid()
Body.X = 0
Body.Y = 0
Body.BgColor = theme.BodyBg
defer (func() {
w, _ := tm.Size()
Body.Width = w
})()
return tm.Init()
}
func Close() {
tm.Close()
}
func TermWidth() int {
w, _ := tm.Size()
return w
}
func TermHeight() int {
_, h := tm.Size()
return h
}
// render all from left to right, right could overlap on left ones
func Render(rs ...Bufferer) {
tm.Clear(tm.ColorDefault, toTmAttr(theme.BodyBg))
for _, r := range rs {
buf := r.Buffer()
for _, v := range buf {
tm.SetCell(v.X, v.Y, v.Ch, toTmAttr(v.Fg), toTmAttr(v.Bg))
}
}
tm.Flush()
}