Skip to content
New issue

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? Sign in to your account

Provide isinitialized function #128

Open
bdarnell opened this issue Apr 20, 2017 · 4 comments
Open

Provide isinitialized function #128

bdarnell opened this issue Apr 20, 2017 · 4 comments

Comments

@bdarnell
Copy link

In tornadoweb/tornado#2019, we need a way to tell whether colorama is enabled (analogous to the check a curses-based system would do by looking at the TERM environment variable). There doesn't appear to be any documented way to do this. We're considering a couple of undocumented hacks to discover this, but it would be better to have a documented and supported solution.

@mivade
Copy link

mivade commented Apr 20, 2017

Specifically, the hacks are to either check that sys.stderr is the same as colorama.initialise.wrapped_stderr or that sys.stderr is (on Windows) an instance of colorama.ansitowin32.StreamWrapper.

@wiggin15
Copy link
Collaborator

The first suggested fix (check if sys.stderr is wrapped_stderr) won't work for sure because in some cases wrapped_stderr could be the original sys.stderr (not really a wrapped stream) - so they could be equal even if colorama is not in effect. This happens when wrapper.should_wrap() is False.

@wiggin15
Copy link
Collaborator

What that means is that you can call colorama.init and it will not wrap anything. So maybe what we need is not isinitialized, but is_wrapped?
Something like this:

def is_wrapped():
    return (isinstance(sys.stdout, StreamWrapper) or
            isinstance(sys.stderr, StreamWrapper))

@bdarnell
Copy link
Author

I think is_wrapped is too specific in light of #104 - in the future colorama might recognize that the terminal supports color without wrapping anything. What we want is basically "does stderr support color".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants