+class SearchFormatter(object):
+ def __call__(self, result, options):
+ return("%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 '\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 ("%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 = {}