diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-10-12 02:59:43 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-10-12 02:59:43 +0200 |
commit | e74b16297e4ab932236a8a9eb71c545a1d70eb49 (patch) | |
tree | 3bb0b6a68de90b94e765663d1c4c2fba45085cf5 | |
parent | dc38ab4e6d6302cf278df6e6adfcefe0afd841fe (diff) | |
download | ponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.tar.gz ponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.tar.bz2 ponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.zip |
colouring is fully functional
-rwxr-xr-x | ponysay.py | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -720,7 +720,7 @@ class Ponysay(): hyphencolour = '' if args.opts['--colour-wrap'] is not None: hyphencolour = '\033[' + ';'.join(args.opts['--colour-wrap']) + 'm' - hyphen = '\033[31m' + hyphencolour + '-' + hyphen = '\033[31m' + hyphencolour + '-' # TODO make configurable ## Link and balloon colouring linkcolour = '' @@ -1527,15 +1527,9 @@ class Backend(): if wrap is not None: msg = self.__wrapMessage(msg, wrap) - AUTO_PUSH = '\033[01010~' - AUTO_POP = '\033[10101~' - cstack = ColourStack(AUTO_PUSH, AUTO_POP) - buf = '' - for c in msg.replace('\n', AUTO_PUSH + self.ballooncolour + '\n' + AUTO_POP) + self.ballooncolour: - buf += c - buf += cstack.feed(c) + msg = msg.replace('\n', '\033[0m%s\n' % (self.ballooncolour)) + '\033[0m' + self.ballooncolour - return self.balloon.get(width, height, buf.split('\n'), self.__len) + return self.balloon.get(width, height, msg.split('\n'), self.__len); ''' @@ -1544,7 +1538,12 @@ class Backend(): def __wrapMessage(self, message, wrap): AUTO_PUSH = '\033[01010~' AUTO_POP = '\033[10101~' - lines = message.split('\n') + msg = message.replace('\n', AUTO_PUSH + '\n' + AUTO_POP); + cstack = ColourStack(AUTO_PUSH, AUTO_POP) + buf = '' + for c in msg: + buf += c + cstack.feed(c) + lines = buf.replace(AUTO_PUSH, '').replace(AUTO_POP, '').split('\n') buf = '' for line in lines: b = [None] * len(line) @@ -1660,7 +1659,7 @@ class Backend(): rc = '\n'.join(line.rstrip() for line in buf[:-1].split('\n')); rc = rc.replace('', ''); # remove soft hyphens - rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP)) # TODO make configurable + rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP)) return rc |