Skip to content

Commit

Permalink
Add transparent support for colour on Windows
Browse files Browse the repository at this point in the history
If the colorama package is present, we use that to provide support for
coloured output on Windows. Otherwise, we fall back to no colour.
  • Loading branch information
nickstenning committed Feb 7, 2015
1 parent 2ddc095 commit a1b2cb5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions honcho/printer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import namedtuple
import sys

from .compat import ON_WINDOWS

Message = namedtuple("Message", "type data time name colour")

Expand Down Expand Up @@ -51,3 +52,16 @@ def _ansi(code):

def _colour_string(colour, s):
return '{0}{1}{2}'.format(_ansi(colour), s, _ansi(0))


if ON_WINDOWS:
# The colorama package provides transparent support for ANSI colour codes
# on Win32 platforms. We try and import and configure that, but fall back
# to no colour if we fail.
try:
import colorama
except ImportError:
def _colour_string(colour, s): # noqa
return s
else:
colorama.init()

0 comments on commit a1b2cb5

Please sign in to comment.