Procházet zdrojové kódy

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

Matthew Wang před 11 roky
rodič
revize
eab2534a42
1 změnil soubory, kde provedl 9 přidání a 6 odebrání
  1. 9
    6
      src/cdiff.py

+ 9
- 6
src/cdiff.py Zobrazit soubor

@@ -139,20 +139,23 @@ class Diff(object):
139 139
             """
140 140
             out = []
141 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 146
             while markup and count < width:
143
-                patt = re.compile('^(\x1b\[(1;)?\d{1,2}m)(.*)')
144 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 150
                 else:
151
+                    # FIXME: utf-8 char broken here
148 152
                     out.append(markup[0])
149 153
                     markup = markup[1:]
150 154
                     count += 1
151 155
 
152
-            if count == width and patt.sub('', markup):
156
+            if count == width and repl.sub('', markup):
153 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 159
             elif count < width and pad:
157 160
                 pad_len = width - count
158 161
                 out.append('%*s' % (pad_len, ''))