gitrepo DiffFile: convert tab to » + spaces
tabs are displayed as question mark by urwid, so need replacing. While we are replacing, might as well mark them like in the web UI. Ideally I would want to use a slightly different color for them, but that would require to add many new colors in the config (context, full new line, part of new line) and would not be very compatible with 8-colors terminals -- the '»' character is hopefully rarely used enough to be useable as is. Change-Id: Ic974774bf546765fa5b3e9266aee8ff973865502
This commit is contained in:
parent
21a1cda390
commit
c4b7fc6e37
|
@ -187,9 +187,12 @@ class DiffFile(object):
|
|||
def finalize(self):
|
||||
if not self.current_chunk:
|
||||
return
|
||||
oldlines = [(n, d, self.expand_tabs(l)) for (n, d, l)
|
||||
in self.current_chunk.oldlines]
|
||||
newlines = [(n, d, self.expand_tabs(l)) for (n, d, l)
|
||||
in self.current_chunk.newlines]
|
||||
self.current_chunk.lines = list(
|
||||
six.moves.zip(self.current_chunk.oldlines,
|
||||
self.current_chunk.newlines))
|
||||
six.moves.zip(oldlines, newlines))
|
||||
if not self.chunks:
|
||||
self.current_chunk.first = True
|
||||
else:
|
||||
|
@ -199,6 +202,26 @@ class DiffFile(object):
|
|||
self.chunks.append(self.current_chunk)
|
||||
self.current_chunk = None
|
||||
|
||||
def expand_tabs(self, l, tabstop = 8):
|
||||
offset = { 'start': 0, 'prevstart': 0 }
|
||||
def replace(match):
|
||||
offset['start'] += match.start(0) - offset['prevstart']
|
||||
offset['prevstart'] = match.start(0)
|
||||
cnt = tabstop - offset['start'] % tabstop - 1
|
||||
offset['start'] += cnt
|
||||
return "»" + " " * cnt
|
||||
|
||||
try:
|
||||
if isinstance(l, six.string_types):
|
||||
return re.sub(r'\t', replace, l)
|
||||
elif isinstance(l, list):
|
||||
return [self.expand_tabs(e) for e in l]
|
||||
else:
|
||||
(a, b) = l
|
||||
return (a, re.sub(r'\t', replace, b))
|
||||
except:
|
||||
return l
|
||||
|
||||
def addDiffLines(self, old, new):
|
||||
if (self.current_chunk and
|
||||
not isinstance(self.current_chunk, DiffChangedChunk)):
|
||||
|
|
Loading…
Reference in New Issue