问题
I am using "termcolor" and "colored" for printing some colored words in my test script.
>>> from termcolor import colored
>>> result = colored("pass", "red")
>>> print result
pass ----> ("appears in red")
>>> result = '\033[1m' + result + '\033[0m'
>>> print result
pass ------> ("appears in red and bold")
The above works fine on Mac and CentOS but fails to print it in red or bold in eclipse (on CentOS). It prints something like this "?[32mPASS?[0m" -- which does not help much..
I want to add that, the above text is seen on an XML file opened in eclipse. The encoding format probably has a role to play here. Right now I see "UTF-8" in the XML as encoding format.
回答1:
The issue is that unlike most terminals, the default Eclipse console does not know how to deal with the ANSI escape sequences that provide the color information.
There is however a plugin called ANSI Escape in Console available from the Eclipse marketplace that augments the standard Eclipse console to be able to deal with these ANSI color escape sequences:
http://marketplace.eclipse.org/content/ansi-escape-console#.U978fXV515Q
The plugin author's blog provides some more information:
http://mihai-nita.net/2013/06/03/eclipse-plugin-ansi-in-console/
来源:https://stackoverflow.com/questions/25111324/support-ansi-terminal-color-escape-sequences-in-xml