},
'Term::ANSIColor' => {
- 'DISTRIBUTION' => 'RRA/Term-ANSIColor-5.00.tar.gz',
+ 'DISTRIBUTION' => 'RRA/Term-ANSIColor-5.01.tar.gz',
'FILES' => q[cpan/Term-ANSIColor],
'EXCLUDED' => [
qr{^docs/},
# against circular module loading (not that we load any modules, but
# consistency is good).
BEGIN {
- $VERSION = '5.00';
+ $VERSION = '5.01';
# All of the basic supported constants, used in %EXPORT_TAGS.
my @colorlist = qw(
# called sub against the list of attributes, and if it's an all-caps version
# of one of them, we define the sub on the fly and then run it.
#
-# If the environment variable ANSI_COLORS_DISABLED is set to a true value,
-# just return the arguments without adding any escape sequences. This is to
-# make it easier to write scripts that also work on systems without any ANSI
-# support, like Windows consoles.
+# If the environment variable ANSI_COLORS_DISABLED is set to a true value, or
+# if the variable NO_COLOR is set, just return the arguments without adding
+# any escape sequences. This is to make it easier to write scripts that also
+# work on systems without any ANSI support, like Windows consoles.
#
# Avoid using character classes like [:upper:] and \w here, since they load
# Unicode character tables and consume a ton of memory. All of our constants
# If colors are disabled, just return the input. Do this without
# installing a sub for (marginal, unbenchmarked) speed.
- if ($ENV{ANSI_COLORS_DISABLED}) {
+ if ($ENV{ANSI_COLORS_DISABLED} || defined($ENV{NO_COLOR})) {
return join(q{}, @_);
}
## no critic (ValuesAndExpressions::ProhibitImplicitNewlines)
my $eval_result = eval qq{
sub $AUTOLOAD {
- if (\$ENV{ANSI_COLORS_DISABLED}) {
+ if (\$ENV{ANSI_COLORS_DISABLED} || defined(\$ENV{NO_COLOR})) {
return join(q{}, \@_);
} elsif (\$AUTOLOCAL && \@_) {
return PUSHCOLOR('$escape') . join(q{}, \@_) . POPCOLOR;
my (@codes) = @_;
# Return the empty string if colors are disabled.
- if ($ENV{ANSI_COLORS_DISABLED}) {
+ if ($ENV{ANSI_COLORS_DISABLED} || defined($ENV{NO_COLOR})) {
return q{};
}
}
# Return the string unmolested if colors are disabled.
- if ($ENV{ANSI_COLORS_DISABLED}) {
+ if ($ENV{ANSI_COLORS_DISABLED} || defined($ENV{NO_COLOR})) {
return $string;
}
# Map escape sequences back to color names.
use Term::ANSIColor 1.04 qw(uncolor);
- my $names = uncolor('01;31');
- print join(q{ }, @{$names}), "\n";
+ my @names = uncolor('01;31');
+ print join(q{ }, @names), "\n";
# Strip all color escape sequences.
use Term::ANSIColor 2.01 qw(colorstrip);
256-color RGB colors. Only ASCII alphanumerics, C<.>, C<_>, and C<-> are
allowed in alias names.
+If ATTR includes aliases, those aliases will be expanded at definition time
+and their values will be used to define the new alias. This means that if you
+define an alias A in terms of another alias B, and then later redefine alias
+B, the value of alias A will not change.
+
If ATTR is not specified, coloralias() returns the standard attribute or
attributes to which ALIAS is aliased, if any, or undef if ALIAS does not
exist. If it is aliased to multiple attributes, the return value will be a
=item ANSI_COLORS_DISABLED
If this environment variable is set to a true value, all of the functions
-defined by this module (color(), colored(), and all of the constants not
-previously used in the program) will not output any escape sequences and
-instead will just return the empty string or pass through the original
-text as appropriate. This is intended to support easy use of scripts
-using this module on platforms that don't support ANSI escape sequences.
+defined by this module (color(), colored(), and all of the constants) will not
+output any escape sequences and instead will just return the empty string or
+pass through the original text as appropriate. This is intended to support
+easy use of scripts using this module on platforms that don't support ANSI
+escape sequences.
+
+=item NO_COLOR
+
+If this environment variable is set to any value, it suppresses generation of
+escape sequences the same as if ANSI_COLORS_DISABLED is set to a true value.
+This implements the L<https://no-color.org/> informal standard. Programs that
+want to enable color despite NO_COLOR being set will need to unset that
+environment variable before any constant or function provided by this module
+is used.
=back
to multiple attributes instead of only a single attribute was added in
Term::ANSIColor 5.00.
+Support for NO_COLOR was added in Term::ANSIColor 5.01.
+
=head1 RESTRICTIONS
Both colored() and many uses of the color constants will add the reset escape
programs you can run to check the true color support in your terminal emulator
are available at L<https://gist.github.com/XVilka/8346728>.
+L<CLICOLORS|https://bixense.com/clicolors/> and
+L<NO_COLOR|https://no-color.org/> are useful standards to be aware of, and
+ideally follow, for any application using color. Term::ANSIColor complies
+with the latter.
+
The current version of this module is always available from its web site
at L<https://www.eyrie.org/~eagle/software/ansicolor/>. It is also part
of the Perl core distribution as of 5.6.0.
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(color colored colorvalid uncolor coloralias));
}
use strict;
use warnings;
-use Test::More tests => 152;
+use Test::More tests => 169;
# Load the module.
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor',
qw(:pushpop color colored uncolor colorstrip colorvalid));
}
is((BOLD), "\e[1m", '...likewise for constants');
delete $ENV{ANSI_COLORS_DISABLED};
+# Similar tests for NO_COLOR, although NO_COLOR may be set to any value.
+local $ENV{NO_COLOR} = 1;
+is(color('blue'), q{}, 'color support for NO_COLOR');
+is(colored('testing', 'blue', 'on_red'),
+ 'testing', 'colored support for NO_COLOR');
+is((BLUE 'testing'), 'testing', 'Constant support for NO_COLOR');
+local $ENV{NO_COLOR} = q{};
+is(color('blue'), q{}, 'color support for NO_COLOR with empty string');
+is((RED 'testing'),
+ 'testing', 'Constant support for NO_COLOR with empty string');
+delete $ENV{NO_COLOR};
+
# Make sure DARK is exported. This was omitted in versions prior to 1.07.
is((DARK 'testing'), "\e[2mtesting", 'DARK');
is(RESET, q{}, '...and for RESET');
delete $ENV{ANSI_COLORS_DISABLED};
+# Do the same for disabled colors with NO_COLOR.
+local $ENV{NO_COLOR} = 1;
+is(BOLD, q{}, 'NO_COLOR works for BOLD');
+is(BLUE, q{}, '...and for BLUE');
+is(GREEN, q{}, '...and for GREEN');
+is(DARK, q{}, '...and for DARK');
+is(FAINT, q{}, '...and for FAINT');
+is(BRIGHT_RED, q{}, '...and for BRIGHT_RED');
+is(ON_BRIGHT_RED, q{}, '...and for ON_BRIGHT_RED');
+is(ITALIC, q{}, '...and for ITALIC');
+is(RED, q{}, '...and for RED');
+is(ON_GREEN, q{}, '...and for ON_GREEN');
+is(ON_BLUE, q{}, '...and for ON_BLUE');
+is(RESET, q{}, '...and for RESET');
+delete $ENV{NO_COLOR};
+
# Do the same for AUTORESET.
$Term::ANSIColor::AUTORESET = 1;
is((BOLD 't'), "\e[1mt\e[0m", 'AUTORESET works for BOLD');
use strict;
use warnings;
-use Test::More tests => 94;
+use Test::More tests => 100;
# Load the module.
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(:constants256 color uncolor colorvalid));
}
is(GREY23, q{}, '...and for GREY23');
delete $ENV{ANSI_COLORS_DISABLED};
+# Do the same with NO_COLOR.
+local $ENV{NO_COLOR} = 0;
+is(ANSI0, q{}, 'NO_COLOR works for ANSI0');
+is(ANSI15, q{}, '...and for ANSI15');
+is(RGB000, q{}, '...and for RGB000');
+is(RGB555, q{}, '...and for RGB555');
+is(GREY0, q{}, '...and for GREY0');
+is(GREY23, q{}, '...and for GREY23');
+delete $ENV{NO_COLOR};
+
# Do the same for AUTORESET.
$Term::ANSIColor::AUTORESET = 1;
is((ANSI0 't'), "\e[38;5;0mt\e[0m", 'AUTORESET works for ANSI0');
use strict;
use warnings;
-use Test::More tests => 15;
+use Test::More tests => 17;
# We refer to $@ in the test descriptions.
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(:constants));
}
is(BLINK, q{}, '...and for BLINK');
delete $ENV{ANSI_COLORS_DISABLED};
+# Now, NO_COLOR.
+local $ENV{NO_COLOR} = 'foo';
+is(BOLD, q{}, 'NO_COLOR works for BOLD');
+is(BLINK, q{}, '...and for BLINK');
+delete $ENV{NO_COLOR};
+
# Now, AUTORESET.
$Term::ANSIColor::AUTORESET = 1;
is((BOLD 't'), "\e[1mt\e[0m", 'AUTORESET works for BOLD');
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(colored));
}
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(color uncolor colorvalid));
}
BEGIN {
delete $ENV{ANSI_COLORS_ALIASES};
delete $ENV{ANSI_COLORS_DISABLED};
+ delete $ENV{NO_COLOR};
use_ok('Term::ANSIColor', qw(:pushpop));
}