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