We might be running in an environment that captures stdout
by using some replacement class. Do not fail in that case
but just disble coloring
_ANSI_ESCAPE_SURROUND = '\x1b[{}m{}\x1b[0m'
-_STDOUT_IS_TTY = stdout.isatty()
+# only color output if we are writing output to a terminal (not a file or so)
+try:
+ _STDOUT_IS_TTY = stdout.isatty()
+except Exception:
+ # stdout might be some wrapper around the real thing to capture output
+ _STDOUT_IS_TTY = False
def colored(text, foreground=None, background=None, style=None):