]> jfr.im git - z_archive/twitter.git/blobdiff - twitter/ansi.py
make cmd client understand any language
[z_archive/twitter.git] / twitter / ansi.py
index ae99ddb786daa09470fc05675bb62ead7c6a9f5d..0a8456444987783b817e99efa44974f3ad0a541e 100644 (file)
@@ -15,6 +15,7 @@ Support for ANSI colours in command-line client.
 """
 
 import itertools
+import sys
 
 ESC = chr(0x1B)
 RESET = "0"
@@ -50,16 +51,22 @@ class ColourMap(object):
             self._cmap[string] = self._colourIter.next()
         return self._cmap[string]
 
+def cmdReset():
+    ''' Returns the ansi cmd colour for a RESET '''
+    if sys.stdout.isatty():
+        return ESC + "[0m"
+    else:
+        return ""
+
 def cmdColour(colour):
     '''
     Return the ansi cmd colour (i.e. escape sequence)
     for the ansi `colour` value
     '''
-    return ESC + "[" + colour + "m"
-
-def cmdReset():
-    ''' Returns the ansi cmd colour for a RESET '''
-    return cmdColour(RESET)
+    if sys.stdout.isatty():
+        return ESC + "[" + colour + "m"
+    else:
+        return ""
 
 def cmdColourNamed(colour):
     ''' Return the ansi cmdColour for a given named `colour` '''