43 lines
824 B
Go
43 lines
824 B
Go
package tui
|
|
|
|
import (
|
|
"git.milar.in/milarin/slices"
|
|
"github.com/gdamore/tcell"
|
|
"github.com/mattn/go-runewidth"
|
|
)
|
|
|
|
func drawBuffer(scr tcell.Screen, buf *ViewBuffer) {
|
|
buf.ForEachLine(func(y int, content []Rune) {
|
|
for x := 0; x < buf.Width(); x++ {
|
|
rn := content[x]
|
|
|
|
extraRuneCount := runewidth.RuneWidth(rn.Rn) - 1
|
|
var extraRunes []Rune
|
|
if x+1+extraRuneCount < len(content) {
|
|
extraRunes = content[x+1 : x+1+extraRuneCount]
|
|
} else {
|
|
extraRunes = content[x+1 : x+1]
|
|
}
|
|
|
|
scr.SetContent(x, y, rn.Rn, slices.Map(extraRunes, getRune), rn.Style)
|
|
x += extraRuneCount
|
|
}
|
|
})
|
|
|
|
scr.Show()
|
|
}
|
|
|
|
func getRune(rn Rune) rune {
|
|
return rn.Rn
|
|
}
|
|
|
|
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)
|
|
}
|