diff --git a/weboob/applications/boobmsg/boobmsg.py b/weboob/applications/boobmsg/boobmsg.py index 51ef3c10..f7f6ff07 100644 --- a/weboob/applications/boobmsg/boobmsg.py +++ b/weboob/applications/boobmsg/boobmsg.py @@ -34,15 +34,16 @@ class MessageFormatter(IFormatter): pass def format_dict(self, item): - result = u'%sTitle:%s %s\n' % (ReplApplication.BOLD, - ReplApplication.NC, item['title']) - result += u'%sDate:%s %s\n' % (ReplApplication.BOLD, - ReplApplication.NC, item['date']) - result += u'%sFrom:%s %s\n' % (ReplApplication.BOLD, - ReplApplication.NC, item['sender']) + print self.outfile + result = u'%sTitle:%s %s\n' % (self.BOLD, + self.NC, item['title']) + result += u'%sDate:%s %s\n' % (self.BOLD, + self.NC, item['date']) + result += u'%sFrom:%s %s\n' % (self.BOLD, + self.NC, item['sender']) if item['receivers']: - result += u'%sTo:%s %s\n' % (ReplApplication.BOLD, - ReplApplication.NC, + result += u'%sTo:%s %s\n' % (self.BOLD, + self.NC, ', '.join(item['receivers'])) if item['flags'] & Message.IS_HTML: diff --git a/weboob/tools/application/formatters/iformatter.py b/weboob/tools/application/formatters/iformatter.py index edb798ac..f1c73ed6 100644 --- a/weboob/tools/application/formatters/iformatter.py +++ b/weboob/tools/application/formatters/iformatter.py @@ -43,6 +43,7 @@ else: from weboob.capabilities.base import CapBaseObject, FieldNotFound from weboob.tools.ordereddict import OrderedDict +from weboob.tools.application.console import ConsoleApplication __all__ = ['IFormatter', 'MandatoryFieldsNotFound'] @@ -57,6 +58,21 @@ class IFormatter(object): MANDATORY_FIELDS = None + def get_bold(self): + if self.outfile != sys.stdout: + return '' + else: + return ConsoleApplication.BOLD + + def get_nc(self): + if self.outfile != sys.stdout: + return '' + else: + return ConsoleApplication.NC + + BOLD = property(get_bold) + NC = property(get_nc) + def __init__(self, display_keys=True, display_header=True, return_only=False, outfile=sys.stdout): self.display_keys = display_keys self.display_header = display_header @@ -66,9 +82,11 @@ class IFormatter(object): self.termrows = 0 self.outfile = outfile # XXX if stdin is not a tty, it seems that the command fails. + if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()): self.termrows = int(os.popen('stty size', 'r').read().split()[0]) + def after_format(self, formatted): if self.outfile != sys.stdout: with open(self.outfile, "a+") as outfile: