@@ -332,10 +332,11 @@ unshift @INC, bless \%fatpacked, $class;
332
332
} # END OF FATPACK CODE
333
333
334
334
335
- my $VERSION = " 1.2.6 " ;
335
+ my $VERSION = " 1.3.0 " ;
336
336
337
337
# ################################################################################
338
338
339
+ use 5.010; # Require Perl 5.10 for 'state' variables
339
340
use File::Spec; # For catdir
340
341
use File::Basename; # For dirname
341
342
use Encode; # For handling UTF8 stuff
@@ -497,7 +498,7 @@ sub do_dsf_stuff {
497
498
# Look for the filename #
498
499
# ########################
499
500
# $4 $5
500
- } elsif ($line =~ / ^${ansi_color_regex} diff (-r|--git|--cc) (.+ ?)(\s | \e |$) / ) {
501
+ } elsif ($line =~ / ^${ansi_color_regex} diff (-r|--git|--cc) (.* ?)(\e | b \/ |$) / ) {
501
502
502
503
# Mercurial looks like: diff -r 82e55d328c8c hello.c
503
504
if ($4 eq " -r" ) {
@@ -557,8 +558,13 @@ sub do_dsf_stuff {
557
558
# #######################################
558
559
# Check for "@@ -3,41 +3,63 @@" syntax #
559
560
# #######################################
561
+ } elsif (!$change_hunk_indicators && $line =~ / ^${ansi_color_regex} (@@@* .+? @@@*)(.*)/ ) {
562
+ $in_hunk = 1;
563
+
564
+ print $line ;
560
565
} elsif ($change_hunk_indicators && $line =~ / ^${ansi_color_regex} (@@@* .+? @@@*)(.*)/ ) {
561
- $in_hunk = 1;
566
+ $in_hunk = 1;
567
+
562
568
my $hunk_header = $4 ;
563
569
my $remain = bleach_text($5 );
564
570
@@ -580,7 +586,21 @@ sub do_dsf_stuff {
580
586
my $start_line = start_line_calc($new_offset ,$new_count );
581
587
582
588
# Last function has it's own color
583
- my $last_function_color = get_config_color(" last_function" );
589
+ my $last_function_color = " " ;
590
+ if ($remain ) {
591
+ $last_function_color = get_config_color(" last_function" );
592
+ }
593
+
594
+ # Check to see if we have the color for the fragment from git
595
+ if ($5 =~ / \e\[\d / ) {
596
+ # print "Has ANSI color for fragment\n";
597
+ } else {
598
+ # We don't have the ANSI sequence so we shell out to get it
599
+ # print "No ANSI color for fragment\n";
600
+ my $frag_color = get_config_color(" fragment" );
601
+ print $frag_color ;
602
+ }
603
+
584
604
print " @ $last_file_seen :$start_line \@ ${bold}${last_function_color}${remain}${reset_color} \n " ;
585
605
# ##################################
586
606
# Remove any new file permissions #
@@ -688,8 +708,19 @@ sub mark_empty_line {
688
708
my $reset_color = " \e\\ [0?m" ;
689
709
my $reset_escape = " \e\[ m" ;
690
710
my $invert_color = " \e\[ 7m" ;
691
-
692
- $line =~ s / ^($ansi_color_regex)[+-]$reset_color\s *$/ $invert_color$1 $reset_escape \n / ;
711
+ my $add_color = $DiffHighlight::NEW_HIGHLIGHT [1];
712
+ my $del_color = $DiffHighlight::OLD_HIGHLIGHT [1];
713
+
714
+ # This captures lines that do not have any ANSI in them (raw vanilla diff)
715
+ if ($line eq " +\n " ) {
716
+ $line = $invert_color . $add_color . " " . color(' reset' ) . " \n " ;
717
+ # This captures lines that do not have any ANSI in them (raw vanilla diff)
718
+ } elsif ($line eq " -\n " ) {
719
+ $line = $invert_color . $del_color . " " . color(' reset' ) . " \n " ;
720
+ # This handles everything else
721
+ } else {
722
+ $line =~ s / ^($ansi_color_regex)[+-]$reset_color\s *$/ $invert_color$1 $reset_escape \n / ;
723
+ }
693
724
694
725
return $line ;
695
726
}
@@ -890,11 +921,7 @@ sub trim {
890
921
# Print a line of em-dash or line-drawing chars the full width of the screen
891
922
sub horizontal_rule {
892
923
my $color = $_ [0] || " " ;
893
- my $width = $ruler_width || ` tput cols` ;
894
-
895
- if (is_windows()) {
896
- $width --;
897
- }
924
+ my $width = get_terminal_width();
898
925
899
926
# em-dash http://www.fileformat.info/info/unicode/char/2014/index.htm
900
927
# my $dash = "\x{2014}";
@@ -907,7 +934,7 @@ sub horizontal_rule {
907
934
}
908
935
909
936
# Draw the line
910
- my $ret = $color . ($dash x $width ) . " \n " ;
937
+ my $ret = $color . ($dash x $width ) . " $reset_color \n " ;
911
938
912
939
return $ret ;
913
940
}
@@ -984,9 +1011,12 @@ sub usage {
984
1011
985
1012
$out .= " Usage:
986
1013
987
- git diff --color | diff-so-fancy # Use d-s-f on one diff
988
- diff-so-fancy --colors # View the commands to set the recommended colors
989
- diff-so-fancy --set-defaults # Configure git-diff to use diff-so-fancy and suggested colors
1014
+ git diff --color | diff-so-fancy # Use d-s-f on one diff
1015
+ cat diff.txt | diff-so-fancy # Use d-s-f on a diff/patch file
1016
+ diff -u one.txt two.txt | diff-so-fancy # Use d-s-f on unified diff output
1017
+
1018
+ diff-so-fancy --colors # View the commands to set the recommended colors
1019
+ diff-so-fancy --set-defaults # Configure git-diff to use diff-so-fancy and suggested colors
990
1020
991
1021
# Configure git to use d-s-f for *all* diff operations
992
1022
git config --global core.pager \" diff-so-fancy | less --tabs=4 -RFX\"\n " ;
@@ -1130,6 +1160,8 @@ sub color {
1130
1160
return $static_config -> {$str };
1131
1161
}
1132
1162
1163
+ # print color(15) . "Shelling out for color: '$str'\n" . color('reset');
1164
+
1133
1165
if ($str eq " meta" ) {
1134
1166
# Default ANSI yellow
1135
1167
$ret = DiffHighlight::color_config(' color.diff.meta' , color(11));
@@ -1141,8 +1173,10 @@ sub color {
1141
1173
} elsif ($str eq " remove_line" ) {
1142
1174
# Default ANSI red
1143
1175
$ret = DiffHighlight::color_config(' color.diff.old' , color(' bold' ) . color(1));
1176
+ } elsif ($str eq " fragment" ) {
1177
+ $ret = DiffHighlight::color_config(' color.diff.frag' , color(' 13_bold' ));
1144
1178
} elsif ($str eq " last_function" ) {
1145
- $ret = DiffHighlight::color_config(' color.diff.func' , color(146));
1179
+ $ret = DiffHighlight::color_config(' color.diff.func' , color(' bold ' ) . color( 146));
1146
1180
}
1147
1181
1148
1182
# Cache (memoize) the entry for later
@@ -1162,4 +1196,34 @@ sub starts_with_ansi {
1162
1196
}
1163
1197
}
1164
1198
1199
+ sub get_terminal_width {
1200
+ # Make width static so we only calculate it once
1201
+ state $width ;
1202
+
1203
+ if ($width ) {
1204
+ return $width ;
1205
+ }
1206
+
1207
+ # If there is a ruler width in the config we use that
1208
+ if ($ruler_width ) {
1209
+ $width = $ruler_width ;
1210
+ # Otherwise we check the terminal width using tput
1211
+ } else {
1212
+ my $tput = ` tput cols` ;
1213
+
1214
+ if ($tput ) {
1215
+ $width = int ($tput );
1216
+
1217
+ if (is_windows()) {
1218
+ $width --;
1219
+ }
1220
+ } else {
1221
+ print color(' orange' ) . " Warning: `tput cols` did not return numeric input" . color(' reset' ) . " \n " ;
1222
+ $width = 80;
1223
+ }
1224
+ }
1225
+
1226
+ return $width ;
1227
+ }
1228
+
1165
1229
# vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4
0 commit comments