Reputation: 321
When I use:
print('\27[31mReady!')
Everything else I print keeps the same color. And putting \n after it doesn't do anything. What should this even do? Is there a "\" command to turn back close color codes like this or not?
How do I make the text normal, so everything else I print? I want to make "Ready!" red and everything else back to normal with the easiest tactic (whatever) and maybe if I add another print where it says it should be green then I want that it is green just after the message it should be back to normal.
Upvotes: 2
Views: 5879
Reputation: 54525
When you use
print('\27[31mReady!')
that changes the foreground color. It is one of the standard ECMA-48 control sequences. Most (not all) of the terminals you might use implement the standard SGR 39 as well (reset the foreground color).
print('\27[39mNext!')
Likewise most reset colors (and all other video attributes) on SGR 0 (zero is optional):
print('\27[0mDone!')
print('\27[mDone!')
Reference:
Upvotes: 2
Reputation: 66
When you are finished using the new color, use \27[0m
to reset your colors to the default.
Example:
print('\27[31mReady!\27[0m\n')
Upvotes: 5