python - Read the current text color in a xterm -


i'm writing various utilities, , i'm liking colorized text. nothing fancy, using escape sequences. i've created simple class has pprint(msg, color) function. i've got working rather after finding codes here.

the problem i'm having should able turn off color after printing. example, let's user runs program prints in default terminal color, there error, , want print error in red. prefix error message '\033[0;32m', , message in red. unfortunately, text red until change it. that's fine while program running because know color messages should be. however, color remains after program ends. basically, i'd read current color when program starts, , restore when finished. same way scripts restore pwd when exiting.

how read current escape sequence?

system: red hat 5.x bash python 2.3

thanks help.

i don't believe that's possible , it's unlikely portable if were. best can send sgr0 resets attributes default (not previous). on xterms, sgr0 esc[m. if want reset colors , not affect other attributes, send op on xterms esc[39;49m.

these codes should not hardcoded. should use terminfo, termcap or [n]curses.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -