Skip to content

Commit

Permalink
Color each line instead of whole lines
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
perlpunk committed May 22, 2020
1 parent 0d004ff commit 4fc6d50
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/Mojo/Log/Colored.pm
Expand Up @@ -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] } )
Expand Down
2 changes: 1 addition & 1 deletion t/via_mojo.t
Expand Up @@ -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;
Expand Down

0 comments on commit 4fc6d50

Please sign in to comment.