mirror of
https://github.com/erkin/ponysay.git
synced 2025-01-31 10:26:43 +01:00
better colour stacking
This commit is contained in:
parent
1b78d94ef4
commit
1601dda9d3
1 changed files with 12 additions and 24 deletions
22
ponysay
22
ponysay
|
@ -1246,8 +1246,8 @@ class Backend():
|
|||
h = int(props[props.index(',') + 1:])
|
||||
else:
|
||||
w = int(props)
|
||||
balloon = self.__getballoon(w, h, indent).split('\n')
|
||||
balloon = [AUTO_PUSH + item + AUTO_POP for item in balloon]
|
||||
balloon = self.__getballoon(w, h, indent)
|
||||
balloon = balloon.split('\n')
|
||||
for b in balloon[0]:
|
||||
self.output += b + colourstack.feed(b)
|
||||
if lineindex == 0:
|
||||
|
@ -1520,32 +1520,20 @@ class ColourStack():
|
|||
self.stack = [[self.bufproto, None, None, [False] * 9]] + self.stack
|
||||
if len(self.stack) == 1:
|
||||
return None
|
||||
old = self.stack[1]
|
||||
rc = '\033['
|
||||
if old[1] is not None: rc += '39;'
|
||||
if old[2] is not None: rc += '49;'
|
||||
for i in range(0, 9):
|
||||
if old[3][i]:
|
||||
rc += '2%i;' % (i + 1)
|
||||
return '' if len(rc) == 2 else (rc[:-1] + 'm')
|
||||
return '\033[0m'
|
||||
|
||||
|
||||
def pop(self):
|
||||
old = self.stack[0]
|
||||
self.stack = self.stack[1:]
|
||||
rc = '\033['
|
||||
if old[1] is not None: rc += '39;'
|
||||
if old[2] is not None: rc += '49;'
|
||||
for i in range(0, 9):
|
||||
if old[3][i]:
|
||||
rc += str(i + 21) + ';'
|
||||
rc = '\033[0;'
|
||||
new = self.stack[0]
|
||||
if new[1] is not None: rc += new[1] + ';'
|
||||
if new[2] is not None: rc += new[2] + ';'
|
||||
for i in range(0, 9):
|
||||
if new[3][i]:
|
||||
rc += str(i + 1) + ';'
|
||||
return '' if len(rc) == 2 else (rc[:-1] + 'm')
|
||||
return rc[:-1] + 'm'
|
||||
|
||||
|
||||
def feed(self, char):
|
||||
|
|
Loading…
Reference in a new issue