From 0467e0c929adff480e0a3591e8201084bb3f3871 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 11 Mar 2015 00:15:56 +0300 Subject: [PATCH] More sophisticated color codes stripper. #217 --- console/progress.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/console/progress.go b/console/progress.go index 398add43..a10980ea 100644 --- a/console/progress.go +++ b/console/progress.go @@ -133,19 +133,30 @@ func (p *Progress) ColoredPrintf(msg string, a ...interface{}) { p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"} } else { // stip color marks - var prev rune + var inColorMark, inCurly bool msg = strings.Map(func(r rune) rune { - if prev == '@' { - prev = 0 - if r == '@' { - return r + if inColorMark { + if inCurly { + if r == '}' { + inCurly = false + inColorMark = false + return -1 + } + } else { + if r == '{' { + inCurly = true + } else if r == '@' { + return '@' + } else { + inColorMark = false + } } return -1 } - prev = r - if r == '@' { - return -1 + if r == '@' { + inColorMark = true + return -1 } return r