@@ -27,10 +27,35 @@ my $ruler_width = git_config("diff-so-fancy.rulerWidth", undef);
27
27
my $git_strip_prefix = git_config_boolean(" diff.noprefix" ," false" );
28
28
my $has_stdin = has_stdin();
29
29
30
+ my $box_horizontal ;
31
+ my $box_vertical ;
32
+ my $box_down ;
33
+ my $box_up ;
34
+ # BOX DRAWINGS LIGHT HORIZONTAL http://www.fileformat.info/info/unicode/char/2500/index.htm
35
+ # BOX DRAWINGS LIGHT VERTICAL https://www.fileformat.info/info/unicode/char/2502/index.htm
36
+ # BOX DRAWINGS LIGHT DOWN AND LEFT https://www.fileformat.info/info/unicode/char/2510/index.htm
37
+ # BOX DRAWINGS LIGHT UP AND LEFT https://www.fileformat.info/info/unicode/char/2518/index.htm
38
+ if ($use_unicode_dash_for_ruler && should_print_unicode()) {
39
+ # $box_horizontal = Encode::encode('UTF-8', "\x{2500}");
40
+ $box_horizontal = " \xE2\x94\x80 " ;
41
+ # $box_vertical = Encode::encode('UTF-8', "\x{2502}");
42
+ $box_vertical = " \xE2\x94\x82 " ;
43
+ # $box_down = Encode::encode('UTF-8', "\x{2510}");
44
+ $box_down = " \xE2\x94\x90 " ;
45
+ # $box_up = Encode::encode('UTF-8', "\x{2518}");
46
+ $box_up = " \xE2\x94\x98 " ;
47
+ } else {
48
+ $box_horizontal = " -" ;
49
+ $box_vertical = " |" ;
50
+ $box_down = " ." ;
51
+ $box_up = " '" ;
52
+ }
53
+
30
54
my $ansi_color_regex = qr / (\e\[ ([0-9]{1,3}(;[0-9]{1,3}){0,10})[mK])?/ ;
31
55
my $reset_color = color(" reset" );
32
56
my $bold = color(" bold" );
33
57
my $meta_color = " " ;
58
+ my $commit_color = " " ;
34
59
35
60
# Set the diff highlight colors from the config
36
61
init_diff_highlight_colors();
@@ -147,13 +172,17 @@ sub do_dsf_stuff {
147
172
148
173
# ######################################################################
149
174
175
+ # #######################
176
+ # Look for commit line #
177
+ # #######################
178
+ if ($line =~ / ^${ansi_color_regex} commit [0-9a-f]{40}/ ) {
179
+ $commit_color = $1 || get_config_color(" commit" );
180
+ print_commit_box($line );
150
181
# ###################################################################
151
182
# Look for git index and replace it horizontal line (header later) #
152
183
# ###################################################################
153
- if ($line =~ / ^${ansi_color_regex} index / ) {
154
- # Print the line color and then the actual line
184
+ } elsif ($line =~ / ^${ansi_color_regex} index / ) {
155
185
$meta_color = $1 || get_config_color(" meta" );
156
-
157
186
# Get the next line without incrementing counter while loop
158
187
my $next = $input -> [0] || " " ;
159
188
my ($file_1 ,$file_2 );
@@ -173,9 +202,7 @@ sub do_dsf_stuff {
173
202
}
174
203
175
204
if ($file_1 && $file_2 ) {
176
- print horizontal_rule($meta_color );
177
- print $meta_color . file_change_string($file_1 ,$file_2 ) . " \n " ;
178
- print horizontal_rule($meta_color );
205
+ print_file_change_box(file_change_string($file_1 ,$file_2 ));
179
206
}
180
207
# ########################
181
208
# Look for the filename #
@@ -186,7 +213,6 @@ sub do_dsf_stuff {
186
213
# Mercurial looks like: diff -r 82e55d328c8c hello.c
187
214
if ($4 eq " -r" ) {
188
215
$is_mercurial = 1;
189
- $meta_color ||= get_config_color(" meta" );
190
216
# Git looks like: diff --git a/diff-so-fancy b/diff-so-fancy
191
217
} else {
192
218
$last_file_seen = $5 ;
@@ -202,8 +228,6 @@ sub do_dsf_stuff {
202
228
# Find the first file: --- a/README.md #
203
229
# #######################################
204
230
} elsif (!$in_hunk && $line =~ / ^$ansi_color_regex --- (\w\/ )?(.+?)(\e |\t |$) / ) {
205
- $meta_color ||= get_config_color(" meta" );
206
-
207
231
if ($git_strip_prefix ) {
208
232
my $file_dir = $4 || " " ;
209
233
$file_1 = $file_dir . $5 ;
@@ -228,20 +252,7 @@ sub do_dsf_stuff {
228
252
$last_file_seen = $file_2 ;
229
253
}
230
254
231
- # Print out the top horizontal line of the header
232
- print $reset_color ;
233
- print horizontal_rule($meta_color );
234
-
235
- # Mercurial coloring is slightly different so we need to hard reset colors
236
- if ($is_mercurial ) {
237
- print $reset_color ;
238
- }
239
-
240
- print $meta_color ;
241
- print file_change_string($file_1 ,$file_2 ) . " \n " ;
242
-
243
- # Print out the bottom horizontal line of the header
244
- print horizontal_rule($meta_color );
255
+ print_file_change_box(file_change_string($file_1 ,$file_2 ));
245
256
# #######################################
246
257
# Check for "@@ -3,41 +3,63 @@" syntax #
247
258
# #######################################
@@ -311,10 +322,8 @@ sub do_dsf_stuff {
311
322
# Look for binary file changes #
312
323
# ###############################
313
324
} elsif ($line =~ / ^Binary files (\w\/ )?(.+?) and (\w\/ )?(.+?) differ/ ) {
314
- my $change = file_change_string($2 ,$4 );
315
- print horizontal_rule($meta_color );
316
- print " $meta_color$change (binary)\n " ;
317
- print horizontal_rule($meta_color );
325
+ my ($change ,$change_length ) = file_change_string($2 ,$4 );
326
+ print_file_change_box($change . " (binary)" , $change_length + 9);
318
327
# ####################################################
319
328
# Check if we're changing the permissions of a file #
320
329
# ####################################################
@@ -353,14 +362,7 @@ sub do_dsf_stuff {
353
362
my ($file2 ) = $next =~ / rename to (.+?)(\e |\t |$) / ;
354
363
355
364
if ($file1 && $file2 ) {
356
- # We may not have extracted this yet, so we pull from the config if not
357
- $meta_color ||= get_config_color(" meta" );
358
-
359
- my $change = file_change_string($file1 ,$file2 );
360
-
361
- print horizontal_rule($meta_color );
362
- print $meta_color . $change . " \n " ;
363
- print horizontal_rule($meta_color );
365
+ print_file_change_box(file_change_string($file1 ,$file2 ));
364
366
}
365
367
366
368
$i += 3; # We've consumed three lines
@@ -623,26 +625,23 @@ sub trim {
623
625
return $s ;
624
626
}
625
627
626
- # Print a line of em-dash or line-drawing chars the full width of the screen
627
- sub horizontal_rule {
628
- my $color = $_ [0] || " " ;
629
- my $width = get_terminal_width();
630
-
631
- # em-dash http://www.fileformat.info/info/unicode/char/2014/index.htm
632
- # my $dash = "\x{2014}";
633
- # BOX DRAWINGS LIGHT HORIZONTAL http://www.fileformat.info/info/unicode/char/2500/index.htm
634
- my $dash ;
635
- if ($use_unicode_dash_for_ruler && should_print_unicode()) {
636
- # $dash = Encode::encode('UTF-8', "\x{2500}");
637
- $dash = " \xE2\x94\x80 " ;
638
- } else {
639
- $dash = " -" ;
640
- }
641
-
642
- # Draw the line
643
- my $ret = $color . ($dash x $width ) . " $reset_color \n " ;
628
+ sub print_commit_box {
629
+ my $line = shift ();
630
+ my $ruler = $box_horizontal x get_terminal_width();
631
+ $commit_color ||= get_config_color(" commit" );
632
+ print $commit_color .$ruler .$reset_color ." \n " ;
633
+ print $line ;
634
+ print $commit_color .$ruler .$reset_color ." \n " ;
635
+ }
644
636
645
- return $ret ;
637
+ sub print_file_change_box {
638
+ my $change = shift ();
639
+ my $change_length = shift ();
640
+ my $ruler = $box_horizontal x ($change_length + 1);
641
+ $meta_color ||= get_config_color(" meta" );
642
+ print $meta_color .$ruler .$box_down .$reset_color ." \n " ;
643
+ print $meta_color .$change ." " .$meta_color .$box_vertical .$reset_color ." \n " ;
644
+ print $meta_color .$ruler .$box_up .$reset_color ." \n " ;
646
645
}
647
646
648
647
sub file_change_string {
@@ -651,25 +650,26 @@ sub file_change_string {
651
650
652
651
# If they're the same it's a modify
653
652
if ($file_1 eq $file_2 ) {
654
- return " modified: $file_1 " ;
653
+ return ( " modified: $file_1 " , 10 + length ( $file_1 )) ;
655
654
# If the first is /dev/null it's a new file
656
655
} elsif ($file_1 eq " /dev/null" ) {
657
656
my $add_color = $DiffHighlight::NEW_HIGHLIGHT [1];
658
- return " added: $add_color$file_2$reset_color " ;
657
+ return ( " added: $add_color$file_2$reset_color " , 7 + length ( $file_2 )) ;
659
658
# If the second is /dev/null it's a deletion
660
659
} elsif ($file_2 eq " /dev/null" ) {
661
660
my $del_color = $DiffHighlight::OLD_HIGHLIGHT [1];
662
- return " deleted: $del_color$file_1$reset_color " ;
661
+ return ( " deleted: $del_color$file_1$reset_color " , 9 + length ( $file_1 )) ;
663
662
# If the files aren't the same it's a rename
664
663
} elsif ($file_1 ne $file_2 ) {
665
664
my ($old , $new ) = DiffHighlight::highlight_pair($file_1 ,$file_2 ,{only_diff => 1});
666
665
# highlight_pair already includes reset_color, but adds newline characters that need to be trimmed off
667
666
$old = trim($old );
668
667
$new = trim($new );
669
- return " renamed: $old$meta_color to $new "
668
+ $meta_color ||= get_config_color(" meta" );
669
+ return (" renamed: $old$meta_color to $new " , 13 + length ($file_1 ) + length ($file_2 ));
670
670
# Something we haven't thought of yet
671
671
} else {
672
- return " $file_1 -> $file_2 " ;
672
+ return ( " $file_1 -> $file_2 " , 4 + length ( $file_1 ) + length ( $file_2 )) ;
673
673
}
674
674
}
675
675
@@ -871,6 +871,9 @@ sub color {
871
871
if ($str eq " meta" ) {
872
872
# Default ANSI yellow
873
873
$ret = git_ansi_color(git_config(' color.diff.meta' )) || color(11);
874
+ } elsif ($str eq " commit" ) {
875
+ # Default ANSI yellow bold
876
+ $ret = git_ansi_color(git_config(' color.diff.commit' )) || color(' 11_bold' );
874
877
} elsif ($str eq " reset" ) {
875
878
$ret = color(" reset" );
876
879
} elsif ($str eq " add_line" ) {
0 commit comments