summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Byrkjeflot Anonsen <eirik@eirikba.org>2012-04-20 12:27:49 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2012-04-20 12:35:21 +0100
commit6cb1fd76cc3cad8c5e483e9a1fca066ac3561bbb (patch)
tree341bb200d980f36b7b8d21c66078bcd3c3a9f653
parent934a0f6495296a0cfc98ff18836e7b2560d8bb2a (diff)
downloaddeluge-6cb1fd76cc3cad8c5e483e9a1fca066ac3561bbb.tar.gz
deluge-6cb1fd76cc3cad8c5e483e9a1fca066ac3561bbb.tar.bz2
deluge-6cb1fd76cc3cad8c5e483e9a1fca066ac3561bbb.zip
Fix #2062 : Console discards text before first colour string
-rw-r--r--deluge/ui/console/modes/legacy.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/deluge/ui/console/modes/legacy.py b/deluge/ui/console/modes/legacy.py
index 0ffe81b65..c59654dda 100644
--- a/deluge/ui/console/modes/legacy.py
+++ b/deluge/ui/console/modes/legacy.py
@@ -311,26 +311,25 @@ class Legacy(BaseMode):
Returns a list of 2-tuples (color string, text)
"""
- chunks = []
- num_chunks = line.count("{!")
- for i in range(num_chunks):
- # Find the beginning and end of the color tag
- beg = line.find("{!")
- end = line.find("!}") + 2
- color = line[beg:end]
- 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))
+ if not line or line.count("{!") != line.count("!}"):
+ return []
+ chunks = []
+ if not line.startswith('{!'):
+ begin = line.find('{!')
+ if begin == -1:
+ begin = len(line)
+ chunks.append( ('', line[:begin]) )
+ line = line[begin:]
+
+ 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
for line in text.splitlines():
@@ -338,8 +337,8 @@ class Legacy(BaseMode):
try:
line_length = colors.get_line_length(line)
except colors.BadColorString:
- log.error("Passed a bad colored string..")
- line_length = len(line)
+ log.error("Passed a bad colored line: %s", line)
+ continue
if line_length >= (self.cols - 1):
s = ""