Closed resposit closed 2 years ago
It's either a bug or not supported yet :)
A workaround is to apply the colour to the text before and after the newline, but not to the newline itself.
For example:
from prettytable import PrettyTable
from termcolor import colored
rows2 = [["A", colored("line1", "red") + "\n" +colored("line2", "red")]]
t2 = PrettyTable()
t2.add_rows(rows2)
print(t2)
Or with a helper:
from prettytable import PrettyTable
from termcolor import colored
def multiline_colored(text, color):
lines = text.split("\n")
lines = [colored(line, color) for line in lines]
return "\n".join(lines)
rows3 = [["A", multiline_colored("line1\nline2", "red")]]
t3 = PrettyTable()
t3.add_rows(rows3)
print(t3)
Which could also be:
def multiline_colored(text, color):
return "\n".join([colored(line, color) for line in text.split("\n")])
Thank you for the workaround, it works perfectly.
Hello,
I tried to create a table having one cell containing a colored multi-line string (using "\n" ). This seems to break the color of table borders. For example:
Everything is fine with a single-line colored string:
Is it a bug/feature or is there a better way to do this ? Thanks