From: Steffen Mueller Date: Mon, 31 Aug 2009 13:02:46 +0000 (+0200) Subject: Upgrade Term::ANSIColor to 2.02 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cdab9eb9f4a609665cca826dbf612dd2fc05a19b;p=p5sagit%2Fp5-mst-13.2.git Upgrade Term::ANSIColor to 2.02 --- diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index f50c985..a2f5bcc 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -1620,7 +1620,7 @@ package Maintainers; 'Term::ANSIColor' => { 'MAINTAINER' => 'rra', - 'DISTRIBUTION' => 'RRA/ANSIColor-2.01.tar.gz', + 'DISTRIBUTION' => 'RRA/ANSIColor-2.02.tar.gz', 'FILES' => q{ext/Term-ANSIColor}, 'EXCLUDED' => [ qr{^tests/}, qw(t/pod-spelling.t t/pod.t) ], 'CPAN' => 1, diff --git a/ext/Term-ANSIColor/ANSIColor.pm b/ext/Term-ANSIColor/ANSIColor.pm index d640908..1ee7a1e 100644 --- a/ext/Term-ANSIColor/ANSIColor.pm +++ b/ext/Term-ANSIColor/ANSIColor.pm @@ -17,7 +17,7 @@ package Term::ANSIColor; require 5.001; -$VERSION = '2.01'; +$VERSION = '2.02'; use strict; use vars qw($AUTOLOAD $AUTOLOCAL $AUTORESET @COLORLIST @COLORSTACK $EACHLINE @@ -26,13 +26,13 @@ use vars qw($AUTOLOAD $AUTOLOCAL $AUTORESET @COLORLIST @COLORSTACK $EACHLINE use Exporter (); BEGIN { - @COLORLIST = qw(CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE - CONCEALED BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE - ON_BLACK ON_RED ON_GREEN ON_YELLOW ON_BLUE ON_MAGENTA - ON_CYAN ON_WHITE); + @COLORLIST = qw(CLEAR RESET BOLD DARK FAINT UNDERLINE UNDERSCORE BLINK + REVERSE CONCEALED BLACK RED GREEN YELLOW BLUE MAGENTA + CYAN WHITE ON_BLACK ON_RED ON_GREEN ON_YELLOW ON_BLUE + ON_MAGENTA ON_CYAN ON_WHITE); @ISA = qw(Exporter); @EXPORT = qw(color colored); - @EXPORT_OK = qw(uncolor colorstrip); + @EXPORT_OK = qw(uncolor colorstrip colorvalid); %EXPORT_TAGS = (constants => \@COLORLIST, pushpop => [ @COLORLIST, qw(PUSHCOLOR POPCOLOR LOCALCOLOR) ]); @@ -235,6 +235,18 @@ sub colorstrip { return wantarray ? @string : join ('', @string); } +# Given a list of color attributes (arguments for color, for instance), return +# true if they're all valid or false if any of them are invalid. +sub colorvalid { + my @codes = map { split } @_; + for (@codes) { + unless (defined $ATTRIBUTES{lc $_}) { + return; + } + } + return 1; +} + ############################################################################## # Module return value and documentation ############################################################################## @@ -270,6 +282,10 @@ reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com use Term::ANSIColor qw(colorstrip); print colorstrip '\e[1mThis is bold\e[0m', "\n"; + use Term::ANSIColor qw(colorvalid); + my $valid = colorvalid ('blue bold', 'on_magenta'); + print "Color string is ", $valid ? "valid\n" : "invalid\n"; + use Term::ANSIColor qw(:constants); print BOLD, BLUE, "This text is in bold blue.\n", RESET; @@ -297,9 +313,9 @@ reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com =head1 DESCRIPTION This module has two interfaces, one through color() and colored() and the -other through constants. It also offers the utility functions uncolor() -and colorstrip(), which have to be explicitly imported to be used (see -L). +other through constants. It also offers the utility functions uncolor(), +colorstrip(), and colorvalid(), which have to be explicitly imported to be +used (see L). =head2 Function Interface @@ -308,7 +324,9 @@ space-separated lists of attributes. It then forms and returns the escape sequence to set those attributes. It doesn't print it out, just returns it, so you'll have to print it yourself if you want to (this is so that you can save it as a string, pass it to something else, send it to a file -handle, or do anything else with it that you might care to). +handle, or do anything else with it that you might care to). color() +throws an exception if given an invalid attribute, so you can also use it +to check attribute names for validity (see L). uncolor() performs the opposite translation, turning escape sequences into a list of strings. @@ -317,6 +335,9 @@ colorstrip() removes all color escape sequences from the provided strings, returning the modified strings separately in array context or joined together in scalar context. Its arguments are not modified. +colorvalid() takes attribute strings the same as color() and returns true +if all attributes are known and false otherwise. + The recognized non-color attributes are clear, reset, bold, dark, faint, underline, underscore, blink, reverse, and concealed. Clear and reset (reset to default attributes), dark and faint (dim and saturated), and @@ -357,11 +378,11 @@ $Term::ANSIColor::EACHLINE to C<"\n"> to use this feature. =head2 Constant Interface Alternately, if you import C<:constants>, you can use the constants CLEAR, -RESET, BOLD, DARK, UNDERLINE, UNDERSCORE, BLINK, REVERSE, CONCEALED, -BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, ON_BLACK, ON_RED, -ON_GREEN, ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and ON_WHITE directly. -These are the same as color('attribute') and can be used if you prefer -typing: +RESET, BOLD, DARK, FAINT, UNDERLINE, UNDERSCORE, BLINK, REVERSE, +CONCEALED, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, +ON_BLACK, ON_RED, ON_GREEN, ON_YELLOW, ON_BLUE, ON_MAGENTA, ON_CYAN, and +ON_WHITE directly. These are the same as color('attribute') and can be +used if you prefer typing: print BOLD BLUE ON_WHITE "Text", RESET, "\n"; @@ -529,7 +550,7 @@ helped me flesh it out: clear bold faint under blink reverse conceal ------------------------------------------------------------------------ - xterm yes yes no yes bold yes yes + xterm yes yes no yes yes yes yes linux yes yes yes bold yes yes no rxvt yes yes no yes bold/black yes no dtterm yes yes yes yes reverse yes yes diff --git a/ext/Term-ANSIColor/ChangeLog b/ext/Term-ANSIColor/ChangeLog index 47e2c1f..9888ad1 100644 --- a/ext/Term-ANSIColor/ChangeLog +++ b/ext/Term-ANSIColor/ChangeLog @@ -1,5 +1,23 @@ +2009-08-30 Russ Allbery + + * ANSIColor.pm: Version 2.02 released. + + * ANSIColor.pm: Update compatibility matrix to reflect that xterm + now supports blink. + + * ANSIColor.pm (colorvalid): New function to check whether an + attribute is known. + * t/basic.t: Test colorvalid. + 2009-07-04 Russ Allbery + * ANSIColor.pm: Add an example of checking color attributes by + catching exceptions from color() to the documentation. + + * ANSIColor.pm: Add FAINT as a synonym for DARK and export it when + constants are requested. + * t/basic.t: Test faint and FAINT as a synonym for dark/DARK. + * ANSIColor.pm: Version 2.01 released. * t/basic.t: Test error handling in color, colored, and uncolor. diff --git a/ext/Term-ANSIColor/README b/ext/Term-ANSIColor/README index 834a43f..94391c0 100644 --- a/ext/Term-ANSIColor/README +++ b/ext/Term-ANSIColor/README @@ -1,4 +1,4 @@ - Term::ANSIColor version 2.01 + Term::ANSIColor version 2.02 (A simple ANSI text attribute control module) Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2007, 2009 diff --git a/ext/Term-ANSIColor/t/basic.t b/ext/Term-ANSIColor/t/basic.t index fe01a1d..748cdcc 100644 --- a/ext/Term-ANSIColor/t/basic.t +++ b/ext/Term-ANSIColor/t/basic.t @@ -9,11 +9,12 @@ # under the same terms as Perl itself. use strict; -use Test::More tests => 43; +use Test::More tests => 47; BEGIN { delete $ENV{ANSI_COLORS_DISABLED}; - use_ok ('Term::ANSIColor', qw/:pushpop color colored uncolor colorstrip/); + use_ok ('Term::ANSIColor', + qw/:pushpop color colored uncolor colorstrip colorvalid/); } # Various basic tests. @@ -47,6 +48,10 @@ delete $ENV{ANSI_COLORS_DISABLED}; # Make sure DARK is exported. This was omitted in versions prior to 1.07. is ((DARK "testing"), "\e[2mtesting\e[0m", 'DARK'); +# Check faint as a synonym for dark. +is (colored ('test', 'faint'), "\e[2mtest\e[0m", 'colored supports faint'); +is ((FAINT "test"), "\e[2mtest\e[0m", '...and the FAINT constant works'); + # Test colored with 0 and EACHLINE. $Term::ANSIColor::EACHLINE = "\n"; is (colored ('0', 'blue', 'bold'), "\e[34;1m0\e[0m", @@ -96,6 +101,12 @@ is (colorstrip ("\e[2cSome other code\e and stray [0m stuff"), "\e[2cSome other code\e and stray [0m stuff", 'colorstrip does not remove non-color stuff'); +# Test colorvalid. +is (colorvalid ("blue bold dark", "blink on_green"), 1, + 'colorvalid returns true for valid attributes'); +is (colorvalid ("green orange"), undef, + '...and false for invalid attributes'); + # Test error handling. my $output = eval { color 'chartreuse' }; is ($output, undef, 'color on unknown color name fails');