comparison diff-colorize.py @ 15:a7214992f904 1.0b2

Added a different set of default color codes and a different colorization format string. Both of these are to support 16-color mode (which is all Terminal supports).
author Peter Hosey
date Mon, 11 Aug 2008 01:59:57 -0700
parents 89284f926abb
children 54a209909531
comparison
equal deleted inserted replaced
14:03603b3ec1c1 15:a7214992f904
2 2
3 import sys 3 import sys
4 import os 4 import os
5 import fileinput 5 import fileinput
6 6
7 index_color = int(os.environ.get('DIFF_INDEX_COLOR', 32)) 7 has_256_color = (os.environ.get('TERM', None) == 'xterm-256color')
8 old_mode_color = int(os.environ.get('DIFF_OLD_MODE_COLOR', 88)) 8
9 new_mode_color = int(os.environ.get('DIFF_NEW_MODE_COLOR', 28)) 9 index_color = int(os.environ.get('DIFF_INDEX_COLOR',
10 removed_color = int(os.environ.get('DIFF_REMOVED_COLOR', 160)) 10 32 if has_256_color else 36))
11 added_color = int(os.environ.get('DIFF_ADDED_COLOR', 2)) 11 old_mode_color = int(os.environ.get('DIFF_OLD_MODE_COLOR',
12 hunk_start_color = int(os.environ.get('DIFF_HUNK_START_COLOR', 32)) 12 88 if has_256_color else 31))
13 new_mode_color = int(os.environ.get('DIFF_NEW_MODE_COLOR',
14 28 if has_256_color else 32))
15 removed_color = int(os.environ.get('DIFF_REMOVED_COLOR',
16 160 if has_256_color else 31))
17 added_color = int(os.environ.get('DIFF_ADDED_COLOR',
18 2 if has_256_color else 32))
19 hunk_start_color = int(os.environ.get('DIFF_HUNK_START_COLOR',
20 32 if has_256_color else 36))
13 21
14 RESET_FORMAT = '\033[0m' 22 RESET_FORMAT = '\033[0m'
15 COLOR_FORMAT = '\033[38;5;%um' 23 COLOR_FORMAT_256 = '\033[38;5;%um'
24 COLOR_FORMAT_16 = '\033[38;%um'
25 COLOR_FORMAT = COLOR_FORMAT_256 if has_256_color else COLOR_FORMAT_16
16 BEGIN_REVERSE_FORMAT = '\033[7m' 26 BEGIN_REVERSE_FORMAT = '\033[7m'
17 END_REVERSE_FORMAT = '\033[27m' 27 END_REVERSE_FORMAT = '\033[27m'
18 28
19 USAGE = """ 29 USAGE = """
20 Usage: diff ... | diff-colorize 30 Usage: diff ... | diff-colorize