Contributors:
Horacio Duran <horacio.duran@gmail.com> (utf-8 patch for IRC bot)
+Rainer Michael Schmid (bugfix: crash when redirecting output to a file in 1.1)
Anders Sandvig (cmdline -l, -d, and -t flags)
"""
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 ""
print >> sys.stderr, "No such action: ", options['action']
sys.exit(1)
+def printNicely(string):
+ if sys.stdout.encoding:
+ print string.encode(sys.stdout.encoding, 'replace')
+ else:
+ print string.encode('utf-8')
+
class StatusAction(Action):
def __call__(self, twitter, options):
statuses = self.getStatuses(twitter, options)
for status in statuses:
statusStr = sf(status, options)
if statusStr.strip():
- print statusStr.encode(sys.stdout.encoding, 'replace')
+ printNicely(statusStr)
class AdminAction(Action):
def __call__(self, twitter, options):
print
print e
else:
- print af(options['action'], user).encode(sys.stdout.encoding, 'replace')
+ printNicely(af(options['action'], user))
class FriendsAction(StatusAction):
def getStatuses(self, twitter, options):