Fix #2062 : Console discards text before first colour string

This commit is contained in:
Eirik Byrkjeflot Anonsen 2012-04-20 12:27:49 +01:00 committed by Calum Lind
parent 934a0f6495
commit 6cb1fd76cc
1 changed files with 19 additions and 20 deletions

View File

@ -311,26 +311,25 @@ class Legacy(BaseMode):
Returns a list of 2-tuples (color string, text) Returns a list of 2-tuples (color string, text)
""" """
if not line or line.count("{!") != line.count("!}"):
return []
chunks = [] chunks = []
num_chunks = line.count("{!") if not line.startswith('{!'):
for i in range(num_chunks): begin = line.find('{!')
# Find the beginning and end of the color tag if begin == -1:
beg = line.find("{!") begin = len(line)
end = line.find("!}") + 2 chunks.append( ('', line[:begin]) )
color = line[beg:end] line = line[begin:]
line = line[end:]
# Check to see if this is the last chunk
if i + 1 == num_chunks:
text = line
else:
# Not the last chunk so get the text up to the next tag
# and remove the text from line
text = line[:line.find("{!")]
line = line[line.find("{!"):]
chunks.append((color, text))
while line:
# We know the line starts with '{!' here
end_color = line.find('!}')
next_color = line.find('{!', end_color)
if next_color == -1:
next_color = len(line)
chunks.append( (line[:end_color+2], line[end_color+2:next_color]) )
line = line[next_color:]
return chunks return chunks
for line in text.splitlines(): for line in text.splitlines():
@ -338,8 +337,8 @@ class Legacy(BaseMode):
try: try:
line_length = colors.get_line_length(line) line_length = colors.get_line_length(line)
except colors.BadColorString: except colors.BadColorString:
log.error("Passed a bad colored string..") log.error("Passed a bad colored line: %s", line)
line_length = len(line) continue
if line_length >= (self.cols - 1): if line_length >= (self.cols - 1):
s = "" s = ""