Quellcode durchsuchen

should use 2 different pattern in _fit_width(); FIXME: markup[0] breaks utf-8 char

Matthew Wang vor 11 Jahren
Ursprung
Commit
eab2534a42
1 geänderte Dateien mit 9 neuen und 6 gelöschten Zeilen
  1. 9
    6
      src/cdiff.py

+ 9
- 6
src/cdiff.py Datei anzeigen

139
             """
139
             """
140
             out = []
140
             out = []
141
             count = 0
141
             count = 0
142
+            ansi_color_regex = r'\x1b\[(1;)?\d{1,2}m'
143
+            patt = re.compile('^(%s)(.*)' % ansi_color_regex)
144
+            repl = re.compile(ansi_color_regex)
145
+
142
             while markup and count < width:
146
             while markup and count < width:
143
-                patt = re.compile('^(\x1b\[(1;)?\d{1,2}m)(.*)')
144
                 if patt.match(markup):
147
                 if patt.match(markup):
145
-                    out.append(patt.sub(r'\1', markup, count=1))
146
-                    markup = patt.sub(r'\3', markup, count=1)
148
+                    out.append(patt.sub(r'\1', markup))
149
+                    markup = patt.sub(r'\3', markup)
147
                 else:
150
                 else:
151
+                    # FIXME: utf-8 char broken here
148
                     out.append(markup[0])
152
                     out.append(markup[0])
149
                     markup = markup[1:]
153
                     markup = markup[1:]
150
                     count += 1
154
                     count += 1
151
 
155
 
152
-            if count == width and patt.sub('', markup):
156
+            if count == width and repl.sub('', markup):
153
                 # stripped: output fulfil and still have ascii in markup
157
                 # stripped: output fulfil and still have ascii in markup
154
-                #out[-1] = ansi_code('reset') + colorize('☞', 'lightmagenta')
155
-                out[-1] = ansi_code('reset') + colorize('↵', 'lightmagenta')
158
+                out[-1] = ansi_code('reset') + colorize('>', 'lightmagenta')
156
             elif count < width and pad:
159
             elif count < width and pad:
157
                 pad_len = width - count
160
                 pad_len = width - count
158
                 out.append('%*s' % (pad_len, ''))
161
                 out.append('%*s' % (pad_len, ''))