From 8f12558148e70cc87b326f1970ec696fa746734a Mon Sep 17 00:00:00 2001
From: Eirik Byrkjeflot Anonsen <eirik@eirikba.org>
Date: Sat, 24 Mar 2012 16:28:06 +0100
Subject: [PATCH] Make sure Screen.add_line.get_line_chunks() does not discard beginning of line.
The old version would discard everything before the first '{!'.
---
deluge/ui/console/screen.py | 29 +++++++++++------------------
1 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/deluge/ui/console/screen.py b/deluge/ui/console/screen.py
index 1a05c45..763551a 100644
|
a
|
b
|
def add_line(self, text, refresh=True):
|
| 163 | 163 | def get_line_chunks(line): |
| 164 | 164 | """ |
| 165 | 165 | Returns a list of 2-tuples (color string, text) |
| | 166 | First tuple may have empty color string. |
| 166 | 167 | |
| 167 | 168 | """ |
| | 169 | spans = line.split('{!') |
| 168 | 170 | chunks = [] |
| 169 | | num_chunks = line.count("{!") |
| 170 | | for i in range(num_chunks): |
| 171 | | # Find the beginning and end of the color tag |
| 172 | | beg = line.find("{!") |
| 173 | | end = line.find("!}") + 2 |
| 174 | | color = line[beg:end] |
| 175 | | line = line[end:] |
| 176 | | |
| 177 | | # Check to see if this is the last chunk |
| 178 | | if i + 1 == num_chunks: |
| 179 | | text = line |
| | 171 | if spans[0] != '': |
| | 172 | chunks.append( ('', spans[0]) ) |
| | 173 | spans = spans[1:] |
| | 174 | for span in spans: |
| | 175 | span = '{!' + span |
| | 176 | end = span.find('!}') |
| | 177 | if end < 0: |
| | 178 | chunks.append((span, '')) |
| 180 | 179 | else: |
| 181 | | # Not the last chunk so get the text up to the next tag |
| 182 | | # and remove the text from line |
| 183 | | text = line[:line.find("{!")] |
| 184 | | line = line[line.find("{!"):] |
| 185 | | |
| 186 | | chunks.append((color, text)) |
| 187 | | |
| | 180 | chunks.append((span[:end+2], span[end+2:])) |
| 188 | 181 | return chunks |
| 189 | 182 | |
| 190 | 183 | for line in text.splitlines(): |