manrajgrover / halo

💫 Beautiful spinners for terminal, IPython and Jupyter
MIT License
2.86k stars 148 forks source link

#151: Remove colorama init, Only use colorama on windows #152

Open li-wjohnson opened 3 years ago

li-wjohnson commented 3 years ago

Description of new feature, or changes

Colorama.init escapes all ansi codes by default on stdout / stderr when not in a tty, regardless of OS, which breaks color output. Instead of globally affecting stdout and stderr at library import time, only wrap the stream that Halo uses.

Also, I turned colorama into a conditional dependency, seeing as its only needed on windows.

Something to note: there's a change in behavior here.

Previously: Windows Other
stdout isatty() convert ansi
stdout not isatty() strip strip
stream isatty() ansi ansi
stream not isatty() ansi ansi
Now: Windows Other
stdout isatty() convert ansi
stdout not isatty() strip ansi
stream isatty() convert ansi
stream not isatty() strip ansi

(convert: ansi converted to win32 calls, strip: ansi removed, ansi: ansi unchanged)

You may consider using colorama to strip the output when the stream is not a tty, regardless of OS, but you should likely have a way to override the behavior. (See also: https://github.com/tartley/colorama/pull/230)

Checklist

Related Issues and Discussions

https://github.com/manrajgrover/halo/issues/151

People to notify

lemassykoi commented 3 years ago

Thanks