diff --git a/Makefile.PL b/Makefile.PL index 53b7441..e326412 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,4 +1,4 @@ -# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.024. +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.032. use strict; use warnings; @@ -18,6 +18,7 @@ my %WriteMakefileArgs = ( "NAME" => "Rex::Hook::File::Diff", "PREREQ_PM" => { "File::Basename" => 0, + "IPC::Run" => 0, "Rex" => "1.013004", "Rex::Helper::Run" => 0, "Rex::Hook" => 0, @@ -46,6 +47,7 @@ my %FallbackPrereqs = ( "File::Basename" => 0, "File::Temp" => 0, "File::Touch" => "0.08", + "IPC::Run" => 0, "Rex" => "1.013004", "Rex::Commands::File" => "1.012", "Rex::Helper::Run" => 0, diff --git a/cpanfile b/cpanfile index ba3ee66..2485ef0 100644 --- a/cpanfile +++ b/cpanfile @@ -1,7 +1,8 @@ -# This file is generated by Dist::Zilla::Plugin::CPANFile v6.024 +# This file is generated by Dist::Zilla::Plugin::CPANFile v6.032 # Do not edit this file directly. To change prereqs, edit the `dist.ini` file. requires "File::Basename" => "0"; +requires "IPC::Run" => "0"; requires "Rex" => "1.013004"; requires "Rex::Helper::Run" => "0"; requires "Rex::Hook" => "0"; diff --git a/lib/Rex/Hook/File/Diff.pm b/lib/Rex/Hook/File/Diff.pm index 67d4bbb..29d2e24 100644 --- a/lib/Rex/Hook/File/Diff.pm +++ b/lib/Rex/Hook/File/Diff.pm @@ -6,6 +6,7 @@ use 5.012; use warnings; use File::Basename; +use IPC::Run; use Rex 1.013004 -base; use Rex::Helper::Run; use Rex::Hook; @@ -39,6 +40,13 @@ sub show_diff { } if ( length $diff > 0 ) { + my @highlighter = qw( delta --color-only --diff-so-fancy ); + my $highlighted; + + IPC::Run::run \@highlighter, \$diff, \$highlighted; + + $diff = $highlighted; + Rex::Commands::say("Diff for: $original_file\n$diff"); } diff --git a/t/diff.t b/t/diff.t old mode 100644 new mode 100755 index e0a8d78..0917e49 --- a/t/diff.t +++ b/t/diff.t @@ -148,6 +148,9 @@ subtest 'full file lifecycle' => sub { subtest 'file command with source option' => sub { my $file = File::Temp->new( TEMPLATE => "$PROGRAM_NAME.XXXX" )->filename(); my $rex_tmp_filename = Rex::Commands::File::get_tmp_file_name($file); + my $red = qr/\e\[1;31m/; + my $green = qr/\e\[1;32m/; + my $reset_color = qr/\e\[0m/; my @tests = ( { @@ -193,8 +196,8 @@ subtest 'file command with source option' => sub { \Q+++ $rex_tmp_filename\E(\s+.*?)?\n # header for new file \Q@@ -1,2 +1,2 @@\E\n # hunk \Q 1\E\n # unchanged line - \Q-2\E\n # removed line - \Q+3\E\n # added line + $red\Q-2\E$reset_color\n # removed line + $green\Q+3\E$reset_color\n # added line \Z # end of output }, },