mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 12:31:06 +01:00
Workaround for issue#3: text containing tag like content is not colorized properly.
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user