Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #4 without changing existing behaviour, just introduce new opti... #6

Merged
merged 1 commit into from
Jan 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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