colorama
colorama copied to clipboard
Auto reset doesn't function in uncommon situations
Py 2.7.13
init(autoreset=True)
I'd like to use different colors in a single line, so what I did was:
out = eval("co.p%d('%s') + co.white(' : ')" % (self.p, self.s))
print out
But if I make co.p%d('%s')
return like Fore.LIGHTWHITE_EX + Back.CYAN + s
and co.white(' : ')
return like Fore.LIGHTWHITE_EX + s
, Back.CYAN
will take effect on :
.
Finally I had to add + Fore.RESET + Back.RESET
to each return.
It may be nicer if auto reset can function not only after stdout...
But after thinking it over, I doubted if auto reset was just expected to be used in common situations...
I'd like to use different colors in a single line
autoreset
is meant to take effect only after a line is printed. It doesn't have an effect inside a single line. So if you print something like:
`Fore.LIGHTWHITE_EX + Back.CYAN + s + Fore.LIGHTWHITE_EX + ' : '`
there is nothing that resets Back.CYAN
and the ':'
will get a cyan background. You will have to add Back.RESET
in between. This is the expected behavior.