Mercurial > diff-colorize
comparison diff-colorize.py @ 17:54a209909531
Make the file importable for debugging purposes by wrapping the main-program-only bits in an if __name__ == "__main__" block.
author | Peter Hosey <hg@boredzo.org> |
---|---|
date | Mon, 03 Jan 2011 20:27:37 -0800 |
parents | a7214992f904 |
children | 83d58ccc70bf 948c96784f00 |
comparison
equal
deleted
inserted
replaced
16:4950e751a7cb | 17:54a209909531 |
---|---|
120 COLOR_FORMAT % (hunk_start_color,) | 120 COLOR_FORMAT % (hunk_start_color,) |
121 + BEGIN_REVERSE_FORMAT | 121 + BEGIN_REVERSE_FORMAT |
122 + '@@' | 122 + '@@' |
123 ) | 123 ) |
124 | 124 |
125 if sys.stdin.isatty(): | 125 if __name__ == "__main__": |
126 # Standard input is a TTY, meaning that the user ran 'diff-colorize' at the shell prompt, without redirecting anything into it. Print usage info and exit. | 126 if sys.stdin.isatty(): |
127 sys.exit(USAGE) | 127 # Standard input is a TTY, meaning that the user ran 'diff-colorize' at the shell prompt, without redirecting anything into it. Print usage info and exit. |
128 sys.exit(USAGE) | |
128 | 129 |
129 for line in fileinput.input(): | 130 for line in fileinput.input(): |
130 for prefix_to_test in prefixes: | 131 for prefix_to_test in prefixes: |
131 if line.startswith(prefix_to_test): | 132 if line.startswith(prefix_to_test): |
132 sys.stdout.write(prefixes[prefix_to_test]) | 133 sys.stdout.write(prefixes[prefix_to_test]) |
133 line = line[len(prefix_to_test):] | 134 line = line[len(prefix_to_test):] |
134 | 135 |
135 sys.stdout.write(line) | 136 sys.stdout.write(line) |
136 | 137 |
137 sys.stdout.write(RESET_FORMAT) | 138 sys.stdout.write(RESET_FORMAT) |