Created
July 30, 2015 10:29
-
-
Save kaosf/b6392be33be2e8af7904 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git contrib/diff-highlight/diff-highlight contrib/diff-highlight/diff-highlight | |
| index ffefc31..c2547cf 100755 | |
| --- contrib/diff-highlight/diff-highlight | |
| +++ contrib/diff-highlight/diff-highlight | |
| @@ -4,6 +4,8 @@ use 5.008; | |
| use warnings FATAL => 'all'; | |
| use strict; | |
| +use Encode qw(decode_utf8 encode_utf8); | |
| + | |
| # Highlight by reversing foreground and background. You could do | |
| # other things like bold or underline if you prefer. | |
| my @OLD_HIGHLIGHT = ( | |
| @@ -35,10 +37,10 @@ while (<>) { | |
| $in_hunk = /^$COLOR*\@/; | |
| } | |
| elsif (/^$COLOR*-/) { | |
| - push @removed, $_; | |
| + push @removed, decode_utf8($_); | |
| } | |
| elsif (/^$COLOR*\+/) { | |
| - push @added, $_; | |
| + push @added, decode_utf8($_); | |
| } | |
| else { | |
| show_hunk(\@removed, \@added); | |
| @@ -84,7 +86,7 @@ sub show_hunk { | |
| # If one side is empty, then there is nothing to compare or highlight. | |
| if (!@$a || !@$b) { | |
| - print @$a, @$b; | |
| + print encode_utf8($_) for @$a, @$b; | |
| return; | |
| } | |
| @@ -93,17 +95,17 @@ sub show_hunk { | |
| # stupid, and only handle multi-line hunks that remove and add the same | |
| # number of lines. | |
| if (@$a != @$b) { | |
| - print @$a, @$b; | |
| + print encode_utf8($_) for @$a, @$b; | |
| return; | |
| } | |
| my @queue; | |
| for (my $i = 0; $i < @$a; $i++) { | |
| my ($rm, $add) = highlight_pair($a->[$i], $b->[$i]); | |
| - print $rm; | |
| + print encode_utf8($rm); | |
| push @queue, $add; | |
| } | |
| - print @queue; | |
| + print encode_utf8($_) for @queue; | |
| } | |
| sub highlight_pair { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment