I have read a couple of URLs about setting colour in terminal. But after a colour change a while later I'd like to reset into previous colour. How can I get current colour ? (I'd like to avoid third party libraries and use only batteries included ;-)) Especially (from (python) colour printing with decorator in a function ):
import sys
green = '\033[01;32m'
red = '\033[01;31m'
... remember current colours here ...
sys.stdout.write(green+"Hello ")
sys.stderr.write(red+"world!")
You can return default color the same way you colorize your texts:
native = '\033[m'
sys.stdout.write(native)
Thus temporary coloring may be achieved with
print green + 'Hello' + native
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With