##// END OF EJS Templates
diff: enhance highlighting with color (issue3034)...
Kirill Elagin -
r15201:2c4fdee4 default
parent child Browse files
Show More
@@ -1619,27 +1619,36 b' def diff(repo, node1=None, node2=None, m'
1619
1619
1620 def difflabel(func, *args, **kw):
1620 def difflabel(func, *args, **kw):
1621 '''yields 2-tuples of (output, label) based on the output of func()'''
1621 '''yields 2-tuples of (output, label) based on the output of func()'''
1622 prefixes = [('diff', 'diff.diffline'),
1622 headprefixes = [('diff', 'diff.diffline'),
1623 ('copy', 'diff.extended'),
1623 ('copy', 'diff.extended'),
1624 ('rename', 'diff.extended'),
1624 ('rename', 'diff.extended'),
1625 ('old', 'diff.extended'),
1625 ('old', 'diff.extended'),
1626 ('new', 'diff.extended'),
1626 ('new', 'diff.extended'),
1627 ('deleted', 'diff.extended'),
1627 ('deleted', 'diff.extended'),
1628 ('---', 'diff.file_a'),
1628 ('---', 'diff.file_a'),
1629 ('+++', 'diff.file_b'),
1629 ('+++', 'diff.file_b')]
1630 ('@@', 'diff.hunk'),
1630 textprefixes = [('@', 'diff.hunk'),
1631 ('-', 'diff.deleted'),
1631 ('-', 'diff.deleted'),
1632 ('+', 'diff.inserted')]
1632 ('+', 'diff.inserted')]
1633
1633 head = False
1634 for chunk in func(*args, **kw):
1634 for chunk in func(*args, **kw):
1635 lines = chunk.split('\n')
1635 lines = chunk.split('\n')
1636 for i, line in enumerate(lines):
1636 for i, line in enumerate(lines):
1637 if i != 0:
1637 if i != 0:
1638 yield ('\n', '')
1638 yield ('\n', '')
1639 if head:
1640 if line.startswith('@'):
1641 head = False
1642 else:
1643 if line and not line[0] in ' +-@':
1644 head = True
1639 stripline = line
1645 stripline = line
1640 if line and line[0] in '+-':
1646 if not head and line and line[0] in '+-':
1641 # highlight trailing whitespace, but only in changed lines
1647 # highlight trailing whitespace, but only in changed lines
1642 stripline = line.rstrip()
1648 stripline = line.rstrip()
1649 prefixes = textprefixes
1650 if head:
1651 prefixes = headprefixes
1643 for prefix, label in prefixes:
1652 for prefix, label in prefixes:
1644 if stripline.startswith(prefix):
1653 if stripline.startswith(prefix):
1645 yield (stripline, label)
1654 yield (stripline, label)
General Comments 0
You need to be logged in to leave comments. Login now