--- /usr/bin/colordiff 2009-04-29 09:56:04.000000000 +0200 +++ /home/manu/bin/colordiff 2013-03-29 12:27:34.789423159 +0100 @@ -141,9 +141,20 @@ } } -# If output is to a file, 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)) { +# We explicitly close STDOUT always. +END { close(STDOUT) || die "can't close stdout: $!" } + + +my $use_color ="auto"; + +my $specified_difftype; +GetOptions( + "difftype=s" => \$specified_difftype, + "color:s" => \$use_color +); + +if (($use_color eq 'auto' and (!(-t STDOUT) && ($color_patch == 0))) + or ($use_color eq 'never' or $use_color eq 'no')) { $plain_text = ''; $file_old = ''; $file_new = ''; @@ -151,12 +162,18 @@ $cvs_stuff = ''; $plain_text = ''; $colour{off} = ''; +} elsif ($use_color eq 'auto' + or $use_color eq 'yes' or $use_color eq 'always') { + # Nothing to do +} else { + print STDERR "Unknown value for option '--color': $use_color\n"; + print STDERR "Valid options are:\n". + " --color[=WHEN],\n". + " --colour[=WHEN] use markers to highlight the matching strings;\n". + " WHEN is `always', `never', or `auto'\n"; + exit(1); } -my $specified_difftype; -GetOptions( - "difftype=s" => \$specified_difftype -); # TODO - check that specified type is valid, issue warning if not # ---------------------------------------------------------------------------- @@ -166,6 +183,13 @@ print STDERR "$copyright $author, $author_email\n\n"; } +# If output is to a file, switch off colours, unless 'color_patch' is set +# Relates to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=378563 +if (-t STDOUT) { + my $pager = $ENV{PAGER} || "less -r"; + print $pager."\n"; + open(STDOUT, "| $pager") or die "can't fork a pager: $!"; +} # FIXME - work out some magic here to make it rip off # colordiff-specific long options, such as: #