termui/render.go

35 lines
717 B
Go
Raw Normal View History

2017-01-14 06:07:43 +00:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2015-03-20 20:21:50 +00:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
2015-02-03 14:07:31 +00:00
package termui
2015-09-18 15:41:44 +00:00
import (
"image"
2015-09-18 15:41:44 +00:00
2018-09-06 21:48:09 +00:00
tb "github.com/nsf/termbox-go"
2015-09-18 15:41:44 +00:00
)
2015-02-03 14:07:31 +00:00
2019-01-24 04:12:10 +00:00
type Drawable interface {
GetRect() image.Rectangle
SetRect(int, int, int, int)
Draw(*Buffer)
}
func Render(items ...Drawable) {
for _, item := range items {
buf := NewBuffer(item.GetRect())
item.Draw(buf)
for point, cell := range buf.CellMap {
if point.In(buf.Rectangle) {
tb.SetCell(
point.X, point.Y,
cell.Rune,
tb.Attribute(cell.Style.Fg+1)|tb.Attribute(cell.Style.Modifier), tb.Attribute(cell.Style.Bg+1),
)
}
2015-02-04 01:56:49 +00:00
}
}
2018-09-06 21:48:09 +00:00
tb.Flush()
2015-02-03 14:07:31 +00:00
}