1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-27 13:48:51 +08:00
termui/render.go

29 lines
525 B
Go
Raw Normal View History

2015-02-03 09:07:31 -05:00
package termui
import tm "github.com/nsf/termbox-go"
// all renderable components should implement this
2015-03-03 13:28:09 -05:00
type Bufferer interface {
2015-02-03 09:07:31 -05:00
Buffer() []Point
}
func Init() error {
return tm.Init()
}
2015-02-03 20:56:49 -05:00
func Close() {
2015-02-03 09:07:31 -05:00
tm.Close()
}
// render all from left to right, right could overlap on left ones
2015-03-03 13:28:09 -05:00
func Render(rs ...Bufferer) {
tm.Clear(tm.ColorDefault, toTmAttr(theme.BodyBg))
2015-02-03 20:56:49 -05:00
for _, r := range rs {
buf := r.Buffer()
for _, v := range buf {
2015-03-03 13:28:09 -05:00
tm.SetCell(v.X, v.Y, v.Ch, toTmAttr(v.Fg), toTmAttr(v.Bg))
2015-02-03 20:56:49 -05:00
}
2015-02-03 09:07:31 -05:00
}
tm.Flush()
}