~benoit.pierre/bzrtools/colordiff_when_tty

« back to all changes in this revision

Viewing changes to colordiff.py

  • Committer: Benoît Pierre
  • Date: 2008-11-17 20:34:27 UTC
  • Revision ID: benoit.pierre@gmail.com-20081117203427-4mv27d7qbuwnhzjx
Add --color=MODE option to cdiff; MODE can be:
* never: never colorize output
* auto: colorize output if terminal supports it, and STDOUT is a TTY
* always: always colorize ouput (default)

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
        self._old_lines, self._new_lines = ([], [])
180
180
 
181
181
 
182
 
def colordiff(check_style, *args, **kwargs):
 
182
def colordiff(color, check_style, *args, **kwargs):
183
183
    from terminal import has_ansi_colors
184
 
    if not has_ansi_colors():
 
184
    if 'never' == color or ('auto' == color and not has_ansi_colors()):
185
185
        get_cmd_object('diff').run(*args, **kwargs)
186
186
        return
187
187
    real_stdout = sys.stdout