Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """ This takes unified diff output and adds colors """
- from __future__ import print_function
- import re
- import sys
- def main():
- """ main routine """
- RED = '\033[0;31m'
- GREEN = '\033[0;32m'
- YELLOW = '\033[0;33m'
- BLUE = '\033[0;34m'
- MAGENTA = '\033[0;35m'
- ENDCOLOR = '\033[0m'
- added = 0
- deleted = 0
- try:
- for line in sys.stdin:
- if re.search('(^Index: .*)', line):
- line = "%s%s%s" % (BLUE, line, ENDCOLOR)
- elif re.search('(^\+\+\+ .*)', line):
- line = "%s%s%s" % (MAGENTA, line, ENDCOLOR)
- elif re.search('(^\+.*)', line):
- line = "%s%s%s" % (GREEN, line, ENDCOLOR)
- added = added + 1
- elif re.search('(^\-\-\- .*)', line):
- line = "%s%s%s" % (YELLOW, line, ENDCOLOR)
- elif re.search('(^\-.*)', line):
- line = "%s%s%s" % (RED, line, ENDCOLOR)
- deleted = deleted + 1
- else:
- pass
- sys.stdout.write(line)
- print('added ' + str(added) + ' deleted ' + str(deleted))
- except:
- print('exception')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement