handle unusual escape codes in files

This commit is contained in:
Gokcehan 2016-11-29 17:00:40 +03:00
parent bfd33f8437
commit 217d89ff96

15
ui.go
View File

@ -111,12 +111,14 @@ func (win *Win) print(x, y int, fg, bg termbox.Attribute, s string) {
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
r, w := utf8.DecodeRuneInString(s[i:]) r, w := utf8.DecodeRuneInString(s[i:])
if r == EscapeCode { if r == EscapeCode && i+1 < len(s) && s[i+1] == '[' {
i++ j := strings.IndexByte(s[i:min(len(s), i+8)], 'm')
if s[i] == '[' {
j := strings.IndexByte(s[i:], 'm')
toks := strings.Split(s[i+1:i+j], ";") if j == -1 {
continue
}
toks := strings.Split(s[i+2:i+j], ";")
var nums []int var nums []int
for _, t := range toks { for _, t := range toks {
@ -185,10 +187,9 @@ func (win *Win) print(x, y int, fg, bg termbox.Attribute, s string) {
} }
} }
i = i + j i += j
continue continue
} }
}
if x >= win.w { if x >= win.w {
break break