diff --git a/bin/prove b/bin/prove index 6637cc44..13286472 100755 --- a/bin/prove +++ b/bin/prove @@ -108,12 +108,12 @@ matching the pattern C. =head2 Colored Test Output -Colored test output using L is the default, but -if output is not to a terminal, color is disabled. You can override this by +Colored test output using L is the default, but +if output is not to a terminal, color is disabled. You can override this by adding the C<--color> switch. -Color support requires L on Unix-like platforms and -L on windows. If the necessary module is not installed +Color support requires L and, on windows platforms, also +L. If the necessary module(s) are not installed colored output will not be available. =head2 Exit Code diff --git a/lib/App/Prove.pm b/lib/App/Prove.pm index c3216592..f522832d 100644 --- a/lib/App/Prove.pm +++ b/lib/App/Prove.pm @@ -279,7 +279,7 @@ sub _help { sub _color_default { my $self = shift; - return -t STDOUT && !$ENV{HARNESS_NOTTY} && !IS_WIN32; + return -t STDOUT && !$ENV{HARNESS_NOTTY}; } sub _get_args { diff --git a/lib/TAP/Formatter/Color.pm b/lib/TAP/Formatter/Color.pm index 43084d14..7ed477a3 100644 --- a/lib/TAP/Formatter/Color.pm +++ b/lib/TAP/Formatter/Color.pm @@ -12,56 +12,24 @@ my $NO_COLOR; BEGIN { $NO_COLOR = 0; + eval 'require Term::ANSIColor'; + if ($@) { + $NO_COLOR = $@; + }; if (IS_WIN32) { - eval 'use Win32::Console'; + eval 'use Win32::Console::ANSI'; if ($@) { $NO_COLOR = $@; } - else { - my $console = Win32::Console->new( STD_OUTPUT_HANDLE() ); - - # eval here because we might not know about these variables - my $fg = eval '$FG_LIGHTGRAY'; - my $bg = eval '$BG_BLACK'; - - *set_color = sub { - my ( $self, $output, $color ) = @_; - - my $var; - if ( $color eq 'reset' ) { - $fg = eval '$FG_LIGHTGRAY'; - $bg = eval '$BG_BLACK'; - } - elsif ( $color =~ /^on_(.+)$/ ) { - $bg = eval '$BG_' . uc($1); - } - else { - $fg = eval '$FG_' . uc($color); - } - - # In case of colors that aren't defined - $self->set_color('reset') - unless defined $bg && defined $fg; - - $console->Attr( $bg | $fg ); - }; - } - } - else { - eval 'use Term::ANSIColor'; - if ($@) { - $NO_COLOR = $@; - } - else { - *set_color = sub { - my ( $self, $output, $color ) = @_; - $output->( color($color) ); - }; - } - } + }; if ($NO_COLOR) { *set_color = sub { }; + } else { + *set_color = sub { + my ( $self, $output, $color ) = @_; + $output->( Term::ANSIColor::color($color) ); + }; } } @@ -87,7 +55,7 @@ in color. Passing tests are printed in green. Failing tests are in red. Skipped tests are blue on a white background and TODO tests are printed in white. -If L cannot be found (or L if running +If L cannot be found (and L if running under Windows) tests will be run without color. =head1 SYNOPSIS