Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
to your account
When i import structlog with colorama installed, my sys.stdout is overwritten by colorama.init() called here:
If I then try to force printing of ANSI color codes in my script while piping the results somewhere, all color codes are stripped which I didn't expect.
Could this be avoided somehow? Perhaps by calling colorama.init(wrap=False), or something else if that breaks on windows?
Example to reproduce:
print('\033[92m' + 'Before structlog import' + '\033[0m sys.stdout:', sys.stdout)
print('\033[92m' + 'After structlog import' + '\033[0m sys.stdout:', sys.stdout)
sys.stdout = sys.__stdout__
print('\033[92m' + 'After resetting' + '\033[0m sys.stdout:', sys.stdout)
Example output where 2nd line has no colors anymore:
/poc.py | cat
Before structlog import sys.stdout: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
After structlog import sys.stdout: <colorama.ansitowin32.StreamWrapper object at 0x7f1c0c981b70>
After resetting sys.stdout: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>
The text was updated successfully, but these errors were encountered:
Hm, that's very unfortunate indeed. Maybe we should make colorama.init() lazy?
Sorry, something went wrong.
I hope I fixed it in 3b534af – would you mind checking if master fixes the problem for you before I release? TIA
Successfully merging a pull request may close this issue.