diff options
author | Steve Hay <steve.m.hay@googlemail.com> | 2016-11-01 17:29:33 +0000 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2016-11-01 17:29:33 +0000 |
commit | 93d7ac13d34e6b9246990d232910a98d65549808 (patch) | |
tree | 5c1812953b14a2db31adf8a0db68099f2fd84c7a /cpan | |
parent | 5585e758ec847fcd75936b77096edf5234d6e0c0 (diff) | |
download | perl-93d7ac13d34e6b9246990d232910a98d65549808.tar.gz |
Upgrade Term::ANSIColor from version 4.05 to 4.06
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/Term-ANSIColor/lib/Term/ANSIColor.pm | 49 | ||||
-rw-r--r-- | cpan/Term-ANSIColor/t/lib/Test/RRA.pm | 51 | ||||
-rw-r--r-- | cpan/Term-ANSIColor/t/lib/Test/RRA/Config.pm | 30 | ||||
-rw-r--r-- | cpan/Term-ANSIColor/t/module/basic256.t | 20 |
4 files changed, 109 insertions, 41 deletions
diff --git a/cpan/Term-ANSIColor/lib/Term/ANSIColor.pm b/cpan/Term-ANSIColor/lib/Term/ANSIColor.pm index 1a10edc6bf..730124b7f6 100644 --- a/cpan/Term-ANSIColor/lib/Term/ANSIColor.pm +++ b/cpan/Term-ANSIColor/lib/Term/ANSIColor.pm @@ -41,7 +41,7 @@ our $AUTOLOAD; # against circular module loading (not that we load any modules, but # consistency is good). BEGIN { - $VERSION = '4.05'; + $VERSION = '4.06'; # All of the basic supported constants, used in %EXPORT_TAGS. my @colorlist = qw( @@ -62,7 +62,7 @@ BEGIN { # 256-color constants, used in %EXPORT_TAGS. my @colorlist256 = ( - (map { ("ANSI$_", "ON_ANSI$_") } 0 .. 15), + (map { ("ANSI$_", "ON_ANSI$_") } 0 .. 255), (map { ("GREY$_", "ON_GREY$_") } 0 .. 23), ); for my $r (0 .. 5) { @@ -145,8 +145,8 @@ our %ATTRIBUTES = ( # Generating the 256-color codes involves a lot of codes and offsets that are # not helped by turning them into constants. -# The first 16 256-color codes are duplicates of the 16 ANSI colors, -# included for completeness. +# The first 16 256-color codes are duplicates of the 16 ANSI colors. The rest +# are RBG and greyscale values. for my $code (0 .. 15) { $ATTRIBUTES{"ansi$code"} = "38;5;$code"; $ATTRIBUTES{"on_ansi$code"} = "48;5;$code"; @@ -177,6 +177,15 @@ for my $attr (reverse sort keys %ATTRIBUTES) { $ATTRIBUTES_R{ $ATTRIBUTES{$attr} } = $attr; } +# Provide ansiN names for all 256 characters to provide a convenient flat +# namespace if one doesn't want to mess with the RGB and greyscale naming. Do +# this after creating %ATTRIBUTES_R since we want to use the canonical names +# when reversing a color. +for my $code (16 .. 255) { + $ATTRIBUTES{"ansi$code"} = "38;5;$code"; + $ATTRIBUTES{"on_ansi$code"} = "48;5;$code"; +} + # Import any custom colors set in the environment. our %ALIASES; if (exists $ENV{ANSI_COLORS_ALIASES}) { @@ -695,10 +704,12 @@ sixteen-color emulators but use the 256-color escape syntax, C<grey0> through C<grey23> ranging from nearly black to nearly white, and a set of RGB colors. The RGB colors are of the form C<rgbI<RGB>> where I<R>, I<G>, and I<B> are numbers from 0 to 5 giving the intensity of red, green, and -blue. C<on_> variants of all of these colors are also provided. These -colors may be ignored completely on non-256-color terminals or may be -misinterpreted and produce random behavior. Additional attributes such as -blink, italic, or bold may not work with the 256-color palette. +blue. The grey and RGB colors are also available as C<ansi16> through +C<ansi255> if you want simple names for all 256 colors. C<on_> variants +of all of these colors are also provided. These colors may be ignored +completely on non-256-color terminals or may be misinterpreted and produce +random behavior. Additional attributes such as blink, italic, or bold may +not work with the 256-color palette. There is unfortunately no way to know whether the current emulator supports more than eight colors, which makes the choice of colors @@ -744,13 +755,13 @@ The recognized bright background color attributes (colors 8 to 15) are: For 256-color terminals, the recognized foreground colors are: - ansi0 .. ansi15 + ansi0 .. ansi255 grey0 .. grey23 plus C<rgbI<RGB>> for I<R>, I<G>, and I<B> values from 0 to 5, such as C<rgb000> or C<rgb515>. Similarly, the recognized background colors are: - on_ansi0 .. on_ansi15 + on_ansi0 .. on_ansi255 on_grey0 .. on_grey23 plus C<on_rgbI<RGB>> for I<R>, I<G>, and I<B> values from 0 to 5. @@ -801,7 +812,9 @@ $Term::ANSIColor::EACHLINE to C<"\n"> to use this feature. uncolor() performs the opposite translation as color(), turning escape sequences into a list of strings corresponding to the attributes being set -by those sequences. +by those sequences. uncolor() will never return C<ansi16> through +C<ansi255>, instead preferring the C<grey> and C<rgb> names (and likewise +for C<on_ansi16> through C<on_ansi255>). =item colorstrip(STRING[, STRING ...]) @@ -875,12 +888,12 @@ described above since a background color is being used.) If you import C<:constants256>, you can use the following constants directly: - ANSI0 .. ANSI15 + ANSI0 .. ANSI255 GREY0 .. GREY23 RGBXYZ (for X, Y, and Z values from 0 to 5, like RGB000 or RGB515) - ON_ANSI0 .. ON_ANSI15 + ON_ANSI0 .. ON_ANSI255 ON_GREY0 .. ON_GREY23 ON_RGBXYZ (for X, Y, and Z values from 0 to 5) @@ -1122,6 +1135,10 @@ $Term::ANSIColor::AUTOLOCAL was changed to take precedence over $Term::ANSIColor::AUTORESET, rather than the other way around, in Term::ANSIColor 4.00, included in Perl 5.17.8. +C<ansi16> through C<ansi255>, as aliases for the C<rgb> and C<grey> +colors, and the corresponding C<on_ansi> names and C<ANSI> and C<ON_ANSI> +constants, were added in Term::ANSIColor 4.06. + =head1 RESTRICTIONS It would be nice if one could leave off the commas around the constants @@ -1233,6 +1250,8 @@ The CPAN module L<Term::ExtendedColor> provides a different and more comprehensive interface for 256-color emulators that may be more convenient. The CPAN module L<Win32::Console::ANSI> provides ANSI color (and other escape sequence) support in the Win32 Console environment. +The CPAN module L<Term::Chrome> provides a different interface using +objects and operator overloading. ECMA-048 is available on-line (at least at the time of this writing) at L<http://www.ecma-international.org/publications/standards/Ecma-048.htm>. @@ -1247,7 +1266,7 @@ L<http://invisible-island.net/xterm/ctlseqs/ctlseqs.html> (search for 256-color). The current version of this module is always available from its web site -at L<http://www.eyrie.org/~eagle/software/ansicolor/>. It is also part of -the Perl core distribution as of 5.6.0. +at L<https://www.eyrie.org/~eagle/software/ansicolor/>. It is also part +of the Perl core distribution as of 5.6.0. =cut diff --git a/cpan/Term-ANSIColor/t/lib/Test/RRA.pm b/cpan/Term-ANSIColor/t/lib/Test/RRA.pm index 5ac6eb8d78..bcd653240f 100644 --- a/cpan/Term-ANSIColor/t/lib/Test/RRA.pm +++ b/cpan/Term-ANSIColor/t/lib/Test/RRA.pm @@ -13,6 +13,7 @@ use strict; use warnings; use Exporter; +use File::Temp; use Test::More; # For Perl 5.006 compatibility. @@ -26,12 +27,56 @@ our (@EXPORT_OK, @ISA, $VERSION); # consistency is good). BEGIN { @ISA = qw(Exporter); - @EXPORT_OK = qw(skip_unless_author skip_unless_automated use_prereq); + @EXPORT_OK = qw( + is_file_contents skip_unless_author skip_unless_automated use_prereq + ); # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '5.11'; + $VERSION = '6.02'; +} + +# Compare a string to the contents of a file, similar to the standard is() +# function, but to show the line-based unified diff between them if they +# differ. +# +# $got - The output that we received +# $expected - The path to the file containing the expected output +# $message - The message to use when reporting the test results +# +# Returns: undef +# Throws: Exception on failure to read or write files or run diff +sub is_file_contents { + my ($got, $expected, $message) = @_; + + # If they're equal, this is simple. + open(my $fh, '<', $expected) or BAIL_OUT("Cannot open $expected: $!\n"); + my $data = do { local $/ = undef; <$fh> }; + close($fh) or BAIL_OUT("Cannot close $expected: $!\n"); + if ($got eq $data) { + is($got, $data, $message); + return; + } + + # Otherwise, we show a diff, but only if we have IPC::System::Simple. + eval { require IPC::System::Simple }; + if ($@) { + ok(0, $message); + return; + } + + # They're not equal. Write out what we got so that we can run diff. + my $tmp = File::Temp->new(); + my $tmpname = $tmp->filename; + print {$tmp} $got or BAIL_OUT("Cannot write to $tmpname: $!\n"); + my @command = ('diff', '-u', $expected, $tmpname); + my $diff = IPC::System::Simple::capturex([0 .. 1], @command); + diag($diff); + + # Remove the temporary file and report failure. + ok(0, $message); + return; } # Skip this test unless author tests are requested. Takes a short description @@ -225,7 +270,7 @@ SOFTWARE. Test::More(3), Test::RRA::Automake(3), Test::RRA::Config(3) This module is maintained in the rra-c-util package. The current version is -available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>. +available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>. The functions to control when tests are run use environment variables defined by the L<Lancaster diff --git a/cpan/Term-ANSIColor/t/lib/Test/RRA/Config.pm b/cpan/Term-ANSIColor/t/lib/Test/RRA/Config.pm index 311032471b..bdb31e60c0 100644 --- a/cpan/Term-ANSIColor/t/lib/Test/RRA/Config.pm +++ b/cpan/Term-ANSIColor/t/lib/Test/RRA/Config.pm @@ -34,16 +34,16 @@ BEGIN { # This version should match the corresponding rra-c-util release, but with # two digits for the minor version, including a leading zero if necessary, # so that it will sort properly. - $VERSION = '5.11'; + $VERSION = '6.02'; } -# If BUILD or SOURCE are set in the environment, look for data/perl.conf under -# those paths for a C Automake package. Otherwise, look in t/data/perl.conf -# for a standalone Perl module or tests/data/perl.conf for Perl tests embedded -# in a larger distribution. Don't use Test::RRA::Automake since it may not -# exist. +# If C_TAP_BUILD or C_TAP_SOURCE are set in the environment, look for +# data/perl.conf under those paths for a C Automake package. Otherwise, look +# in t/data/perl.conf for a standalone Perl module or tests/data/perl.conf for +# Perl tests embedded in a larger distribution. Don't use Test::RRA::Automake +# since it may not exist. our $PATH; -for my $base ($ENV{BUILD}, $ENV{SOURCE}, 't', 'tests') { +for my $base ($ENV{C_TAP_BUILD}, $ENV{C_TAP_SOURCE}, './t', './tests') { next if !defined($base); my $path = "$base/data/perl.conf"; if (-r $path) { @@ -70,7 +70,7 @@ our @STRICT_PREREQ; # Load the configuration. if (!do($PATH)) { my $error = $@ || $! || 'loading file did not return true'; - BAIL_OUT("cannot load data/perl.conf: $error"); + BAIL_OUT("cannot load $PATH: $error"); } 1; @@ -98,10 +98,10 @@ for both C Automake packages and stand-alone Perl modules. Test::RRA::Config looks for a file named F<data/perl.conf> relative to the root of the test directory. That root is taken from the environment variables -BUILD or SOURCE (in that order) if set, which will be the case for C Automake -packages using C TAP Harness. If neither is set, it expects the root of the -test directory to be a directory named F<t> relative to the current directory, -which will be the case for stand-alone Perl modules. +C_TAP_BUILD or C_TAP_SOURCE (in that order) if set, which will be the case for +C Automake packages using C TAP Harness. If neither is set, it expects the +root of the test directory to be a directory named F<t> relative to the +current directory, which will be the case for stand-alone Perl modules. The following variables are supported: @@ -185,6 +185,8 @@ Russ Allbery <eagle@eyrie.org> =head1 COPYRIGHT AND LICENSE +Copyright 2015, 2016 Russ Allbery <eagle@eyrie.org> + Copyright 2013, 2014 The Board of Trustees of the Leland Stanford Junior University @@ -212,9 +214,9 @@ perlcritic(1), Test::MinimumVersion(3), Test::RRA(3), Test::RRA::Automake(3), Test::Strict(3) This module is maintained in the rra-c-util package. The current version is -available from L<http://www.eyrie.org/~eagle/software/rra-c-util/>. +available from L<https://www.eyrie.org/~eagle/software/rra-c-util/>. The C TAP Harness test driver and libraries for TAP-based C testing are -available from L<http://www.eyrie.org/~eagle/software/c-tap-harness/>. +available from L<https://www.eyrie.org/~eagle/software/c-tap-harness/>. =cut diff --git a/cpan/Term-ANSIColor/t/module/basic256.t b/cpan/Term-ANSIColor/t/module/basic256.t index a24b0cef37..ae06d1ada5 100644 --- a/cpan/Term-ANSIColor/t/module/basic256.t +++ b/cpan/Term-ANSIColor/t/module/basic256.t @@ -3,7 +3,7 @@ # Tests for 256-color support. # # Copyright 2012 Kurt Starsinic <kstarsinic@gmail.com> -# Copyright 2012, 2013 Russ Allbery <rra@cpan.org> +# Copyright 2012, 2013, 2016 Russ Allbery <rra@cpan.org> # # This program is free software; you may redistribute it and/or modify it # under the same terms as Perl itself. @@ -11,7 +11,7 @@ use strict; use warnings; -use Test::More tests => 92; +use Test::More tests => 94; # Load the module. BEGIN { @@ -29,7 +29,7 @@ is(color('grey0'), "\e[38;5;232m", 'Grey 0'); is(color('grey23'), "\e[38;5;255m", 'Grey 23'); # Errors at boundary cases. -for my $color (qw(ansi16 rgb600 rgb060 rgb006 rgb666 rgb999 rgb0000 grey24)) { +for my $color (qw(ansi256 rgb600 rgb060 rgb006 rgb666 rgb999 rgb0000 grey24)) { my $output = eval { color($color) }; is($output, undef, 'color on unknown color name fails'); like( @@ -49,6 +49,7 @@ for my $color (qw(ansi0 ansi15 rgb000 rgb555 grey0 grey23)) { is_deeply([uncolor('38;5;0')], ['ansi0'], 'uncolor of ansi0'); is_deeply([uncolor("\e[38;5;231m")], ['rgb555'], 'uncolor of rgb555'); is_deeply([uncolor("\e[48;05;001m")], ['on_ansi1'], 'uncolor with leading 0s'); +is_deeply([uncolor("\e[38;5;233")], ['grey1'], 'uncolor of grey1'); # An invalid 256-color code should report an error on the part that makes it # invalid. Check truncated codes (should report on the 38 or 48), codes with @@ -79,12 +80,13 @@ while (my ($escape, $invalid) = each %uncolor_tests) { } # Test all the variations of a few different constants. -is((ANSI0 't'), "\e[38;5;0mt", 'Basic constant works for ANSI0'); -is((ANSI15 't'), "\e[38;5;15mt", '...and for ANSI15'); -is((RGB000 't'), "\e[38;5;16mt", '...and for RGB000'); -is((RGB555 't'), "\e[38;5;231mt", '...and for RGB555'); -is((GREY0 't'), "\e[38;5;232mt", '...and for GREY0'); -is((GREY23 't'), "\e[38;5;255mt", '...and for GREY23'); +is((ANSI0 't'), "\e[38;5;0mt", 'Basic constant works for ANSI0'); +is((ANSI15 't'), "\e[38;5;15mt", '...and for ANSI15'); +is((ANSI255 't'), "\e[38;5;255mt", '...and for ANSI255'); +is((RGB000 't'), "\e[38;5;16mt", '...and for RGB000'); +is((RGB555 't'), "\e[38;5;231mt", '...and for RGB555'); +is((GREY0 't'), "\e[38;5;232mt", '...and for GREY0'); +is((GREY23 't'), "\e[38;5;255mt", '...and for GREY23'); # Do the same for disabled colors. local $ENV{ANSI_COLORS_DISABLED} = 1; |