halo icon indicating copy to clipboard operation
halo copied to clipboard

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

Open li-wjohnson opened this issue 5 years ago • 1 comments

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

  • [x] Your branch is up-to-date with the base branch
  • [ ] You've included at least one test if this is a new feature
  • [x] All tests are passing

Related Issues and Discussions

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

People to notify

li-wjohnson avatar Sep 09 '20 13:09 li-wjohnson

Thanks

lemassykoi avatar Jan 22 '21 03:01 lemassykoi