+
+class ListsFormatter(object):
+ def __call__(self, list):
+ if list['description']:
+ list_str = u"%-30s (%s)" % (list['name'], list['description'])
+ else:
+ list_str = u"%-30s" % (list['name'])
+ return u"%s\n" % list_str
+
+class ListsVerboseFormatter(object):
+ def __call__(self, list):
+ list_str = u"%-30s\n description: %s\n members: %s\n mode:%s\n" % (list['name'], list['description'], list['member_count'], list['mode'])
+ return list_str
+
+class AnsiListsFormatter(object):
+ def __init__(self):
+ self._colourMap = ansi.ColourMap()
+
+ def __call__(self, list):
+ colour = self._colourMap.colourFor(list['name'])
+ return (u"%s%-15s%s %s" %(
+ ansi.cmdColour(colour), list['name'],
+ ansi.cmdReset(), list['description']))
+
+
+class AdminFormatter(object):
+ def __call__(self, action, user):
+ user_str = u"%s (%s)" %(user['screen_name'], user['name'])
+ if action == "follow":
+ return u"You are now following %s.\n" %(user_str)
+ else:
+ return u"You are no longer following %s.\n" %(user_str)
+
+class VerboseAdminFormatter(object):
+ def __call__(self, action, user):
+ return(u"-- %s: %s (%s): %s" % (
+ "Following" if action == "follow" else "Leaving",
+ user['screen_name'],
+ user['name'],
+ user['url']))
+
+class SearchFormatter(object):
+ def __call__(self, result, options):
+ return(u"%s%s %s" %(
+ get_time_string(result, options, "%a, %d %b %Y %H:%M:%S +0000"),
+ result['from_user'], result['text']))
+
+class VerboseSearchFormatter(SearchFormatter):
+ pass #Default to the regular one
+
+class URLSearchFormatter(object):
+ urlmatch = re.compile(r'https?://\S+')
+ def __call__(self, result, options):
+ urls = self.urlmatch.findall(result['text'])
+ return u'\n'.join(urls) if urls else ""
+
+class AnsiSearchFormatter(object):
+ def __init__(self):
+ self._colourMap = ansi.ColourMap()
+
+ def __call__(self, result, options):
+ colour = self._colourMap.colourFor(result['from_user'])
+ return (u"%s%s%s%s %s" %(
+ get_time_string(result, options, "%a, %d %b %Y %H:%M:%S +0000"),
+ ansi.cmdColour(colour), result['from_user'],
+ ansi.cmdReset(), result['text']))
+
+_term_encoding = None
+def get_term_encoding():
+ global _term_encoding
+ if not _term_encoding:
+ lang = os.getenv('LANG', 'unknown.UTF-8').split('.')
+ if lang[1:]:
+ _term_encoding = lang[1]
+ else:
+ _term_encoding = 'UTF-8'
+ return _term_encoding
+
+formatters = {}
+status_formatters = {