From 4fc6d5057d06f26dda0d1fe0b296216b6885cace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Fri, 22 May 2020 12:07:22 +0200 Subject: [PATCH] Color each line instead of whole lines Right now, the color-end escape sequence will turn up after the last linebreak on its own line. This can actually disturb output, for example when running tests with prove. This change will make Term::ANSIColor color each line, without the linebreaks. --- lib/Mojo/Log/Colored.pm | 2 ++ t/via_mojo.t | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Mojo/Log/Colored.pm b/lib/Mojo/Log/Colored.pm index 5cd48b3..593ab99 100644 --- a/lib/Mojo/Log/Colored.pm +++ b/lib/Mojo/Log/Colored.pm @@ -27,6 +27,8 @@ sub format { return $self->_format( sub { + # Prevent having the end escape sequence at the start of the line + local $Term::ANSIColor::EACHLINE = "\n"; # only add colors if we have a color for this level exists $self->colors->{ $_[1] } ? colored( $format->(@_), $self->colors->{ $_[1] } ) diff --git a/t/via_mojo.t b/t/via_mojo.t index 6ff063c..dbdfdda 100644 --- a/t/via_mojo.t +++ b/t/via_mojo.t @@ -35,8 +35,8 @@ for my $level ( sort keys %defaults ) { like $stderr, qr{ \Q$defaults{$level}\E # color of this level, escaped $level - \n \e\[0m # end of coloring + \n }x, "log contains colors for $level"; } done_testing;