Skip to content

Commit

Permalink
Merge pull request #6 from ymattw/issue4
Browse files Browse the repository at this point in the history
Merge ymattw's changes to introduce '--color' option.
  • Loading branch information
daveewart committed Jan 26, 2013
2 parents ed4822e + a0e7e9c commit 5fb657c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ colour escape sequences, otherwise displayed incorrectly or discarded by

$ diff -u file1 file2 | colordiff | less -R

Note above example assumes you set 'color_patches=yes' in your colordiffrc file
if it exists, if you want to force disable colour escape sequences (for example
pipe the output to patch(1)), you can use option '--color=no' to do that.

$ diff -u file1 file2 | colordiff --color=no | patch -p0 -d another-working-dir

If you have wdiff installed, colordiff will correctly colourise the added and
removed text, provided that the '-n' option is given to wdiff:

Expand Down
16 changes: 13 additions & 3 deletions colordiff.pl
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ sub detect_diff_type {
my $enable_verifymode;
my $specified_difftype;
my $enable_fakeexitcode;
my $colormode = "auto";
GetOptions(
# --enable-verifymode option is for testing behaviour of colordiff
# against standard test diffs
"verifymode" => \$enable_verifymode,
"fakeexitcode" => \$enable_fakeexitcode,
"difftype=s" => \$specified_difftype
"difftype=s" => \$specified_difftype,
"color=s" => \$colormode
# TODO - check that specified type is valid, issue warning if not
);

Expand Down Expand Up @@ -255,9 +257,17 @@ sub detect_diff_type {
}
}

# If output is to a file, switch off colours, unless 'color_patch' is set
# --color=yes and --color=no will override the color_patches setting
if ($colormode eq "yes") {
$color_patch = 1;
} elsif ($colormode eq "no") {
$color_patch = 0;
}

# If output is to a file, switch off colours, unless 'color_patch' is set, if
# --color=no is specified, force disable colours too
# Relates to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=378563
if ((-f STDOUT) && ($color_patch == 0)) {
if (((-f STDOUT) && ($color_patch == 0)) || ($colormode eq "no")) {
$plain_text = '';
$file_old = '';
$file_new = '';
Expand Down

0 comments on commit 5fb657c

Please sign in to comment.