Skip to content

Commit

Permalink
Merge pull request daveewart#5 from ymattw/current
Browse files Browse the repository at this point in the history
Merging ymattw's code with a few to applying further modifications to ensure that existing behaviour is not modified for existing users.
  • Loading branch information
daveewart committed Jan 21, 2013
2 parents a79dc09 + 99ed794 commit a71c4b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ For example:
$ colordiff file1 file2
$ diff -u file1 file2 | colordiff

You can pipe the output to 'less', using the '-R' option (some systems or
terminal types may get better results using '-r' instead), which keeps the
colour escape sequences, otherwise displayed incorrectly or discarded by
'less':
With option '--color=yes', you can pipe the colorful output to 'less', using the
'-R' option (some systems or terminal types may get better results using '-r'
instead), which keeps the colour escape sequences, otherwise displayed
incorrectly or discarded by 'less':

$ diff -u file1 file2 | colordiff | less -R
$ diff -u file1 file2 | colordiff --color=yes | less -R

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 Expand Up @@ -66,7 +66,7 @@ function cvsdiff () { cvs diff $@ | colordiff; }

Or, combining the idea above using 'less':

function cvsdiff () { cvs diff $@ | colordiff |less -R; }
function cvsdiff () { cvs diff $@ | colordiff --color=yes |less -R; }

Note that the function name, cvsdiff, can be customized.

Expand Down
15 changes: 12 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,16 @@ 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 not a terminal, switch off colours, unless 'color_patch' is set
# Relates to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=378563
if ((-f STDOUT) && ($color_patch == 0)) {
if ((! -t 1) && ($color_patch == 0)) {
$plain_text = '';
$file_old = '';
$file_new = '';
Expand Down
7 changes: 4 additions & 3 deletions colordiffrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# colordiff output
banner=no
# By default, when colordiff output is being redirected
# to a file, it detects this and does not colour-highlight
# To make the patch file *include* colours, change the option
# below to 'yes'
# to a file or being piped out to other program, it detects
# this and does not colour-highlight. To make the patch file
# *include* colours, change the option below to 'yes'. You
# can also use the --color=yes|no option to overide this
color_patches=no
# Sometimes it can be useful to specify which diff command to
# use: that can be specified here
Expand Down

0 comments on commit a71c4b0

Please sign in to comment.