Ticket #2062: 0001-Make-sure-Screen.add_line.get_line_chunks-does-not-d.patch

File 0001-Make-sure-Screen.add_line.get_line_chunks-does-not-d.patch, 2.1 KB (added by eirikba, 9 years ago)
  • deluge/ui/console/screen.py

    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): 
    163163        def get_line_chunks(line): 
    164164            """ 
    165165            Returns a list of 2-tuples (color string, text) 
     166            First tuple may have empty color string. 
    166167 
    167168            """ 
     169            spans = line.split('{!') 
    168170            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, '')) 
    180179                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:])) 
    188181            return chunks 
    189182 
    190183        for line in text.splitlines():