By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,598 Members | 1,498 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,598 IT Pros & Developers. It's quick & easy.

changing colors in python

P: n/a
i have a ansi.py file that i use in LINUX to change the text color to
STDOUT when i use the "print" function...but when i move this ansi.py
file over the windows...it does not work

is there a version of ansi.py i can use for windows/linux....

please help

Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
To convert ansi escape sequences into text colors you need a terminal
that understands what you are doing. Linux does this by default; dos
and windows do not. You need to have an extra program in memory. The
conventional approach is the "ANSI.SYS" driver which probably still
ships with Windows (link below).

I've included a link to nansi.com but haven't used it with any windows
version > 3.1. If memory serves it is significantly faster.

http://support.microsoft.com/default...;en-us;Q101875
http://alumnus.caltech.edu/~dank/nansi/

Jul 19 '05 #2

P: n/a
AFAIK, the cmd.exe program on Win2K/XP doesn't support ANSI escape
sequences. There are various other options on windows but they
probably won't work on Linux.

http://newcenturycomputers.net/projects/wconio.html
http://effbot.org/zone/console-handbook.htm

Jul 19 '05 #3

P: n/a
if you are talking about writing text console program only , for
Windows, then just use the color command- but you will need a handle to
that console window-

C:\>help color
Sets the default console foreground and background colors.

COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first
corresponds to the background; the second the foreground. Each digit
can be any of the following values:

0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.
Press any key to continue . . .

Jul 19 '05 #4

P: n/a
The readline module (used e.g. in IPython)
http://sourceforge.net/project/showf...group_id=82407
provides the Console.py
script and in my own version of it, the (extended)
Console() class supports any ANSI escape
sequences of the form ESC[#m and ESC[#,#m ,
making it possible to set any by console supported
text and background colors.
http://people.freenet.de/AiTI-IT/Python/Console.py

Replace the Console.py of the readline
module with my extended version and run
it as main script to see the coloured output
looking into the code to see how it comes.

Claudio
http://www.python.org/moin/ClaudioGrondi
"GujuBoy" <di*****@gmail.com> schrieb im Newsbeitrag
news:11**********************@z14g2000cwz.googlegr oups.com...
i have a ansi.py file that i use in LINUX to change the text color to
STDOUT when i use the "print" function...but when i move this ansi.py
file over the windows...it does not work

is there a version of ansi.py i can use for windows/linux....

please help

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.