display combining characters in the text

cc #496
This commit is contained in:
Gokcehan 2021-01-18 20:48:31 +03:00
parent d27748e9b5
commit d6c5590ad0

13
ui.go
View File

@ -193,6 +193,7 @@ func printLength(s string) int {
func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) tcell.Style {
off := x
var comb []rune
for i := 0; i < len(s); i++ {
r, w := utf8.DecodeRuneInString(s[i:])
@ -208,8 +209,18 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
continue
}
for {
rc, wc := utf8.DecodeRuneInString(s[i+w:])
if rc == gEscapeCode || runewidth.RuneWidth(rc) != 0 {
break
}
comb = append(comb, rc)
i += wc
}
if x < win.w {
screen.SetContent(win.x+x, win.y+y, r, nil, st)
screen.SetContent(win.x+x, win.y+y, r, comb, st)
comb = nil
}
i += w - 1