Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python color output and paging output

Tags:

python

colors

Python 2.4.x - I cannot install any non-standard modules. *nix environment.

So I've got an output that I have some color in using ansi coloring. Works great. But the output is so long I needed to either pipe to less or use pydoc's page()

Once I do either - the color turns into

ESC[1;36m TEXT TO FOLLOW: ESC[1;37m

I saw over at Cucumber: pipe output without losing color that Adam says that lots of output that is piped lose it's color - but if sent to terminal it's just fine.

Using pydoc's ttypager retains the color output - but doesn't provide a "less" type feature (scrolling back up).

How do I get the best of both worlds? Color and Less type functionality?

Thank you.

like image 435
Chasester Avatar asked Oct 27 '11 22:10

Chasester


1 Answers

Use the -R flag with less. This will cause it to output ANSI color escape sequences as they are instead of changing them. It appears to be supported on both my Debian box and my Mac OS X box, which is a good indication that -R is widely supported.

like image 165
Dietrich Epp Avatar answered Oct 27 '22 19:10

Dietrich Epp