comparison diff-colorize.py @ 5:fa7cd4c2716b

Added prefixes “old mode” and “new mode”, found in Git-style diffs, along with new color constants for them. We treat these the same way we treat “---” and “+++”.
author Peter Hosey
date Sun, 10 Aug 2008 23:50:06 -0700
parents b8b2d1931a9e
children d58b4e2e12d4
comparison
equal deleted inserted replaced
4:b8b2d1931a9e 5:fa7cd4c2716b
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import os 3 import os
4 4
5 INDEX_COLOR = int(os.environ.get('DIFF_INDEX_COLOR', 32)) 5 INDEX_COLOR = int(os.environ.get('DIFF_INDEX_COLOR', 32))
6 OLD_MODE_COLOR = int(os.environ.get('DIFF_OLD_MODE_COLOR', 124))
7 NEW_MODE_COLOR = int(os.environ.get('DIFF_NEW_MODE_COLOR', 28))
6 REMOVED_COLOR = int(os.environ.get('DIFF_REMOVED_COLOR', 203)) 8 REMOVED_COLOR = int(os.environ.get('DIFF_REMOVED_COLOR', 203))
7 ADDED_COLOR = int(os.environ.get('DIFF_ADDED_COLOR', 2)) 9 ADDED_COLOR = int(os.environ.get('DIFF_ADDED_COLOR', 2))
8 HUNK_START_COLOR = int(os.environ.get('DIFF_HUNK_START_COLOR', 32)) 10 HUNK_START_COLOR = int(os.environ.get('DIFF_HUNK_START_COLOR', 32))
9 11
10 RESET_FORMAT = '\033[0m' 12 RESET_FORMAT = '\033[0m'
56 COLOR_FORMAT % (ADDED_COLOR,) 58 COLOR_FORMAT % (ADDED_COLOR,)
57 + BEGIN_REVERSE_FORMAT 59 + BEGIN_REVERSE_FORMAT
58 + '+' 60 + '+'
59 + END_REVERSE_FORMAT 61 + END_REVERSE_FORMAT
60 ) 62 )
63 prefixes['old mode'] = ( # Git-style diffs only
64 COLOR_FORMAT % (OLD_MODE_COLOR,)
65 + BEGIN_REVERSE_FORMAT
66 + 'old mode'
67 + END_REVERSE_FORMAT
68 )
69 prefixes['new mode'] = ( # Git-style diffs only
70 COLOR_FORMAT % (NEW_MODE_COLOR,)
71 + BEGIN_REVERSE_FORMAT
72 + 'new mode'
73 + END_REVERSE_FORMAT
74 )
61 prefixes['Index: '] = COLOR_FORMAT % (INDEX_COLOR,) + 'Index: ' 75 prefixes['Index: '] = COLOR_FORMAT % (INDEX_COLOR,) + 'Index: '
62 prefixes['diff --git '] = COLOR_FORMAT % (INDEX_COLOR,) + 'diff --git ' 76 prefixes['diff --git '] = COLOR_FORMAT % (INDEX_COLOR,) + 'diff --git '
63 prefixes['@@'] = ( 77 prefixes['@@'] = (
64 COLOR_FORMAT % (HUNK_START_COLOR,) 78 COLOR_FORMAT % (HUNK_START_COLOR,)
65 + BEGIN_REVERSE_FORMAT 79 + BEGIN_REVERSE_FORMAT