Description: |
Takes sdiff output and adds highlighting - red for deletions, yellow for changes, green for additions. The default pivot for sdiff is column 65 because of its default width of 130 characters. You'll want to adjust the --pivot parameter to match your sdiff. There's no smarts in here about tabs. Use sdiff's -t option to print only spaces. |
#!/usr/local/bin/perl
use strict;
use warnings;
use Term::ANSIColor 'colored';
use Getopt::Long 'GetOptions';
$Term::ANSIColor::EACHLINE = "\n";
# sdiff default is 130 columns
my $pivot = 65;
GetOptions(
'pivot=i' => \ $pivot,
'help' => \ &help,
)
or pod2usage( -verbose => 1 );
my $del_rx = qr/^@{[ '.' x ( $pivot - 2 )]} < /;
my $diff_rx = qr/^@{[ '.' x ( $pivot - 2 )]} \| /;
my $add_rx = qr/^@{[ '.' x ( $pivot - 2 )]} > /;
while (<>) {
if ( /$del_rx/o ) {
$_ = colored( $_, 'red on_black' );
}
elsif ( /$diff_rx/o ) {
$_ = colored( $_, 'yellow on_black' );
}
elsif ( /$add_rx/o ) {
$_ = colored( $_, 'green on_black' );
}
print;
}
|