split out logic for getting link and balloon colour as well as the hyphen style

Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
Mattias Andrée 2013-08-17 07:31:45 +02:00
parent fd6863c37a
commit f763d3dae6

View file

@ -924,21 +924,11 @@ class Ponysay():
balloon = self.__getBalloon(balloonfile) if args.opts['-o'] is None else None
## Get hyphen style
hyphen = os.environ['PONYSAY_WRAP_HYPHEN'] if 'PONYSAY_WRAP_HYPHEN' in os.environ else None
if (hyphen is None) or (len(hyphen) == 0):
hyphen = '-'
hyphencolour = ''
if args.opts['--colour-wrap'] is not None:
hyphencolour = '\033[' + ';'.join(args.opts['--colour-wrap']) + 'm'
hyphen = '\033[31m' + hyphencolour + hyphen
hyphen = self.__getHyphen(args)
## Link and balloon colouring
linkcolour = ''
if args.opts['--colour-link'] is not None:
linkcolour = '\033[' + ';'.join(args.opts['--colour-link']) + 'm'
ballooncolour = ''
if args.opts['--colour-bubble'] is not None:
ballooncolour = '\033[' + ';'.join(args.opts['--colour-bubble']) + 'm'
linkcolour = self.__getLinkColour(args)
ballooncolour = self.__getBalloonColour(args)
## Determine --info/++info settings
minusinfo = args.opts['-i'] is not None
@ -1063,6 +1053,30 @@ class Ponysay():
return messagewrap
def __getHyphen(self, args):
hyphen = os.environ['PONYSAY_WRAP_HYPHEN'] if 'PONYSAY_WRAP_HYPHEN' in os.environ else None
if (hyphen is None) or (len(hyphen) == 0):
hyphen = '-'
hyphencolour = ''
if args.opts['--colour-wrap'] is not None:
hyphencolour = '\033[' + ';'.join(args.opts['--colour-wrap']) + 'm'
return '\033[31m' + hyphencolour + hyphen
def __getLinkColour(self, args):
linkcolour = ''
if args.opts['--colour-link'] is not None:
linkcolour = '\033[' + ';'.join(args.opts['--colour-link']) + 'm'
return linkcolour
def __getBalloonColour(self, args):
ballooncolour = ''
if args.opts['--colour-bubble'] is not None:
ballooncolour = '\033[' + ';'.join(args.opts['--colour-bubble']) + 'm'
return ballooncolour
def __printOutput(self, output):
'''
Print the output, but truncate it on the height