Skip to content

Commit eb4a5e7

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 19e55f6 commit eb4a5e7

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
@@ -318,10 +318,10 @@ sub do_dsf_stuff {
318318
}
319319

320320
my $next = shift(@$input);
321-
my ($file1) = $next =~ /rename from (.+)/;
321+
my ($file1) = $next =~ /rename from (.+?)(\e|\t|$)/;
322322

323323
$next = shift(@$input);
324-
my ($file2) = $next =~ /rename to (.+)/;
324+
my ($file2) = $next =~ /rename to (.+?)(\e|\t|$)/;
325325

326326
if ($file1 && $file2) {
327327
# We may not have extracted this yet, so we pull from the config if not
@@ -625,14 +625,10 @@ sub file_change_string {
625625
# If the files aren't the same it's a rename
626626
} elsif ($file_1 ne $file_2) {
627627
my ($old, $new) = DiffHighlight::highlight_pair($file_1,$file_2,{only_diff => 1});
628+
# highlight_pair already includes reset_color, but adds newline characters that need to be trimmed off
628629
$old = trim($old);
629630
$new = trim($new);
630-
631-
# highlight_pair resets the colors, but we want it to be the meta color
632-
$old =~ s/(\e0?\[m)/$1$meta_color/g;
633-
$new =~ s/(\e0?\[m)/$1$meta_color/g;
634-
635-
return "renamed: $old to $new";
631+
return "renamed: $old$meta_color to $new"
636632
# Something we haven't thought of yet
637633
} else {
638634
return "$file_1 -> $file_2";

0 commit comments

Comments
 (0)