ANSI colored output: How to determine how python was called?
Fernando PĂ©rez
fperez528 at yahoo.com
Mon May 20 19:41:22 EDT 2002
Pearu Peterson wrote:
> So, my question is:
>
> Are there alternative (hopefully better) ways to decide whether the
> output "device" of python stdout supports ANSI colored text or not?
>
> Thanks,
> Pearu
Good luck Pearu. Let me know if you find a _robust_ solution to this problem.
IPython uses a lot of colors (by the way, feel free to grab the classes I've
made for it which automate color table management, scheme switching, etc.).
And support in various terminals is very spotty and inconsistent. Even xterm
isn't fully compliant, and rxvt (I think) has a few quirks. I've found
konsole and gnome-terminal to have much better behavior. The CDE dt-terminal
is its own bag of problems.
As far as I can tell, there's no sane way of determining from inside the code
if a given terminal will put out garbage or if it will put out properly
colored text. And when you are trying to run colored text through pagers like
more/less, a whole new can of worms opens up! This weekend I added colored
object introspection to IPython which works beautifully on my Mandrake 8.2
laptop, just to find out that the Redhat 7.2 machines in my office spit out
pure garbage with it!
So if you can figure out a permanent, solid solution please drop me a line on
it.
Cheers,
f.
More information about the Python-list
mailing list