@@ -27,7 +27,8 @@ 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 $ansi_color_regex = qr / (\e\[ ([0-9]{1,3}(;[0-9]{1,3}){0,10})[mK])?/ ;
30
+ my $ansi_regex = qr /\e\[ ([0-9]{1,3}(;[0-9]{1,3}){0,10})[mK]/ ;
31
+ my $ansi_color_regex = qr / (${ansi_regex} )?/ ;
31
32
my $reset_color = color(" reset" );
32
33
my $bold = color(" bold" );
33
34
my $meta_color = " " ;
@@ -120,7 +121,7 @@ my $line_count = 0;
120
121
while (my $line = <STDIN >) {
121
122
# If the very first line of the diff doesn't start with ANSI color we're assuming
122
123
# it's a raw patch file, and we have to color the added/removed lines ourself
123
- if (!$color_forced && $line_count == 0 && starts_with_ansi($line )) {
124
+ if (!$color_forced && $line_count == 0 && ! starts_with_ansi($line )) {
124
125
$manually_color_lines = 1;
125
126
}
126
127
@@ -992,7 +993,8 @@ sub is_numeric {
992
993
sub starts_with_ansi {
993
994
my $str = shift ();
994
995
995
- if ($str =~ / ^$ansi_color_regex / ) {
996
+ # NOTE: This is not `ansi_color_regex`, which includes "no ANSI sequences".
997
+ if ($str =~ / ^$ansi_regex / ) {
996
998
return 1;
997
999
} else {
998
1000
return 0;
0 commit comments