tui/draw_buffer.go
2022-04-03 16:29:01 +02:00

37 lines
708 B
Go

package tui
import (
"github.com/gdamore/tcell"
)
func drawBuffer(scr tcell.Screen, buf *ViewBuffer) {
// buf.ForEach(func(x, y int, rn Rune) {
// scr.SetContent(x, y, rn.Rn, nil, rn.Style)
// })
// TODO use runewidth.RuneWidth(rn)?
buf.ForEachLine(func(y int, content []Rune) {
for x := 0; x < buf.Width(); x++ {
rn := content[x]
if rn.Rn >= '─' && rn.Rn <= '╿' {
scr.SetContent(x, y, rn.Rn, []rune{content[x+1].Rn}, rn.Style)
x++
} else {
scr.SetContent(x, y, rn.Rn, nil, rn.Style)
}
}
})
scr.Show()
}
func truncateBuffer(buf *ViewBuffer, w, h int) *ViewBuffer {
if w < 0 {
w = buf.Width()
}
if h < 0 {
h = buf.Height()
}
return buf.Sub(0, 0, w, h)
}