mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-12 07:46:44 +01:00
m code style + fix issue 169
Signed-off-by: Mattias Andrée <maandree@operamail.com>
This commit is contained in:
parent
f07c6d8631
commit
8f98681290
2 changed files with 21 additions and 21 deletions
|
@ -189,7 +189,7 @@ class Backend():
|
||||||
c = line[i]
|
c = line[i]
|
||||||
i += 1
|
i += 1
|
||||||
if c == '\033':
|
if c == '\033':
|
||||||
colour = Backend.getcolour(line, i - 1)
|
colour = Backend.getColour(line, i - 1)
|
||||||
i += len(colour) - 1
|
i += len(colour) - 1
|
||||||
buf += colour
|
buf += colour
|
||||||
elif c == '\t':
|
elif c == '\t':
|
||||||
|
@ -226,7 +226,7 @@ class Backend():
|
||||||
c = line[i]
|
c = line[i]
|
||||||
i += 1
|
i += 1
|
||||||
if c == '\033':
|
if c == '\033':
|
||||||
colour = Backend.getcolour(line, i - 1)
|
colour = Backend.getColour(line, i - 1)
|
||||||
i += len(colour) - 1
|
i += len(colour) - 1
|
||||||
self.output += colour
|
self.output += colour
|
||||||
else:
|
else:
|
||||||
|
@ -335,7 +335,7 @@ class Backend():
|
||||||
i += 1
|
i += 1
|
||||||
dollar += c
|
dollar += c
|
||||||
elif c == '\033':
|
elif c == '\033':
|
||||||
colour = Backend.getcolour(self.pony, i - 1)
|
colour = Backend.getColour(self.pony, i - 1)
|
||||||
for b in colour:
|
for b in colour:
|
||||||
self.output += b + colourstack.feed(b);
|
self.output += b + colourstack.feed(b);
|
||||||
i += len(colour) - 1
|
i += len(colour) - 1
|
||||||
|
@ -392,7 +392,7 @@ class Backend():
|
||||||
@return :str The escape sequence
|
@return :str The escape sequence
|
||||||
'''
|
'''
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getcolour(input, offset):
|
def getColour(input, offset):
|
||||||
(i, n) = (offset, len(input))
|
(i, n) = (offset, len(input))
|
||||||
rc = input[i]
|
rc = input[i]
|
||||||
i += 1
|
i += 1
|
||||||
|
@ -452,7 +452,7 @@ class Backend():
|
||||||
while i < n:
|
while i < n:
|
||||||
c = input[i]
|
c = input[i]
|
||||||
if c == '\033':
|
if c == '\033':
|
||||||
i += len(Backend.getcolour(input, i))
|
i += len(Backend.getColour(input, i))
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
if not UCS.isCombining(c):
|
if not UCS.isCombining(c):
|
||||||
|
@ -527,7 +527,7 @@ class Backend():
|
||||||
try:
|
try:
|
||||||
AUTO_PUSH = '\033[01010~'
|
AUTO_PUSH = '\033[01010~'
|
||||||
AUTO_POP = '\033[10101~'
|
AUTO_POP = '\033[10101~'
|
||||||
msg = message.replace('\n', AUTO_PUSH + '\n' + AUTO_POP);
|
msg = message.replace('\n', AUTO_PUSH + '\n' + AUTO_POP)
|
||||||
cstack = ColourStack(AUTO_PUSH, AUTO_POP)
|
cstack = ColourStack(AUTO_PUSH, AUTO_POP)
|
||||||
for c in msg:
|
for c in msg:
|
||||||
buf += c + cstack.feed(c)
|
buf += c + cstack.feed(c)
|
||||||
|
@ -549,7 +549,7 @@ class Backend():
|
||||||
if d == '\033':
|
if d == '\033':
|
||||||
## Invisible stuff
|
## Invisible stuff
|
||||||
i -= 1
|
i -= 1
|
||||||
colourseq = Backend.getcolour(line, i)
|
colourseq = Backend.getColour(line, i)
|
||||||
b[bi : bi + len(colourseq)] = colourseq
|
b[bi : bi + len(colourseq)] = colourseq
|
||||||
i += len(colourseq)
|
i += len(colourseq)
|
||||||
bi += len(colourseq)
|
bi += len(colourseq)
|
||||||
|
@ -599,7 +599,7 @@ class Backend():
|
||||||
|
|
||||||
w = iwrap
|
w = iwrap
|
||||||
if indent != -1:
|
if indent != -1:
|
||||||
buf += line[:indent]
|
buf += ' ' * indentc
|
||||||
|
|
||||||
for j in range(bisub, bi):
|
for j in range(bisub, bi):
|
||||||
b[j - bisub] = b[j]
|
b[j - bisub] = b[j]
|
||||||
|
@ -609,7 +609,7 @@ class Backend():
|
||||||
buf += '\n'
|
buf += '\n'
|
||||||
w = wrap
|
w = wrap
|
||||||
if indent != -1:
|
if indent != -1:
|
||||||
buf += line[:indent]
|
buf += ' ' * indentc
|
||||||
w -= indentc
|
w -= indentc
|
||||||
for bb in b[:bi]:
|
for bb in b[:bi]:
|
||||||
if bb is not None:
|
if bb is not None:
|
||||||
|
@ -627,18 +627,18 @@ class Backend():
|
||||||
buf += '\n'
|
buf += '\n'
|
||||||
w = wrap
|
w = wrap
|
||||||
if indent != -1:
|
if indent != -1:
|
||||||
buf + line[:indent]
|
buf += ' ' * indentc
|
||||||
w -= indentc
|
w -= indentc
|
||||||
buf += '\n'
|
buf += '\n'
|
||||||
|
|
||||||
rc = '\n'.join(line.rstrip() for line in buf[:-1].split('\n'));
|
rc = '\n'.join(line.rstrip(' ') for line in buf[:-1].split('\n'));
|
||||||
rc = rc.replace('', ''); # remove soft hyphens
|
rc = rc.replace('', ''); # remove soft hyphens
|
||||||
rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP))
|
rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP))
|
||||||
return rc
|
return rc
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
errormessage = ''.join(traceback.format_exception(type(err), err, None))
|
errormessage = ''.join(traceback.format_exception(type(err), err, None))
|
||||||
rc = '\n'.join(line.rstrip() for line in buf.split('\n'));
|
rc = '\n'.join(line.rstrip(' ') for line in buf.split('\n'));
|
||||||
rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP))
|
rc = rc.replace('\0', '%s%s%s' % (AUTO_PUSH, self.hyphen, AUTO_POP))
|
||||||
errormessage += '\n---- WRAPPING BUFFER ----\n\n' + rc
|
errormessage += '\n---- WRAPPING BUFFER ----\n\n' + rc
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -105,15 +105,15 @@ class ColourStack():
|
||||||
part = self.seq[i]
|
part = self.seq[i]
|
||||||
p = 0 if part == '' else int(part)
|
p = 0 if part == '' else int(part)
|
||||||
i += 1
|
i += 1
|
||||||
if p == 0: self.stack[0][1:] = [None, None, [False] * 9]
|
if p == 0: self.stack[0][1:] = [None, None, [False] * 9]
|
||||||
elif (1 <= p) and (p <= 9): self.stack[0][3][p - 1] = True
|
elif 1 <= p <= 9: self.stack[0][3][p - 1] = True
|
||||||
elif (21 <= p) and (p <= 29): self.stack[0][3][p - 21] = False
|
elif 21 <= p <= 29: self.stack[0][3][p - 21] = False
|
||||||
elif p == 39: self.stack[0][1] = None
|
elif p == 39: self.stack[0][1] = None
|
||||||
elif p == 49: self.stack[0][2] = None
|
elif p == 49: self.stack[0][2] = None
|
||||||
elif (30 <= p) and (p <= 37): self.stack[0][1] = part
|
elif 30 <= p <= 37: self.stack[0][1] = part
|
||||||
elif (90 <= p) and (p <= 97): self.stack[0][1] = part
|
elif 90 <= p <= 97: self.stack[0][1] = part
|
||||||
elif (40 <= p) and (p <= 47): self.stack[0][2] = part
|
elif 40 <= p <= 47: self.stack[0][2] = part
|
||||||
elif (100 <= p) and (p <= 107): self.stack[0][2] = part
|
elif 100 <= p <= 107: self.stack[0][2] = part
|
||||||
elif p == 38:
|
elif p == 38:
|
||||||
self.stack[0][1] = '%s;%s;%s' % (part, self.seq[i], self.seq[i + 1])
|
self.stack[0][1] = '%s;%s;%s' % (part, self.seq[i], self.seq[i + 1])
|
||||||
i += 2
|
i += 2
|
||||||
|
|
Loading…
Reference in a new issue