Frequently calling termbox.Sync() will upset terminal.
This commit is contained in:
gizak 2015-12-09 14:04:28 -05:00
parent 47e145b445
commit 0cb4aedd6f
2 changed files with 11 additions and 6 deletions

5
pos.go
View File

@ -66,6 +66,9 @@ func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle {
return a
}
var termWidth int
var termHeight int
func TermRect() image.Rectangle {
return image.Rect(0, 0, TermWidth(), TermHeight())
return image.Rect(0, 0, termWidth, termHeight)
}

View File

@ -70,21 +70,20 @@ var renderLock sync.Mutex
func termSync() {
renderLock.Lock()
tm.Sync()
termWidth, termHeight = tm.Size()
renderLock.Unlock()
}
// TermWidth returns the current terminal's width.
func TermWidth() int {
termSync()
w, _ := tm.Size()
return w
return termWidth
}
// TermHeight returns the current terminal's height.
func TermHeight() int {
termSync()
_, h := tm.Size()
return h
return termHeight
}
// Render renders all Bufferer in the given order from left to right,
@ -92,19 +91,22 @@ func TermHeight() int {
func render(bs ...Bufferer) {
for _, b := range bs {
buf := b.Buffer()
// set cels in buf
for p, c := range buf.CellMap {
if p.In(buf.Area) {
tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
}
}
}
renderLock.Lock()
// render
tm.Flush()
renderLock.Unlock()
}