no bold when -O

This commit is contained in:
juke 2011-03-08 19:00:18 +01:00 committed by Romain Bignon
commit 480e53cb00
2 changed files with 27 additions and 8 deletions

View file

@ -34,15 +34,16 @@ class MessageFormatter(IFormatter):
pass pass
def format_dict(self, item): def format_dict(self, item):
result = u'%sTitle:%s %s\n' % (ReplApplication.BOLD, print self.outfile
ReplApplication.NC, item['title']) result = u'%sTitle:%s %s\n' % (self.BOLD,
result += u'%sDate:%s %s\n' % (ReplApplication.BOLD, self.NC, item['title'])
ReplApplication.NC, item['date']) result += u'%sDate:%s %s\n' % (self.BOLD,
result += u'%sFrom:%s %s\n' % (ReplApplication.BOLD, self.NC, item['date'])
ReplApplication.NC, item['sender']) result += u'%sFrom:%s %s\n' % (self.BOLD,
self.NC, item['sender'])
if item['receivers']: if item['receivers']:
result += u'%sTo:%s %s\n' % (ReplApplication.BOLD, result += u'%sTo:%s %s\n' % (self.BOLD,
ReplApplication.NC, self.NC,
', '.join(item['receivers'])) ', '.join(item['receivers']))
if item['flags'] & Message.IS_HTML: if item['flags'] & Message.IS_HTML:

View file

@ -43,6 +43,7 @@ else:
from weboob.capabilities.base import CapBaseObject, FieldNotFound from weboob.capabilities.base import CapBaseObject, FieldNotFound
from weboob.tools.ordereddict import OrderedDict from weboob.tools.ordereddict import OrderedDict
from weboob.tools.application.console import ConsoleApplication
__all__ = ['IFormatter', 'MandatoryFieldsNotFound'] __all__ = ['IFormatter', 'MandatoryFieldsNotFound']
@ -57,6 +58,21 @@ class IFormatter(object):
MANDATORY_FIELDS = None 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): def __init__(self, display_keys=True, display_header=True, return_only=False, outfile=sys.stdout):
self.display_keys = display_keys self.display_keys = display_keys
self.display_header = display_header self.display_header = display_header
@ -66,9 +82,11 @@ class IFormatter(object):
self.termrows = 0 self.termrows = 0
self.outfile = outfile self.outfile = outfile
# XXX if stdin is not a tty, it seems that the command fails. # 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()): if os.isatty(sys.stdout.fileno()) and os.isatty(sys.stdin.fileno()):
self.termrows = int(os.popen('stty size', 'r').read().split()[0]) self.termrows = int(os.popen('stty size', 'r').read().split()[0])
def after_format(self, formatted): def after_format(self, formatted):
if self.outfile != sys.stdout: if self.outfile != sys.stdout:
with open(self.outfile, "a+") as outfile: with open(self.outfile, "a+") as outfile: