Frequently calling termbox.Sync() will upset terminal.
This commit is contained in:
parent
47e145b445
commit
0cb4aedd6f
5
pos.go
5
pos.go
@ -66,6 +66,9 @@ func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var termWidth int
|
||||||
|
var termHeight int
|
||||||
|
|
||||||
func TermRect() image.Rectangle {
|
func TermRect() image.Rectangle {
|
||||||
return image.Rect(0, 0, TermWidth(), TermHeight())
|
return image.Rect(0, 0, termWidth, termHeight)
|
||||||
}
|
}
|
||||||
|
12
render.go
12
render.go
@ -70,21 +70,20 @@ var renderLock sync.Mutex
|
|||||||
func termSync() {
|
func termSync() {
|
||||||
renderLock.Lock()
|
renderLock.Lock()
|
||||||
tm.Sync()
|
tm.Sync()
|
||||||
|
termWidth, termHeight = tm.Size()
|
||||||
renderLock.Unlock()
|
renderLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TermWidth returns the current terminal's width.
|
// TermWidth returns the current terminal's width.
|
||||||
func TermWidth() int {
|
func TermWidth() int {
|
||||||
termSync()
|
termSync()
|
||||||
w, _ := tm.Size()
|
return termWidth
|
||||||
return w
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TermHeight returns the current terminal's height.
|
// TermHeight returns the current terminal's height.
|
||||||
func TermHeight() int {
|
func TermHeight() int {
|
||||||
termSync()
|
termSync()
|
||||||
_, h := tm.Size()
|
return termHeight
|
||||||
return h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render renders all Bufferer in the given order from left to right,
|
// Render renders all Bufferer in the given order from left to right,
|
||||||
@ -92,19 +91,22 @@ func TermHeight() int {
|
|||||||
func render(bs ...Bufferer) {
|
func render(bs ...Bufferer) {
|
||||||
|
|
||||||
for _, b := range bs {
|
for _, b := range bs {
|
||||||
|
|
||||||
buf := b.Buffer()
|
buf := b.Buffer()
|
||||||
// set cels in buf
|
// set cels in buf
|
||||||
for p, c := range buf.CellMap {
|
for p, c := range buf.CellMap {
|
||||||
if p.In(buf.Area) {
|
if p.In(buf.Area) {
|
||||||
|
|
||||||
tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
|
tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderLock.Lock()
|
renderLock.Lock()
|
||||||
// render
|
// render
|
||||||
tm.Flush()
|
tm.Flush()
|
||||||
|
|
||||||
renderLock.Unlock()
|
renderLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user