{"action":"created","issue":{"url":"https://api.github.com/repos/tartley/colorama/issues/39","labels_url":"https://api.github.com/repos/tartley/colorama/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/tartley/colorama/issues/39/comments","events_url":"https://api.github.com/repos/tartley/colorama/issues/39/events","html_url":"https://github.com/tartley/colorama/issues/39","id":57795457,"number":39,"title":"play nicely with other stdout/stderr wrappers","user":{"login":"tartley","id":137979,"avatar_url":"https://avatars.githubusercontent.com/u/137979?v=3","gravatar_id":"","url":"https://api.github.com/users/tartley","html_url":"https://github.com/tartley","followers_url":"https://api.github.com/users/tartley/followers","following_url":"https://api.github.com/users/tartley/following{/other_user}","gists_url":"https://api.github.com/users/tartley/gists{/gist_id}","starred_url":"https://api.github.com/users/tartley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tartley/subscriptions","organizations_url":"https://api.github.com/users/tartley/orgs","repos_url":"https://api.github.com/users/tartley/repos","events_url":"https://api.github.com/users/tartley/events{/privacy}","received_events_url":"https://api.github.com/users/tartley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-16T11:53:28Z","updated_at":"2015-02-16T11:54:43Z","closed_at":null,"body":"Migrated from https://code.google.com/p/colorama/issues/detail?id=41\r\nReported by eallik, Jan 21, 2013\r\n\r\nTake a look at the wrapper provided at http://stackoverflow.com/a/3259271/247623 --it reliably enables Unicode output on cmd.exe; unquestionably useful. However, it turns out that colorama does not work out of the box in combination with that wrapper.\r\n\r\nThe reasons for this are:\r\n* first of all, colorama needs to be activated after that wrapper because the other wrapper is more low level/fundamental\r\n* colorama remembers the `orig_stdout` and `orig_stderr` references in its `initialise.py` at import time, thus, by the time `init()` is called, any wrappings that have taken place before `import colorama` and `init()` are effectively cancelled/ignored\r\n* colorama does not convert ANSI codes for streams who are not `.isatty() == True`; I'm not sure why such check was implemented in the first place, but it looks to me that colorama works perfectly well with streams that do not have such property.\r\n\r\nThe current workaround is to manually update `orig_stdout` and `orig_stderr` with fresh values from `sys.stdout` and `sys.stderr` respectively, and also do `sys.stdout.isatty = sys.stderr.isatty = lambda: True` to satisfy the `is_a_tty` check in `ansitowin32.py`. However, it would be nice if colorama did not require such workaround to compose nicely with other wrappers.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/tartley/colorama/issues/comments/74497981","html_url":"https://github.com/tartley/colorama/issues/39#issuecomment-74497981","issue_url":"https://api.github.com/repos/tartley/colorama/issues/39","id":74497981,"user":{"login":"tartley","id":137979,"avatar_url":"https://avatars.githubusercontent.com/u/137979?v=3","gravatar_id":"","url":"https://api.github.com/users/tartley","html_url":"https://github.com/tartley","followers_url":"https://api.github.com/users/tartley/followers","following_url":"https://api.github.com/users/tartley/following{/other_user}","gists_url":"https://api.github.com/users/tartley/gists{/gist_id}","starred_url":"https://api.github.com/users/tartley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tartley/subscriptions","organizations_url":"https://api.github.com/users/tartley/orgs","repos_url":"https://api.github.com/users/tartley/repos","events_url":"https://api.github.com/users/tartley/events{/privacy}","received_events_url":"https://api.github.com/users/tartley/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T11:54:43Z","updated_at":"2015-02-16T11:54:43Z","body":"from dbrackma\r\nI think you should keep the isatty check, as it protects against trying to add color to stdout piped to a file, for example.  The above reference unicode wrapper has a bug where it always returns False for isatty.  The fix for that is to return False only if the UnicodeStream.hConsole is None, in which case it is not a true terminal."}}