I'm writing various utilities, and I'm really liking colorized text. Nothing fancy, just using escape sequences. I've created a simple class that has a pprint(msg, color) function. I've got it working rather easily after finding the codes here.
The problem that I'm having is that I should be able to turn off the color after printing. For example, let's say a user runs my program that prints almost everything in the default terminal color, but there is an error, and I want to print the error in red. I prefix my error message with '33[0;32m', and the message is in red. Unfortunately, all text is red until I change it. That's generally fine while my program is running because I know what color the messages should be. However, the color remains after my program ends. Basically, I'd like to read the current color when my program starts, and restore it when finished. The same way that scripts restore the pwd when exiting.
How do I read the current escape sequence?
System:
Red Hat 5.x
Bash
Python 2.3
Thanks for the help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…