Skip to content

Commit 0281837

Browse files
committed
Don't include ansi color codes in file1 and file2
when processing renamed files. Use the same `(.+?)(\e|\t|$)` regexp used in other similar parts of the code. The motivation behind this change is to be able to process the file1 and file2 strings (e.g. get their length) without the interference of the extra ansi color codes. Also, the resulting d-s-f output is smaller with this change (34 bytes less for each "renamed: X to Y" line).
1 parent 93f360b commit 0281837

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

diff-so-fancy

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ sub do_dsf_stuff {
345345
}
346346

347347
my $next = shift(@$input);
348-
my ($file1) = $next =~ /rename from (.+)/;
348+
my ($file1) = $next =~ /rename from (.+?)(\e|\t|$)/;
349349

350350
$next = shift(@$input);
351-
my ($file2) = $next =~ /rename to (.+)/;
351+
my ($file2) = $next =~ /rename to (.+?)(\e|\t|$)/;
352352

353353
if ($file1 && $file2) {
354354
# We may not have extracted this yet, so we pull from the config if not
@@ -663,14 +663,10 @@ sub file_change_string {
663663
# If the files aren't the same it's a rename
664664
} elsif ($file_1 ne $file_2) {
665665
my ($old, $new) = DiffHighlight::highlight_pair($file_1,$file_2,{only_diff => 1});
666+
# highlight_pair already includes reset_color, but adds newline characters that need to be trimmed off
666667
$old = trim($old);
667668
$new = trim($new);
668-
669-
# highlight_pair resets the colors, but we want it to be the meta color
670-
$old =~ s/(\e0?\[m)/$1$meta_color/g;
671-
$new =~ s/(\e0?\[m)/$1$meta_color/g;
672-
673-
return "renamed: $old to $new";
669+
return "renamed: $old$meta_color to $new"
674670
# Something we haven't thought of yet
675671
} else {
676672
return "$file_1 -> $file_2";

0 commit comments

Comments
 (0)