Perl has the excellent module Term::ANSIScreen
for doing all sorts of fancy cursor movement and terminal color control. I'd like to reimplement a program that's currently in Perl in Python instead, but the terminal ANSI colors are key to its function. Is anyone aware of an equivalent?
views:
398answers:
4
+2
A:
While I haven't used it myself, I believe the curses library is commonly used for this:
http://docs.python.org/library/curses.html
And the How-to:
http://docs.python.org/howto/curses.html#curses-howto
Unfortunatly, this module doesn't appear to be available in the standard library for windows. This site apparently has a windows solution:
monkut
2009-01-23 00:48:12
Not quite the same I think. You need to make a "window" with curses, whereas with Term::ANSIScreen I can print an arbitrary number of lines to the terminal using the standard print function.
Kamil Kisiel
2009-01-23 00:56:22
Yeah, it doesn't look like it's meant to deal with the current terminal. It looks like Jeff may have what your looking for.
monkut
2009-01-23 01:35:00
+3
A:
Here's a cookbook recipe on ActiveState to get you started. It covers colors and positioning.
Jeff Bauer
2009-01-23 01:19:26
Perfect. This is exactly what I was looking for. Now I just have to bundle it up in to a nice module and clean up the code a bit. Thanks.
Kamil Kisiel
2009-01-23 05:30:17
+3
A:
If you only need colors You may want to borrow the implementation from pygments. IMO it's much cleaner than the one from ActiveState
http://dev.pocoo.org/hg/pygments-main/file/b2deea5b5030/pygments/console.py
Jorge Vargas
2009-12-29 21:18:25