More sophisticated color codes stripper. #217

This commit is contained in:
Andrey Smirnov
2015-03-11 00:15:56 +03:00
parent 6e1c9afdd9
commit 0467e0c929
+19 -8
View File
@@ -133,19 +133,30 @@ func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"} p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"}
} else { } else {
// stip color marks // stip color marks
var prev rune var inColorMark, inCurly bool
msg = strings.Map(func(r rune) rune { msg = strings.Map(func(r rune) rune {
if prev == '@' { if inColorMark {
prev = 0 if inCurly {
if r == '@' { if r == '}' {
return r inCurly = false
inColorMark = false
return -1
}
} else {
if r == '{' {
inCurly = true
} else if r == '@' {
return '@'
} else {
inColorMark = false
}
} }
return -1 return -1
} }
prev = r
if r == '@' {
return -1
if r == '@' {
inColorMark = true
return -1
} }
return r return r