mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-29 23:48:00 +01:00
preparation for colour stack used to seperate balloon and link colouring from pony colouring
This commit is contained in:
parent
3324c3e51c
commit
5ee263a055
1 changed files with 39 additions and 6 deletions
45
ponysay
45
ponysay
|
@ -783,13 +783,17 @@ class Backend():
|
||||||
def __processPony(self):
|
def __processPony(self):
|
||||||
self.output = ''
|
self.output = ''
|
||||||
|
|
||||||
|
AUTO_PUSH = '\033[01010~'
|
||||||
|
AUTO_POP = '\033[10101~'
|
||||||
|
|
||||||
variables = {'' : '$'}
|
variables = {'' : '$'}
|
||||||
for key in self.link:
|
for key in self.link:
|
||||||
variables[key] = self.link[key]
|
variables[key] = AUTO_PUSH + self.link[key] + AUTO_POP
|
||||||
|
|
||||||
indent = 0
|
indent = 0
|
||||||
dollar = None
|
dollar = None
|
||||||
balloonLines = None
|
balloonLines = None
|
||||||
|
colourstack = ColourStack(AUTO_PUSH, AUTO_POP)
|
||||||
|
|
||||||
(i, n, lineindex, skip, nonskip) = (0, len(self.pony), 0, 0, 0)
|
(i, n, lineindex, skip, nonskip) = (0, len(self.pony), 0, 0, 0)
|
||||||
while i < n:
|
while i < n:
|
||||||
|
@ -830,12 +834,15 @@ class Backend():
|
||||||
else:
|
else:
|
||||||
w = int(props)
|
w = int(props)
|
||||||
balloon = self.__getballoon(w, h, indent).split('\n')
|
balloon = self.__getballoon(w, h, indent).split('\n')
|
||||||
self.output += balloon[0]
|
balloon = [AUTO_PUSH + item + AUTO_POP for item in balloon]
|
||||||
|
for b in balloon[0]:
|
||||||
|
self.output += b + colourstack.feed(b)
|
||||||
if lineindex == 0:
|
if lineindex == 0:
|
||||||
balloonpre = '\n' + (' ' * indent)
|
balloonpre = '\n' + (' ' * indent)
|
||||||
for line in balloon[1:]:
|
for line in balloon[1:]:
|
||||||
self.output += balloonpre;
|
self.output += balloonpre;
|
||||||
self.output += line;
|
for b in line:
|
||||||
|
self.output += b + colourstack.feed(b);
|
||||||
indent = 0
|
indent = 0
|
||||||
elif len(balloon) > 1:
|
elif len(balloon) > 1:
|
||||||
balloonLines = balloon
|
balloonLines = balloon
|
||||||
|
@ -853,7 +860,8 @@ class Backend():
|
||||||
dollar += c
|
dollar += c
|
||||||
elif c == '\033':
|
elif c == '\033':
|
||||||
colour = self.__getcolour(self.pony, i - 1)
|
colour = self.__getcolour(self.pony, i - 1)
|
||||||
self.output += colour
|
for b in colour:
|
||||||
|
self.output += b + colourstack.feed(b);
|
||||||
i += len(colour) - 1
|
i += len(colour) - 1
|
||||||
elif c == '\n':
|
elif c == '\n':
|
||||||
self.output += c
|
self.output += c
|
||||||
|
@ -878,16 +886,20 @@ class Backend():
|
||||||
if (skip == 0) or (nonskip > 0):
|
if (skip == 0) or (nonskip > 0):
|
||||||
if nonskip > 0:
|
if nonskip > 0:
|
||||||
nonskip -= 1
|
nonskip -= 1
|
||||||
self.output += c
|
self.output += c + colourstack.feed(c);
|
||||||
indent += 1
|
indent += 1
|
||||||
else:
|
else:
|
||||||
skip -= 1
|
skip -= 1
|
||||||
|
|
||||||
if balloonLines is not None:
|
if balloonLines is not None:
|
||||||
for line in balloonLines[balloonLine:]:
|
for line in balloonLines[balloonLine:]:
|
||||||
self.output += ' ' * (balloonIndent - indent) + line + '\n'
|
data = ' ' * (balloonIndent - indent) + line + '\n'
|
||||||
|
for b in data:
|
||||||
|
self.output += b + colourstack.feed(b);
|
||||||
indent = 0
|
indent = 0
|
||||||
|
|
||||||
|
self.output = self.output.replace(AUTO_PUSH, '').replace(AUTO_POP, '')
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Gets colour code att the currect offset in a buffer
|
Gets colour code att the currect offset in a buffer
|
||||||
|
@ -1065,6 +1077,27 @@ class Backend():
|
||||||
return buf[:-1]
|
return buf[:-1]
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
ANSI colour stack
|
||||||
|
'''
|
||||||
|
class ColourStack():
|
||||||
|
'''
|
||||||
|
Constructor
|
||||||
|
'''
|
||||||
|
def __init__(self, autopush, autopop):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def push(self):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def pop(self):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def feed(self, char):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
The user's home directory
|
The user's home directory
|
||||||
|
|
Loading…
Reference in a new issue