ANSI colored output: How to determine how python was called?

Donn Cave donn at u.washington.edu
Mon May 20 18:01:58 EDT 2002


Quoth pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois?= Pinard):
...
| The normal way to check for colour terminal support is through terminal
| info capabilities (terminfo).  Check for `op', 'AF', `AB', `Sf', `Sb',
| 'Co', `pa' and `NC' capabilities, in particular.  I forgot details as of
| now, but remember I had to fight a bit to get everything right.

That is indeed the only bona fide declaration of color capabilities,
but it's good for only a small subset of the color capable terminal
emulations.  If they're coming in as "vt102", it won't help.

I personally could benefit from it, as I have my own terminfo description
and could easily add those color attributes - but then lynx and other
color aware applications will do really horrible things with them,
distasteful and unreadable.  So I use the colors in place of underline
and bold modes, and leave the color attributes undefined.  GNU ls
really does it right, as far as I'm concerned - there's a flag to
say whether you'd like to use color, and then an optional environment
variable to control the actual choice of colors (colors vary greatly
between one emulation and another, and of sometimes you have a black
background instead of white, so some control of the colors may be
needed just to get a readable display.)

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list