tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.56k stars 252 forks source link

init autoreset=True breaks colors in terminal output #258

Closed Serfentum closed 4 years ago

Serfentum commented 4 years ago

Hi! I'm really sorry, can't understand why my shell works in such way, but when I write code like this

import colorama
from colorama import Fore

colorama.init(autoreset=True)
print(Fore.Green, 'Some text', sep='')

And run it in my terminal there is no colors at all( If I don't set autoreset to True and reset style manually (via Fore.RESET) it works fine except burden of manual style resetting. What's wrong with my approach? In pycharm code with colorama.init(autoreset=True, convert=False, strip=False) works ok - it outputs colored text

I have ubuntu 16.04 and GNOME Terminal 3.18.3, thank you very much!

wiggin15 commented 4 years ago

Hi. This indeed looks odd, but apparently expected, as "autoreset" resets the colors after each print argument. In your case, the code prints to the terminal: Green (reset), 'Some text' (reset) and this is why "Some text" is printed without the green color. Try using:

print(Fore.GREEN + 'Some text', sep='')
Serfentum commented 4 years ago

Thank you very much, I missed it!