print color strings?

Gerrit Holl gerrit.holl at pobox.com
Fri Jul 2 06:27:49 EDT 1999


On Thu, Jul 01, 1999 at 09:55:55PM +0000, Donn Cave wrote:
> "Fred L. Drake" <fdrake at cnri.reston.va.us> writes:
> |Gerrit Holl writes:
> |> is there an easy way to print color strings in python?
> |> 
> |> A function like printcolor('brightyellow', 'red', 'spam'), that finds
> |> out on what kind of terminal you are and prints it to stdout?
> |
> | Gerrit,
> |   If you're doing this on Unix, take a look at the ncurses library;
> | there's a Python interface to that.  (I think Oliver Andrich did it;
> | searching DejaNews should find it fairly quickly since this keeps
> | coming up.)
> |   The standard curses module will be documented in the next release of 
> | the Library Reference.
> 
> And if that doesn't work, probably your termcap or terminfo definitions
> lack the necessary information about color escape sequences.  That's a
> widespread problem.
> 
> The color escape sequences that have worked for me on a couple of terminal
> types have been of the form <ESC>[32m, where 32 is a number from 30 to 37.
> I use only 31 to 36.  30 and 37 are more or less black and white, but the
> details vary, so I switch from color to non-color with <ESC>[m instead of
> trying to sort out the details of black and white vs. background and
> foreground.
> 

Ah, thanks. I was forgotten that would work on python the same as in the
bash-shell...

> Of course these are terminal specific escape sequences.  They're evil and
> you must not use them, especially if you have a choice.
> 

Thanks. They're only for my sys.ps1, so it'll be good enough for me..,

But I thought there might be a simpler interface than a whole curses library,
but there's not.

regards,
Gerrit.

-- 
The Dutch Linuxgames homepage:	http://linuxgames.nl.linux.org
Personal homepage:		http://www.nl.linux.org/~gerrit/

Discoverb is a python program (in several languages) which tests the words you
learned by asking it. Homepage: http://www.nl.linux.org/~gerrit/discoverb/
Oh my god! They killed init! You bastards!




More information about the Python-list mailing list