Skip to content

Commit c0099d9

Browse files
Bump the fatpacked version up to v1.3.0
1 parent 70d4d9d commit c0099d9

File tree

1 file changed

+80
-16
lines changed

1 file changed

+80
-16
lines changed

third_party/build_fatpack/diff-so-fancy

+80-16
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,11 @@ unshift @INC, bless \%fatpacked, $class;
332332
} # END OF FATPACK CODE
333333

334334

335-
my $VERSION = "1.2.6";
335+
my $VERSION = "1.3.0";
336336

337337
#################################################################################
338338

339+
use 5.010; # Require Perl 5.10 for 'state' variables
339340
use File::Spec; # For catdir
340341
use File::Basename; # For dirname
341342
use Encode; # For handling UTF8 stuff
@@ -497,7 +498,7 @@ sub do_dsf_stuff {
497498
# Look for the filename #
498499
#########################
499500
# $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\/|$)/) {
501502

502503
# Mercurial looks like: diff -r 82e55d328c8c hello.c
503504
if ($4 eq "-r") {
@@ -557,8 +558,13 @@ sub do_dsf_stuff {
557558
########################################
558559
# Check for "@@ -3,41 +3,63 @@" syntax #
559560
########################################
561+
} elsif (!$change_hunk_indicators && $line =~ /^${ansi_color_regex}(@@@* .+? @@@*)(.*)/) {
562+
$in_hunk = 1;
563+
564+
print $line;
560565
} elsif ($change_hunk_indicators && $line =~ /^${ansi_color_regex}(@@@* .+? @@@*)(.*)/) {
561-
$in_hunk = 1;
566+
$in_hunk = 1;
567+
562568
my $hunk_header = $4;
563569
my $remain = bleach_text($5);
564570

@@ -580,7 +586,21 @@ sub do_dsf_stuff {
580586
my $start_line = start_line_calc($new_offset,$new_count);
581587

582588
# 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+
584604
print "@ $last_file_seen:$start_line \@${bold}${last_function_color}${remain}${reset_color}\n";
585605
###################################
586606
# Remove any new file permissions #
@@ -688,8 +708,19 @@ sub mark_empty_line {
688708
my $reset_color = "\e\\[0?m";
689709
my $reset_escape = "\e\[m";
690710
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+
}
693724

694725
return $line;
695726
}
@@ -890,11 +921,7 @@ sub trim {
890921
# Print a line of em-dash or line-drawing chars the full width of the screen
891922
sub horizontal_rule {
892923
my $color = $_[0] || "";
893-
my $width = $ruler_width || `tput cols`;
894-
895-
if (is_windows()) {
896-
$width--;
897-
}
924+
my $width = get_terminal_width();
898925

899926
# em-dash http://www.fileformat.info/info/unicode/char/2014/index.htm
900927
#my $dash = "\x{2014}";
@@ -907,7 +934,7 @@ sub horizontal_rule {
907934
}
908935

909936
# Draw the line
910-
my $ret = $color . ($dash x $width) . "\n";
937+
my $ret = $color . ($dash x $width) . "$reset_color\n";
911938

912939
return $ret;
913940
}
@@ -984,9 +1011,12 @@ sub usage {
9841011

9851012
$out .= "Usage:
9861013
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
9901020
9911021
# Configure git to use d-s-f for *all* diff operations
9921022
git config --global core.pager \"diff-so-fancy | less --tabs=4 -RFX\"\n";
@@ -1130,6 +1160,8 @@ sub color {
11301160
return $static_config->{$str};
11311161
}
11321162

1163+
#print color(15) . "Shelling out for color: '$str'\n" . color('reset');
1164+
11331165
if ($str eq "meta") {
11341166
# Default ANSI yellow
11351167
$ret = DiffHighlight::color_config('color.diff.meta', color(11));
@@ -1141,8 +1173,10 @@ sub color {
11411173
} elsif ($str eq "remove_line") {
11421174
# Default ANSI red
11431175
$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'));
11441178
} 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));
11461180
}
11471181

11481182
# Cache (memoize) the entry for later
@@ -1162,4 +1196,34 @@ sub starts_with_ansi {
11621196
}
11631197
}
11641198

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+
11651229
# vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4

0 commit comments

Comments
 (0)