|
|
|
|
398
|
|
398
|
|
399
|
class DiffMarker(object):
|
399
|
class DiffMarker(object):
|
400
|
|
400
|
|
401
|
- def markup(self, diffs, side_by_side=False, width=0):
|
|
|
|
|
401
|
+ def markup(self, diffs, side_by_side=False, width=0, tab_width=8):
|
402
|
"""Returns a generator"""
|
402
|
"""Returns a generator"""
|
403
|
if side_by_side:
|
403
|
if side_by_side:
|
404
|
for diff in diffs:
|
404
|
for diff in diffs:
|
405
|
- for line in self._markup_side_by_side(diff, width):
|
|
|
|
|
405
|
+ for line in self._markup_side_by_side(diff, width, tab_width):
|
406
|
yield line
|
406
|
yield line
|
407
|
else:
|
407
|
else:
|
408
|
for diff in diffs:
|
408
|
for diff in diffs:
|
|
|
|
|
442
|
else:
|
442
|
else:
|
443
|
yield self._markup_common(' ' + old[1])
|
443
|
yield self._markup_common(' ' + old[1])
|
444
|
|
444
|
|
445
|
- def _markup_side_by_side(self, diff, width):
|
|
|
|
|
445
|
+ def _markup_side_by_side(self, diff, width, tab_width):
|
446
|
"""Returns a generator"""
|
446
|
"""Returns a generator"""
|
447
|
wrap_char = colorize('>', 'lightmagenta')
|
447
|
wrap_char = colorize('>', 'lightmagenta')
|
448
|
|
448
|
|
449
|
def _normalize(line):
|
449
|
def _normalize(line):
|
450
|
return line.replace(
|
450
|
return line.replace(
|
451
|
- '\t', ' ' * 8).replace('\n', '').replace('\r', '')
|
|
|
|
|
451
|
+ '\t', ' ' * tab_width).replace('\n', '').replace('\r', '')
|
452
|
|
452
|
|
453
|
def _fit_with_marker(text, markup_fn, width, pad=False):
|
453
|
def _fit_with_marker(text, markup_fn, width, pad=False):
|
454
|
"""Wrap or pad input pure text, then markup"""
|
454
|
"""Wrap or pad input pure text, then markup"""
|
|
|
|
|
642
|
diffs = DiffParser(stream).get_diff_generator()
|
642
|
diffs = DiffParser(stream).get_diff_generator()
|
643
|
marker = DiffMarker()
|
643
|
marker = DiffMarker()
|
644
|
color_diff = marker.markup(diffs, side_by_side=opts.side_by_side,
|
644
|
color_diff = marker.markup(diffs, side_by_side=opts.side_by_side,
|
645
|
- width=opts.width)
|
|
|
|
|
645
|
+ width=opts.width, tab_width=opts.tab_width)
|
646
|
|
646
|
|
647
|
for line in color_diff:
|
647
|
for line in color_diff:
|
648
|
pager.stdin.write(line.encode('utf-8'))
|
648
|
pager.stdin.write(line.encode('utf-8'))
|
|
|
|
|
751
|
parser.add_option(
|
751
|
parser.add_option(
|
752
|
'-c', '--color', default='auto', metavar='M',
|
752
|
'-c', '--color', default='auto', metavar='M',
|
753
|
help="""colorize mode 'auto' (default), 'always', or 'never'""")
|
753
|
help="""colorize mode 'auto' (default), 'always', or 'never'""")
|
|
|
754
|
+ parser.add_option(
|
|
|
755
|
+ '-t', '--tab-width', type='int', default=8, metavar='N',
|
|
|
756
|
+ help="""convert tab characters to this many spcaes (default: 8)""")
|
754
|
|
757
|
|
755
|
# Hack: use OptionGroup text for extra help message after option list
|
758
|
# Hack: use OptionGroup text for extra help message after option list
|
756
|
option_group = OptionGroup(
|
759
|
option_group = OptionGroup(
|