Advertisement
dyeske

Untitled

Oct 5th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """ This takes unified diff output and adds colors """
  3.  
  4. import re
  5. import sys
  6.  
  7. def main():
  8.     """ main routine """
  9.     RED = '\033[0;31m'
  10.     GREEN = '\033[0;32m'
  11.     YELLOW = '\033[0;33m'
  12.     BLUE = '\033[0;34m'
  13.     MAGENTA = '\033[0;35m'
  14.     ENDCOLOR = '\033[0m'
  15.     added = 0
  16.     deleted = 0
  17.  
  18.     try:
  19.         for line in sys.stdin:
  20.             if re.search('(^Index: .*)', line):
  21.                 line = "%s%s%s" % (BLUE, line, ENDCOLOR)
  22.             elif re.search('(^\+\+\+ .*)', line):
  23.                 line = "%s%s%s" % (MAGENTA, line, ENDCOLOR)
  24.             elif re.search('(^\+.*)', line):
  25.                 line = "%s%s%s" % (GREEN, line, ENDCOLOR)
  26.                 added = added + 1
  27.             elif re.search('(^\-\-\- .*)', line):
  28.                 line = "%s%s%s" % (YELLOW, line, ENDCOLOR)
  29.             elif re.search('(^\-.*)', line):
  30.                 line = "%s%s%s" % (RED, line, ENDCOLOR)
  31.                 deleted = deleted + 1
  32.             else:
  33.                 pass
  34.             sys.stdout.write(line)
  35.         print 'added ' + str(added) + ' deleted ' + str(deleted)
  36.     except:
  37.         print 'exception'
  38.  
  39. if __name__ == '__main__':
  40.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement