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:32:20 +0100
commitd08ea7da819564410b048e7849358f4b45f04e12 (patch)
tree07a9ebe5fcc5d774fc7926a57dce28befb02f609
parent483c439e385fea093d3ea33d6de5c40bb35b4042 (diff)
downloaddeluge-d08ea7da.zip
deluge-d08ea7da.tar.gz
deluge-d08ea7da.tar.bz2
Fix #2062 : Console discards text before first colour string
-rw-r--r--deluge/ui/console/screen.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/deluge/ui/console/screen.py b/deluge/ui/console/screen.py
index 1a05c45..7df4a4c 100644
--- a/deluge/ui/console/screen.py
+++ b/deluge/ui/console/screen.py
@@ -165,26 +165,25 @@ class Screen(CursesStdIO):
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():
@@ -192,8 +191,8 @@ class Screen(CursesStdIO):
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 = ""