Last active
January 1, 2016 13:59
-
-
Save kaz-utashiro/8155175 to your computer and use it in GitHub Desktop.
print function to remove wdiff control sequence for greple command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub print_wdiff { | |
my %arg = @_; | |
my @matched = @{$arg{matched}}; | |
for (my $i = $#matched; $i >= 0; $i--) { | |
my($s, $e) = @{$matched[$i]}; | |
my $t = substr($_, $s, $e - $s); | |
if ($t =~ s/\A (?:\{\+|\[\-) (.*) (?:\+\}|\-\]) \Z/$1/sx) { | |
substr($_, $s, $e - $s) = $t; | |
$matched[$i][0] = $s - $i * 4; | |
$matched[$i][1] = $e - $i * 4 - 4; | |
} else { | |
die; | |
} | |
} | |
$_; | |
} | |
1; | |
__DATA__ | |
option --wdiffcolor \ | |
--all \ | |
--print print_wdiff --continue \ | |
--re '(?s)\[\-.*?\-\]' --addcolor R \ | |
--re '(?s)\{\+.*?\+\}' --addcolor G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment