aboutsummaryrefslogtreecommitdiff
path: root/ponysay.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-10-12 02:59:43 +0200
committerMattias Andrée <maandree@operamail.com>2012-10-12 02:59:43 +0200
commite74b16297e4ab932236a8a9eb71c545a1d70eb49 (patch)
tree3bb0b6a68de90b94e765663d1c4c2fba45085cf5 /ponysay.py
parentdc38ab4e6d6302cf278df6e6adfcefe0afd841fe (diff)
downloadponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.tar.gz
ponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.tar.bz2
ponysay-e74b16297e4ab932236a8a9eb71c545a1d70eb49.zip
colouring is fully functional
Diffstat (limited to 'ponysay.py')
-rwxr-xr-xponysay.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/ponysay.py b/ponysay.py
index 2bad694..5262964 100755
--- a/ponysay.py
+++ b/ponysay.py
@@ -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