Reapply r106708 "Include initial use of colorama"

isatty() wasn't defined on Windows, causing it to crash.

R=dpranke@chromium.org
BUG=
TEST=manually gclient sync on windows


Review URL: http://codereview.chromium.org/8371006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@106865 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient.py b/gclient.py
index 8a848cf..e29eaa8 100644
--- a/gclient.py
+++ b/gclient.py
@@ -69,6 +69,9 @@
 import gclient_utils
 from third_party.repo.progress import Progress
 import subprocess2
+from third_party import colorama
+# Import shortcut.
+from third_party.colorama import Fore
 
 
 def attr(attribute, data):
@@ -1483,6 +1486,7 @@
   if sys.hexversion < 0x02050000:
     print >> sys.stderr, (
         '\nYour python version is unsupported, please upgrade.\n')
+  colorama.init()
   try:
     # Make stdout auto-flush so buildbot doesn't kill us during lengthy
     # operations. Python as a strong tendency to buffer sys.stdout.
@@ -1492,9 +1496,14 @@
     # Do it late so all commands are listed.
     # Unused variable 'usage'
     # pylint: disable=W0612
-    CMDhelp.usage = ('\n\nCommands are:\n' + '\n'.join([
-        '  %-10s %s' % (fn[3:], Command(fn[3:]).__doc__.split('\n')[0].strip())
-        for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')]))
+    def to_str(fn):
+      return (
+          '  %s%-10s%s' % (Fore.GREEN, fn[3:], Fore.RESET) +
+          ' %s' % Command(fn[3:]).__doc__.split('\n')[0].strip())
+    cmds = (
+        to_str(fn) for fn in dir(sys.modules[__name__]) if fn.startswith('CMD')
+    )
+    CMDhelp.usage = '\n\nCommands are:\n' + '\n'.join(cmds)
     parser = Parser()
     if argv:
       command = Command(argv[0])