changing colors in python

G

GujuBoy

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
 
K

Kane

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.aspx?scid=kb;en-us;Q101875
http://alumnus.caltech.edu/~dank/nansi/
 
C

Cappy2112

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 . . .
 
C

Claudio Grondi

The readline module (used e.g. in IPython)
http://sourceforge.net/project/showfiles.php?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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top