Skip to content
Snippets Groups Projects
Commit a5aea15a authored by Erik Johnston's avatar Erik Johnston
Browse files

Assume isatty is always defined, and catch AttributeError. Also don't bother...

Assume isatty is always defined, and catch AttributeError. Also don't bother checking colour==Normal
parent 1af16acd
No related branches found
No related tags found
No related merge requests found
...@@ -50,10 +50,14 @@ def pid_running(pid): ...@@ -50,10 +50,14 @@ def pid_running(pid):
def write(message, colour=NORMAL, stream=sys.stdout): def write(message, colour=NORMAL, stream=sys.stdout):
# Lets check if we're writing to a TTY before colouring # Lets check if we're writing to a TTY before colouring
should_colour = False should_colour = False
if stream in (sys.stdout, sys.stderr): try:
should_colour = stream.isatty() should_colour = stream.isatty()
except AttributeError:
# Just in case `isatty` isn't defined on everything. The python
# docs are incredibly vague.
pass
if not should_colour or colour == NORMAL: if not should_colour:
stream.write(message + "\n") stream.write(message + "\n")
else: else:
stream.write(colour + message + NORMAL + "\n") stream.write(colour + message + NORMAL + "\n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment