Workaround for issue#3: text containing tag like content is not colorized properly.

This commit is contained in:
2022-10-24 17:55:31 +02:00
parent 5c42f7ab9a
commit 001021dac8
2 changed files with 18 additions and 2 deletions

View File

@@ -152,10 +152,26 @@ func trimRow(row []string) []string {
return fixedrow return fixedrow
} }
func maskParens(in string) string {
/*
we need to escape brackets, because the color module treats
text enclosed within < and > as a color tag and therefore the
color tags don't work anymore.
See https://github.com/gookit/color/issues/52 for details.
*/
return strings.ReplaceAll(strings.ReplaceAll(in, ">", "⦘"), "<", "⦗")
}
func unmaskParens(in string) string {
// does the reverse from above during actual output
return strings.ReplaceAll(strings.ReplaceAll(in, "⦘", ">"), "⦗", "<")
}
func colorizeData(c cfg.Config, output string) string { func colorizeData(c cfg.Config, output string) string {
if len(c.Pattern) > 0 && !c.NoColor && color.IsConsole(os.Stdout) { if len(c.Pattern) > 0 && !c.NoColor && color.IsConsole(os.Stdout) {
r := regexp.MustCompile("(" + c.Pattern + ")") r := regexp.MustCompile("(" + c.Pattern + ")")
return r.ReplaceAllString(output, "<bg="+c.MatchBG+";fg="+c.MatchFG+">$1</>") return r.ReplaceAllString(maskParens(output), "<bg="+c.MatchBG+";fg="+c.MatchFG+">$1</>")
} else { } else {
return output return output
} }

View File

@@ -65,7 +65,7 @@ func printData(w io.Writer, c cfg.Config, data *Tabdata) {
} }
func output(w io.Writer, str string) { func output(w io.Writer, str string) {
fmt.Fprint(w, str) fmt.Fprint(w, unmaskParens(str))
} }
/* /*