Bugfix: when redirecting to a file (not a tty) neuter the ansi formatter
functionality to prevent garbage in file. Also, use utf-8 encoding when
redirecting to file.
"""
import itertools
+import sys
ESC = chr(0x1B)
RESET = "0"
return self._cmap[string]
def cmdReset():
- return ESC + "[0m"
+ if sys.stdout.isatty():
+ return ESC + "[0m"
+ else:
+ return ""
def cmdColour(colour):
- return ESC + "[" + colour + "m"
+ if sys.stdout.isatty():
+ return ESC + "[" + colour + "m"
+ else:
+ return ""
for status in statuses:
statusStr = sf(status)
if statusStr.strip():
- print statusStr.encode(sys.stdout.encoding, 'replace')
+ if sys.stdout.encoding:
+ print statusStr.encode(sys.stdout.encoding, 'replace')
+ else:
+ print statusStr.encode('utf-8')
class AdminAction(Action):
def __call__(self, twitter, options):