|
Packit Service |
d987f3 |
# Color screen output using ANSI escape sequences.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009, 2010,
|
|
Packit Service |
d987f3 |
# 2011, 2012, 2013, 2014, 2015, 2016 Russ Allbery <rra@cpan.org>
|
|
Packit Service |
d987f3 |
# Copyright 1996 Zenin
|
|
Packit Service |
d987f3 |
# Copyright 2012 Kurt Starsinic <kstarsinic@gmail.com>
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# This program is free software; you may redistribute it and/or modify it
|
|
Packit Service |
d987f3 |
# under the same terms as Perl itself.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# PUSH/POP support submitted 2007 by openmethods.com voice solutions
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Ah, September, when the sysadmins turn colors and fall off the trees....
|
|
Packit Service |
d987f3 |
# -- Dave Van Domelen
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Modules and declarations
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
package Term::ANSIColor;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use 5.006;
|
|
Packit Service |
d987f3 |
use strict;
|
|
Packit Service |
d987f3 |
use warnings;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Also uses Carp but loads it on demand to reduce memory usage.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Exporter ();
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# use Exporter plus @ISA instead of use base for 5.6 compatibility.
|
|
Packit Service |
d987f3 |
## no critic (ClassHierarchies::ProhibitExplicitISA)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Declare variables that should be set in BEGIN for robustness.
|
|
Packit Service |
d987f3 |
## no critic (Modules::ProhibitAutomaticExportation)
|
|
Packit Service |
d987f3 |
our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS, @ISA, $VERSION);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# We use autoloading, which sets this variable to the name of the called sub.
|
|
Packit Service |
d987f3 |
our $AUTOLOAD;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Set $VERSION and everything export-related in a BEGIN block for robustness
|
|
Packit Service |
d987f3 |
# against circular module loading (not that we load any modules, but
|
|
Packit Service |
d987f3 |
# consistency is good).
|
|
Packit Service |
d987f3 |
BEGIN {
|
|
Packit Service |
d987f3 |
$VERSION = '4.06';
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# All of the basic supported constants, used in %EXPORT_TAGS.
|
|
Packit Service |
d987f3 |
my @colorlist = qw(
|
|
Packit Service |
d987f3 |
CLEAR RESET BOLD DARK
|
|
Packit Service |
d987f3 |
FAINT ITALIC UNDERLINE UNDERSCORE
|
|
Packit Service |
d987f3 |
BLINK REVERSE CONCEALED
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
BLACK RED GREEN YELLOW
|
|
Packit Service |
d987f3 |
BLUE MAGENTA CYAN WHITE
|
|
Packit Service |
d987f3 |
ON_BLACK ON_RED ON_GREEN ON_YELLOW
|
|
Packit Service |
d987f3 |
ON_BLUE ON_MAGENTA ON_CYAN ON_WHITE
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
BRIGHT_BLACK BRIGHT_RED BRIGHT_GREEN BRIGHT_YELLOW
|
|
Packit Service |
d987f3 |
BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE
|
|
Packit Service |
d987f3 |
ON_BRIGHT_BLACK ON_BRIGHT_RED ON_BRIGHT_GREEN ON_BRIGHT_YELLOW
|
|
Packit Service |
d987f3 |
ON_BRIGHT_BLUE ON_BRIGHT_MAGENTA ON_BRIGHT_CYAN ON_BRIGHT_WHITE
|
|
Packit Service |
d987f3 |
);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# 256-color constants, used in %EXPORT_TAGS.
|
|
Packit Service |
d987f3 |
my @colorlist256 = (
|
|
Packit Service |
d987f3 |
(map { ("ANSI$_", "ON_ANSI$_") } 0 .. 255),
|
|
Packit Service |
d987f3 |
(map { ("GREY$_", "ON_GREY$_") } 0 .. 23),
|
|
Packit Service |
d987f3 |
);
|
|
Packit Service |
d987f3 |
for my $r (0 .. 5) {
|
|
Packit Service |
d987f3 |
for my $g (0 .. 5) {
|
|
Packit Service |
d987f3 |
push(@colorlist256, map { ("RGB$r$g$_", "ON_RGB$r$g$_") } 0 .. 5);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Exported symbol configuration.
|
|
Packit Service |
d987f3 |
@ISA = qw(Exporter);
|
|
Packit Service |
d987f3 |
@EXPORT = qw(color colored);
|
|
Packit Service |
d987f3 |
@EXPORT_OK = qw(uncolor colorstrip colorvalid coloralias);
|
|
Packit Service |
d987f3 |
%EXPORT_TAGS = (
|
|
Packit Service |
d987f3 |
constants => \@colorlist,
|
|
Packit Service |
d987f3 |
constants256 => \@colorlist256,
|
|
Packit Service |
d987f3 |
pushpop => [@colorlist, qw(PUSHCOLOR POPCOLOR LOCALCOLOR)],
|
|
Packit Service |
d987f3 |
);
|
|
Packit Service |
d987f3 |
Exporter::export_ok_tags('pushpop', 'constants256');
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Package variables
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# If this is set, any color changes will implicitly push the current color
|
|
Packit Service |
d987f3 |
# onto the stack and then pop it at the end of the constant sequence, just as
|
|
Packit Service |
d987f3 |
# if LOCALCOLOR were used.
|
|
Packit Service |
d987f3 |
our $AUTOLOCAL;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Caller sets this to force a reset at the end of each constant sequence.
|
|
Packit Service |
d987f3 |
our $AUTORESET;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Caller sets this to force colors to be reset at the end of each line.
|
|
Packit Service |
d987f3 |
our $EACHLINE;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Internal data structures
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# This module does quite a bit of initialization at the time it is first
|
|
Packit Service |
d987f3 |
# loaded, primarily to set up the package-global %ATTRIBUTES hash. The
|
|
Packit Service |
d987f3 |
# entries for 256-color names are easier to handle programmatically, and
|
|
Packit Service |
d987f3 |
# custom colors are also imported from the environment if any are set.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# All basic supported attributes, including aliases.
|
|
Packit Service |
d987f3 |
#<<<
|
|
Packit Service |
d987f3 |
our %ATTRIBUTES = (
|
|
Packit Service |
d987f3 |
'clear' => 0,
|
|
Packit Service |
d987f3 |
'reset' => 0,
|
|
Packit Service |
d987f3 |
'bold' => 1,
|
|
Packit Service |
d987f3 |
'dark' => 2,
|
|
Packit Service |
d987f3 |
'faint' => 2,
|
|
Packit Service |
d987f3 |
'italic' => 3,
|
|
Packit Service |
d987f3 |
'underline' => 4,
|
|
Packit Service |
d987f3 |
'underscore' => 4,
|
|
Packit Service |
d987f3 |
'blink' => 5,
|
|
Packit Service |
d987f3 |
'reverse' => 7,
|
|
Packit Service |
d987f3 |
'concealed' => 8,
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
'black' => 30, 'on_black' => 40,
|
|
Packit Service |
d987f3 |
'red' => 31, 'on_red' => 41,
|
|
Packit Service |
d987f3 |
'green' => 32, 'on_green' => 42,
|
|
Packit Service |
d987f3 |
'yellow' => 33, 'on_yellow' => 43,
|
|
Packit Service |
d987f3 |
'blue' => 34, 'on_blue' => 44,
|
|
Packit Service |
d987f3 |
'magenta' => 35, 'on_magenta' => 45,
|
|
Packit Service |
d987f3 |
'cyan' => 36, 'on_cyan' => 46,
|
|
Packit Service |
d987f3 |
'white' => 37, 'on_white' => 47,
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
'bright_black' => 90, 'on_bright_black' => 100,
|
|
Packit Service |
d987f3 |
'bright_red' => 91, 'on_bright_red' => 101,
|
|
Packit Service |
d987f3 |
'bright_green' => 92, 'on_bright_green' => 102,
|
|
Packit Service |
d987f3 |
'bright_yellow' => 93, 'on_bright_yellow' => 103,
|
|
Packit Service |
d987f3 |
'bright_blue' => 94, 'on_bright_blue' => 104,
|
|
Packit Service |
d987f3 |
'bright_magenta' => 95, 'on_bright_magenta' => 105,
|
|
Packit Service |
d987f3 |
'bright_cyan' => 96, 'on_bright_cyan' => 106,
|
|
Packit Service |
d987f3 |
'bright_white' => 97, 'on_bright_white' => 107,
|
|
Packit Service |
d987f3 |
);
|
|
Packit Service |
d987f3 |
#>>>
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Generating the 256-color codes involves a lot of codes and offsets that are
|
|
Packit Service |
d987f3 |
# not helped by turning them into constants.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# The first 16 256-color codes are duplicates of the 16 ANSI colors. The rest
|
|
Packit Service |
d987f3 |
# are RBG and greyscale values.
|
|
Packit Service |
d987f3 |
for my $code (0 .. 15) {
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"ansi$code"} = "38;5;$code";
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"on_ansi$code"} = "48;5;$code";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# 256-color RGB colors. Red, green, and blue can each be values 0 through 5,
|
|
Packit Service |
d987f3 |
# and the resulting 216 colors start with color 16.
|
|
Packit Service |
d987f3 |
for my $r (0 .. 5) {
|
|
Packit Service |
d987f3 |
for my $g (0 .. 5) {
|
|
Packit Service |
d987f3 |
for my $b (0 .. 5) {
|
|
Packit Service |
d987f3 |
my $code = 16 + (6 * 6 * $r) + (6 * $g) + $b;
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"rgb$r$g$b"} = "38;5;$code";
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"on_rgb$r$g$b"} = "48;5;$code";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# The last 256-color codes are 24 shades of grey.
|
|
Packit Service |
d987f3 |
for my $n (0 .. 23) {
|
|
Packit Service |
d987f3 |
my $code = $n + 232;
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"grey$n"} = "38;5;$code";
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"on_grey$n"} = "48;5;$code";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Reverse lookup. Alphabetically first name for a sequence is preferred.
|
|
Packit Service |
d987f3 |
our %ATTRIBUTES_R;
|
|
Packit Service |
d987f3 |
for my $attr (reverse sort keys %ATTRIBUTES) {
|
|
Packit Service |
d987f3 |
$ATTRIBUTES_R{ $ATTRIBUTES{$attr} } = $attr;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Provide ansiN names for all 256 characters to provide a convenient flat
|
|
Packit Service |
d987f3 |
# namespace if one doesn't want to mess with the RGB and greyscale naming. Do
|
|
Packit Service |
d987f3 |
# this after creating %ATTRIBUTES_R since we want to use the canonical names
|
|
Packit Service |
d987f3 |
# when reversing a color.
|
|
Packit Service |
d987f3 |
for my $code (16 .. 255) {
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"ansi$code"} = "38;5;$code";
|
|
Packit Service |
d987f3 |
$ATTRIBUTES{"on_ansi$code"} = "48;5;$code";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Import any custom colors set in the environment.
|
|
Packit Service |
d987f3 |
our %ALIASES;
|
|
Packit Service |
d987f3 |
if (exists $ENV{ANSI_COLORS_ALIASES}) {
|
|
Packit Service |
d987f3 |
my $spec = $ENV{ANSI_COLORS_ALIASES};
|
|
Packit Service |
d987f3 |
$spec =~ s{\s+}{}xmsg;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Error reporting here is an interesting question. Use warn rather than
|
|
Packit Service |
d987f3 |
# carp because carp would report the line of the use or require, which
|
|
Packit Service |
d987f3 |
# doesn't help anyone understand what's going on, whereas seeing this code
|
|
Packit Service |
d987f3 |
# will be more helpful.
|
|
Packit Service |
d987f3 |
## no critic (ErrorHandling::RequireCarping)
|
|
Packit Service |
d987f3 |
for my $definition (split m{,}xms, $spec) {
|
|
Packit Service |
d987f3 |
my ($new, $old) = split m{=}xms, $definition, 2;
|
|
Packit Service |
d987f3 |
if (!$new || !$old) {
|
|
Packit Service |
d987f3 |
warn qq{Bad color mapping "$definition"};
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
my $result = eval { coloralias($new, $old) };
|
|
Packit Service |
d987f3 |
if (!$result) {
|
|
Packit Service |
d987f3 |
my $error = $@;
|
|
Packit Service |
d987f3 |
$error =~ s{ [ ] at [ ] .* }{}xms;
|
|
Packit Service |
d987f3 |
warn qq{$error in "$definition"};
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Stores the current color stack maintained by PUSHCOLOR and POPCOLOR. This
|
|
Packit Service |
d987f3 |
# is global and therefore not threadsafe.
|
|
Packit Service |
d987f3 |
our @COLORSTACK;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Helper functions
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Stub to load the Carp module on demand.
|
|
Packit Service |
d987f3 |
sub croak {
|
|
Packit Service |
d987f3 |
my (@args) = @_;
|
|
Packit Service |
d987f3 |
require Carp;
|
|
Packit Service |
d987f3 |
Carp::croak(@args);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Implementation (constant form)
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Time to have fun! We now want to define the constant subs, which are named
|
|
Packit Service |
d987f3 |
# the same as the attributes above but in all caps. Each constant sub needs
|
|
Packit Service |
d987f3 |
# to act differently depending on whether $AUTORESET is set. Without
|
|
Packit Service |
d987f3 |
# autoreset:
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# BLUE "text\n" ==> "\e[34mtext\n"
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# If $AUTORESET is set, we should instead get:
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# BLUE "text\n" ==> "\e[34mtext\n\e[0m"
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# The sub also needs to handle the case where it has no arguments correctly.
|
|
Packit Service |
d987f3 |
# Maintaining all of this as separate subs would be a major nightmare, as well
|
|
Packit Service |
d987f3 |
# as duplicate the %ATTRIBUTES hash, so instead we define an AUTOLOAD sub to
|
|
Packit Service |
d987f3 |
# define the constant subs on demand. To do that, we check the name of the
|
|
Packit Service |
d987f3 |
# called sub against the list of attributes, and if it's an all-caps version
|
|
Packit Service |
d987f3 |
# of one of them, we define the sub on the fly and then run it.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# If the environment variable ANSI_COLORS_DISABLED is set to a true value,
|
|
Packit Service |
d987f3 |
# just return the arguments without adding any escape sequences. This is to
|
|
Packit Service |
d987f3 |
# make it easier to write scripts that also work on systems without any ANSI
|
|
Packit Service |
d987f3 |
# support, like Windows consoles.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Avoid using character classes like [:upper:] and \w here, since they load
|
|
Packit Service |
d987f3 |
# Unicode character tables and consume a ton of memory. All of our constants
|
|
Packit Service |
d987f3 |
# only use ASCII characters.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
## no critic (ClassHierarchies::ProhibitAutoloading)
|
|
Packit Service |
d987f3 |
## no critic (Subroutines::RequireArgUnpacking)
|
|
Packit Service |
d987f3 |
## no critic (RegularExpressions::ProhibitEnumeratedClasses)
|
|
Packit Service |
d987f3 |
sub AUTOLOAD {
|
|
Packit Service |
d987f3 |
my ($sub, $attr) = $AUTOLOAD =~ m{
|
|
Packit Service |
d987f3 |
\A ( [a-zA-Z0-9:]* :: ([A-Z0-9_]+) ) \z
|
|
Packit Service |
d987f3 |
}xms;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Check if we were called with something that doesn't look like an
|
|
Packit Service |
d987f3 |
# attribute.
|
|
Packit Service |
d987f3 |
if (!($attr && defined($ATTRIBUTES{ lc $attr }))) {
|
|
Packit Service |
d987f3 |
croak("undefined subroutine &$AUTOLOAD called");
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# If colors are disabled, just return the input. Do this without
|
|
Packit Service |
d987f3 |
# installing a sub for (marginal, unbenchmarked) speed.
|
|
Packit Service |
d987f3 |
if ($ENV{ANSI_COLORS_DISABLED}) {
|
|
Packit Service |
d987f3 |
return join(q{}, @_);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# We've untainted the name of the sub.
|
|
Packit Service |
d987f3 |
$AUTOLOAD = $sub;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Figure out the ANSI string to set the desired attribute.
|
|
Packit Service |
d987f3 |
my $escape = "\e[" . $ATTRIBUTES{ lc $attr } . 'm';
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Save the current value of $@. We can't just use local since we want to
|
|
Packit Service |
d987f3 |
# restore it before dispatching to the newly-created sub. (The caller may
|
|
Packit Service |
d987f3 |
# be colorizing output that includes $@.)
|
|
Packit Service |
d987f3 |
my $eval_err = $@;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Generate the constant sub, which should still recognize some of our
|
|
Packit Service |
d987f3 |
# package variables. Use string eval to avoid a dependency on
|
|
Packit Service |
d987f3 |
# Sub::Install, even though it makes it somewhat less readable.
|
|
Packit Service |
d987f3 |
## no critic (BuiltinFunctions::ProhibitStringyEval)
|
|
Packit Service |
d987f3 |
## no critic (ValuesAndExpressions::ProhibitImplicitNewlines)
|
|
Packit Service |
d987f3 |
my $eval_result = eval qq{
|
|
Packit Service |
d987f3 |
sub $AUTOLOAD {
|
|
Packit Service |
d987f3 |
if (\$ENV{ANSI_COLORS_DISABLED}) {
|
|
Packit Service |
d987f3 |
return join(q{}, \@_);
|
|
Packit Service |
d987f3 |
} elsif (\$AUTOLOCAL && \@_) {
|
|
Packit Service |
d987f3 |
return PUSHCOLOR('$escape') . join(q{}, \@_) . POPCOLOR;
|
|
Packit Service |
d987f3 |
} elsif (\$AUTORESET && \@_) {
|
|
Packit Service |
d987f3 |
return '$escape' . join(q{}, \@_) . "\e[0m";
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
return '$escape' . join(q{}, \@_);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
1;
|
|
Packit Service |
d987f3 |
};
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Failure is an internal error, not a problem with the caller.
|
|
Packit Service |
d987f3 |
## no critic (ErrorHandling::RequireCarping)
|
|
Packit Service |
d987f3 |
if (!$eval_result) {
|
|
Packit Service |
d987f3 |
die "failed to generate constant $attr: $@";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Restore $@.
|
|
Packit Service |
d987f3 |
## no critic (Variables::RequireLocalizedPunctuationVars)
|
|
Packit Service |
d987f3 |
$@ = $eval_err;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Dispatch to the newly-created sub.
|
|
Packit Service |
d987f3 |
## no critic (References::ProhibitDoubleSigils)
|
|
Packit Service |
d987f3 |
goto &$AUTOLOAD;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
## use critic
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Append a new color to the top of the color stack and return the top of
|
|
Packit Service |
d987f3 |
# the stack.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# $text - Any text we're applying colors to, with color escapes prepended
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The text passed in
|
|
Packit Service |
d987f3 |
sub PUSHCOLOR {
|
|
Packit Service |
d987f3 |
my (@text) = @_;
|
|
Packit Service |
d987f3 |
my $text = join(q{}, @text);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Extract any number of color-setting escape sequences from the start of
|
|
Packit Service |
d987f3 |
# the string.
|
|
Packit Service |
d987f3 |
my ($color) = $text =~ m{ \A ( (?:\e\[ [\d;]+ m)+ ) }xms;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# If we already have a stack, append these escapes to the set from the top
|
|
Packit Service |
d987f3 |
# of the stack. This way, each position in the stack stores the complete
|
|
Packit Service |
d987f3 |
# enabled colors for that stage, at the cost of some potential
|
|
Packit Service |
d987f3 |
# inefficiency.
|
|
Packit Service |
d987f3 |
if (@COLORSTACK) {
|
|
Packit Service |
d987f3 |
$color = $COLORSTACK[-1] . $color;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Push the color onto the stack.
|
|
Packit Service |
d987f3 |
push(@COLORSTACK, $color);
|
|
Packit Service |
d987f3 |
return $text;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Pop the color stack and return the new top of the stack (or reset, if
|
|
Packit Service |
d987f3 |
# the stack is empty).
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @text - Any text we're applying colors to
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The concatenation of @text prepended with the new stack color
|
|
Packit Service |
d987f3 |
sub POPCOLOR {
|
|
Packit Service |
d987f3 |
my (@text) = @_;
|
|
Packit Service |
d987f3 |
pop(@COLORSTACK);
|
|
Packit Service |
d987f3 |
if (@COLORSTACK) {
|
|
Packit Service |
d987f3 |
return $COLORSTACK[-1] . join(q{}, @text);
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
return RESET(@text);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Surround arguments with a push and a pop. The effect will be to reset the
|
|
Packit Service |
d987f3 |
# colors to whatever was on the color stack before this sequence of colors was
|
|
Packit Service |
d987f3 |
# applied.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @text - Any text we're applying colors to
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The concatenation of the text and the proper color reset sequence.
|
|
Packit Service |
d987f3 |
sub LOCALCOLOR {
|
|
Packit Service |
d987f3 |
my (@text) = @_;
|
|
Packit Service |
d987f3 |
return PUSHCOLOR(join(q{}, @text)) . POPCOLOR();
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Implementation (attribute string form)
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return the escape code for a given set of color attributes.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @codes - A list of possibly space-separated color attributes
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The escape sequence setting those color attributes
|
|
Packit Service |
d987f3 |
# undef if no escape sequences were given
|
|
Packit Service |
d987f3 |
# Throws: Text exception for any invalid attribute
|
|
Packit Service |
d987f3 |
sub color {
|
|
Packit Service |
d987f3 |
my (@codes) = @_;
|
|
Packit Service |
d987f3 |
@codes = map { split } @codes;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return the empty string if colors are disabled.
|
|
Packit Service |
d987f3 |
if ($ENV{ANSI_COLORS_DISABLED}) {
|
|
Packit Service |
d987f3 |
return q{};
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Build the attribute string from semicolon-separated numbers.
|
|
Packit Service |
d987f3 |
my $attribute = q{};
|
|
Packit Service |
d987f3 |
for my $code (@codes) {
|
|
Packit Service |
d987f3 |
$code = lc($code);
|
|
Packit Service |
d987f3 |
if (defined($ATTRIBUTES{$code})) {
|
|
Packit Service |
d987f3 |
$attribute .= $ATTRIBUTES{$code} . q{;};
|
|
Packit Service |
d987f3 |
} elsif (defined($ALIASES{$code})) {
|
|
Packit Service |
d987f3 |
$attribute .= $ALIASES{$code} . q{;};
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
croak("Invalid attribute name $code");
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# We added one too many semicolons for simplicity. Remove the last one.
|
|
Packit Service |
d987f3 |
chop($attribute);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return undef if there were no attributes.
|
|
Packit Service |
d987f3 |
return ($attribute ne q{}) ? "\e[${attribute}m" : undef;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return a list of named color attributes for a given set of escape codes.
|
|
Packit Service |
d987f3 |
# Escape sequences can be given with or without enclosing "\e[" and "m". The
|
|
Packit Service |
d987f3 |
# empty escape sequence '' or "\e[m" gives an empty list of attrs.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# There is one special case. 256-color codes start with 38 or 48, followed by
|
|
Packit Service |
d987f3 |
# a 5 and then the 256-color code.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @escapes - A list of escape sequences or escape sequence numbers
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: An array of attribute names corresponding to those sequences
|
|
Packit Service |
d987f3 |
# Throws: Text exceptions on invalid escape sequences or unknown colors
|
|
Packit Service |
d987f3 |
sub uncolor {
|
|
Packit Service |
d987f3 |
my (@escapes) = @_;
|
|
Packit Service |
d987f3 |
my (@nums, @result);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Walk the list of escapes and build a list of attribute numbers.
|
|
Packit Service |
d987f3 |
for my $escape (@escapes) {
|
|
Packit Service |
d987f3 |
$escape =~ s{ \A \e\[ }{}xms;
|
|
Packit Service |
d987f3 |
$escape =~ s{ m \z } {}xms;
|
|
Packit Service |
d987f3 |
my ($attrs) = $escape =~ m{ \A ((?:\d+;)* \d*) \z }xms;
|
|
Packit Service |
d987f3 |
if (!defined($attrs)) {
|
|
Packit Service |
d987f3 |
croak("Bad escape sequence $escape");
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Pull off 256-color codes (38;5;n or 48;5;n) as a unit.
|
|
Packit Service |
d987f3 |
push(@nums, $attrs =~ m{ ( 0*[34]8;0*5;\d+ | \d+ ) (?: ; | \z ) }xmsg);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Now, walk the list of numbers and convert them to attribute names.
|
|
Packit Service |
d987f3 |
# Strip leading zeroes from any of the numbers. (xterm, at least, allows
|
|
Packit Service |
d987f3 |
# leading zeroes to be added to any number in an escape sequence.)
|
|
Packit Service |
d987f3 |
for my $num (@nums) {
|
|
Packit Service |
d987f3 |
$num =~ s{ ( \A | ; ) 0+ (\d) }{$1$2}xmsg;
|
|
Packit Service |
d987f3 |
my $name = $ATTRIBUTES_R{$num};
|
|
Packit Service |
d987f3 |
if (!defined($name)) {
|
|
Packit Service |
d987f3 |
croak("No name for escape sequence $num");
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
push(@result, $name);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return the attribute names.
|
|
Packit Service |
d987f3 |
return @result;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Given a string and a set of attributes, returns the string surrounded by
|
|
Packit Service |
d987f3 |
# escape codes to set those attributes and then clear them at the end of the
|
|
Packit Service |
d987f3 |
# string. The attributes can be given either as an array ref as the first
|
|
Packit Service |
d987f3 |
# argument or as a list as the second and subsequent arguments.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# If $EACHLINE is set, insert a reset before each occurrence of the string
|
|
Packit Service |
d987f3 |
# $EACHLINE and the starting attribute code after the string $EACHLINE, so
|
|
Packit Service |
d987f3 |
# that no attribute crosses line delimiters (this is often desirable if the
|
|
Packit Service |
d987f3 |
# output is to be piped to a pager or some other program).
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# $first - An anonymous array of attributes or the text to color
|
|
Packit Service |
d987f3 |
# @rest - The text to color or the list of attributes
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The text, concatenated if necessary, surrounded by escapes to set
|
|
Packit Service |
d987f3 |
# the desired colors and reset them afterwards
|
|
Packit Service |
d987f3 |
# Throws: Text exception on invalid attributes
|
|
Packit Service |
d987f3 |
sub colored {
|
|
Packit Service |
d987f3 |
my ($first, @rest) = @_;
|
|
Packit Service |
d987f3 |
my ($string, @codes);
|
|
Packit Service |
d987f3 |
if (ref($first) && ref($first) eq 'ARRAY') {
|
|
Packit Service |
d987f3 |
@codes = @{$first};
|
|
Packit Service |
d987f3 |
$string = join(q{}, @rest);
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
$string = $first;
|
|
Packit Service |
d987f3 |
@codes = @rest;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Return the string unmolested if colors are disabled.
|
|
Packit Service |
d987f3 |
if ($ENV{ANSI_COLORS_DISABLED}) {
|
|
Packit Service |
d987f3 |
return $string;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Find the attribute string for our colors.
|
|
Packit Service |
d987f3 |
my $attr = color(@codes);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# If $EACHLINE is defined, split the string on line boundaries, suppress
|
|
Packit Service |
d987f3 |
# empty segments, and then colorize each of the line sections.
|
|
Packit Service |
d987f3 |
if (defined($EACHLINE)) {
|
|
Packit Service |
d987f3 |
my @text = map { ($_ ne $EACHLINE) ? $attr . $_ . "\e[0m" : $_ }
|
|
Packit Service |
d987f3 |
grep { length > 0 }
|
|
Packit Service |
d987f3 |
split(m{ (\Q$EACHLINE\E) }xms, $string);
|
|
Packit Service |
d987f3 |
return join(q{}, @text);
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
return $attr . $string . "\e[0m";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Define a new color alias, or return the value of an existing alias.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# $alias - The color alias to define
|
|
Packit Service |
d987f3 |
# $color - The standard color the alias will correspond to (optional)
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: The standard color value of the alias
|
|
Packit Service |
d987f3 |
# undef if one argument was given and the alias was not recognized
|
|
Packit Service |
d987f3 |
# Throws: Text exceptions for invalid alias names, attempts to use a
|
|
Packit Service |
d987f3 |
# standard color name as an alias, or an unknown standard color name
|
|
Packit Service |
d987f3 |
sub coloralias {
|
|
Packit Service |
d987f3 |
my ($alias, $color) = @_;
|
|
Packit Service |
d987f3 |
if (!defined($color)) {
|
|
Packit Service |
d987f3 |
if (!exists $ALIASES{$alias}) {
|
|
Packit Service |
d987f3 |
return;
|
|
Packit Service |
d987f3 |
} else {
|
|
Packit Service |
d987f3 |
return $ATTRIBUTES_R{ $ALIASES{$alias} };
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Avoid \w here to not load Unicode character tables, which increases the
|
|
Packit Service |
d987f3 |
# memory footprint of this module considerably.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
## no critic (RegularExpressions::ProhibitEnumeratedClasses)
|
|
Packit Service |
d987f3 |
if ($alias !~ m{ \A [a-zA-Z0-9._-]+ \z }xms) {
|
|
Packit Service |
d987f3 |
croak(qq{Invalid alias name "$alias"});
|
|
Packit Service |
d987f3 |
} elsif ($ATTRIBUTES{$alias}) {
|
|
Packit Service |
d987f3 |
croak(qq{Cannot alias standard color "$alias"});
|
|
Packit Service |
d987f3 |
} elsif (!exists $ATTRIBUTES{$color}) {
|
|
Packit Service |
d987f3 |
croak(qq{Invalid attribute name "$color"});
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
## use critic
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Set the alias and return.
|
|
Packit Service |
d987f3 |
$ALIASES{$alias} = $ATTRIBUTES{$color};
|
|
Packit Service |
d987f3 |
return $color;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Given a string, strip the ANSI color codes out of that string and return the
|
|
Packit Service |
d987f3 |
# result. This removes only ANSI color codes, not movement codes and other
|
|
Packit Service |
d987f3 |
# escape sequences.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @string - The list of strings to sanitize
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: (array) The strings stripped of ANSI color escape sequences
|
|
Packit Service |
d987f3 |
# (scalar) The same, concatenated
|
|
Packit Service |
d987f3 |
sub colorstrip {
|
|
Packit Service |
d987f3 |
my (@string) = @_;
|
|
Packit Service |
d987f3 |
for my $string (@string) {
|
|
Packit Service |
d987f3 |
$string =~ s{ \e\[ [\d;]* m }{}xmsg;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
return wantarray ? @string : join(q{}, @string);
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Given a list of color attributes (arguments for color, for instance), return
|
|
Packit Service |
d987f3 |
# true if they're all valid or false if any of them are invalid.
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# @codes - A list of color attributes, possibly space-separated
|
|
Packit Service |
d987f3 |
#
|
|
Packit Service |
d987f3 |
# Returns: True if all the attributes are valid, false otherwise.
|
|
Packit Service |
d987f3 |
sub colorvalid {
|
|
Packit Service |
d987f3 |
my (@codes) = @_;
|
|
Packit Service |
d987f3 |
@codes = map { split(q{ }, lc) } @codes;
|
|
Packit Service |
d987f3 |
for my $code (@codes) {
|
|
Packit Service |
d987f3 |
if (!(defined($ATTRIBUTES{$code}) || defined($ALIASES{$code}))) {
|
|
Packit Service |
d987f3 |
return;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
return 1;
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
# Module return value and documentation
|
|
Packit Service |
d987f3 |
##############################################################################
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Ensure we evaluate to true.
|
|
Packit Service |
d987f3 |
1;
|
|
Packit Service |
d987f3 |
__END__
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 NAME
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Term::ANSIColor - Color screen output using ANSI escape sequences
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=for stopwords
|
|
Packit Service |
d987f3 |
cyan colorize namespace runtime TMTOWTDI cmd.exe cmd.exe. 4nt.exe. 4nt.exe
|
|
Packit Service |
d987f3 |
command.com NT ESC Delvare SSH OpenSSH aixterm ECMA-048 Fraktur overlining
|
|
Packit Service |
d987f3 |
Zenin reimplemented Allbery PUSHCOLOR POPCOLOR LOCALCOLOR openmethods.com
|
|
Packit Service |
d987f3 |
openmethods.com. grey ATTR urxvt mistyped prepending Bareword filehandle
|
|
Packit Service |
d987f3 |
Cygwin Starsinic aterm rxvt CPAN RGB Solarized Whitespace alphanumerics
|
|
Packit Service |
d987f3 |
undef
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 SYNOPSIS
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Term::ANSIColor;
|
|
Packit Service |
d987f3 |
print color('bold blue');
|
|
Packit Service |
d987f3 |
print "This text is bold blue.\n";
|
|
Packit Service |
d987f3 |
print color('reset');
|
|
Packit Service |
d987f3 |
print "This text is normal.\n";
|
|
Packit Service |
d987f3 |
print colored("Yellow on magenta.", 'yellow on_magenta'), "\n";
|
|
Packit Service |
d987f3 |
print "This text is normal.\n";
|
|
Packit Service |
d987f3 |
print colored(['yellow on_magenta'], 'Yellow on magenta.', "\n");
|
|
Packit Service |
d987f3 |
print colored(['red on_bright_yellow'], 'Red on bright yellow.', "\n");
|
|
Packit Service |
d987f3 |
print colored(['bright_red on_black'], 'Bright red on black.', "\n");
|
|
Packit Service |
d987f3 |
print "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Map escape sequences back to color names.
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 1.04 qw(uncolor);
|
|
Packit Service |
d987f3 |
my $names = uncolor('01;31');
|
|
Packit Service |
d987f3 |
print join(q{ }, @{$names}), "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Strip all color escape sequences.
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 2.01 qw(colorstrip);
|
|
Packit Service |
d987f3 |
print colorstrip("\e[1mThis is bold\e[0m"), "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Determine whether a color is valid.
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 2.02 qw(colorvalid);
|
|
Packit Service |
d987f3 |
my $valid = colorvalid('blue bold', 'on_magenta');
|
|
Packit Service |
d987f3 |
print "Color string is ", $valid ? "valid\n" : "invalid\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
# Create new aliases for colors.
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 4.00 qw(coloralias);
|
|
Packit Service |
d987f3 |
coloralias('alert', 'red');
|
|
Packit Service |
d987f3 |
print "Alert is ", coloralias('alert'), "\n";
|
|
Packit Service |
d987f3 |
print colored("This is in red.", 'alert'), "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Term::ANSIColor qw(:constants);
|
|
Packit Service |
d987f3 |
print BOLD, BLUE, "This text is in bold blue.\n", RESET;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Term::ANSIColor qw(:constants);
|
|
Packit Service |
d987f3 |
{
|
|
Packit Service |
d987f3 |
local $Term::ANSIColor::AUTORESET = 1;
|
|
Packit Service |
d987f3 |
print BOLD BLUE "This text is in bold blue.\n";
|
|
Packit Service |
d987f3 |
print "This text is normal.\n";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 2.00 qw(:pushpop);
|
|
Packit Service |
d987f3 |
print PUSHCOLOR RED ON_GREEN "This text is red on green.\n";
|
|
Packit Service |
d987f3 |
print PUSHCOLOR BRIGHT_BLUE "This text is bright blue on green.\n";
|
|
Packit Service |
d987f3 |
print RESET BRIGHT_BLUE "This text is just bright blue.\n";
|
|
Packit Service |
d987f3 |
print POPCOLOR "Back to red on green.\n";
|
|
Packit Service |
d987f3 |
print LOCALCOLOR GREEN ON_BLUE "This text is green on blue.\n";
|
|
Packit Service |
d987f3 |
print "This text is red on green.\n";
|
|
Packit Service |
d987f3 |
{
|
|
Packit Service |
d987f3 |
local $Term::ANSIColor::AUTOLOCAL = 1;
|
|
Packit Service |
d987f3 |
print ON_BLUE "This text is red on blue.\n";
|
|
Packit Service |
d987f3 |
print "This text is red on green.\n";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
print POPCOLOR "Back to whatever we started as.\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 DESCRIPTION
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This module has two interfaces, one through color() and colored() and the
|
|
Packit Service |
d987f3 |
other through constants. It also offers the utility functions uncolor(),
|
|
Packit Service |
d987f3 |
colorstrip(), colorvalid(), and coloralias(), which have to be explicitly
|
|
Packit Service |
d987f3 |
imported to be used (see L</SYNOPSIS>).
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
See L</COMPATIBILITY> for the versions of Term::ANSIColor that introduced
|
|
Packit Service |
d987f3 |
particular features and the versions of Perl that included them.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head2 Supported Colors
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Terminal emulators that support color divide into three types: ones that
|
|
Packit Service |
d987f3 |
support only eight colors, ones that support sixteen, and ones that
|
|
Packit Service |
d987f3 |
support 256. This module provides the ANSI escape codes for all of them.
|
|
Packit Service |
d987f3 |
These colors are referred to as ANSI colors 0 through 7 (normal), 8
|
|
Packit Service |
d987f3 |
through 15 (16-color), and 16 through 255 (256-color).
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Unfortunately, interpretation of colors 0 through 7 often depends on
|
|
Packit Service |
d987f3 |
whether the emulator supports eight colors or sixteen colors. Emulators
|
|
Packit Service |
d987f3 |
that only support eight colors (such as the Linux console) will display
|
|
Packit Service |
d987f3 |
colors 0 through 7 with normal brightness and ignore colors 8 through 15,
|
|
Packit Service |
d987f3 |
treating them the same as white. Emulators that support 16 colors, such
|
|
Packit Service |
d987f3 |
as gnome-terminal, normally display colors 0 through 7 as dim or darker
|
|
Packit Service |
d987f3 |
versions and colors 8 through 15 as normal brightness. On such emulators,
|
|
Packit Service |
d987f3 |
the "normal" white (color 7) usually is shown as pale grey, requiring
|
|
Packit Service |
d987f3 |
bright white (15) to be used to get a real white color. Bright black
|
|
Packit Service |
d987f3 |
usually is a dark grey color, although some terminals display it as pure
|
|
Packit Service |
d987f3 |
black. Some sixteen-color terminal emulators also treat normal yellow
|
|
Packit Service |
d987f3 |
(color 3) as orange or brown, and bright yellow (color 11) as yellow.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Following the normal convention of sixteen-color emulators, this module
|
|
Packit Service |
d987f3 |
provides a pair of attributes for each color. For every normal color (0
|
|
Packit Service |
d987f3 |
through 7), the corresponding bright color (8 through 15) is obtained by
|
|
Packit Service |
d987f3 |
prepending the string C<bright_> to the normal color name. For example,
|
|
Packit Service |
d987f3 |
C<red> is color 1 and C<bright_red> is color 9. The same applies for
|
|
Packit Service |
d987f3 |
background colors: C<on_red> is the normal color and C<on_bright_red> is
|
|
Packit Service |
d987f3 |
the bright color. Capitalize these strings for the constant interface.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
For 256-color emulators, this module additionally provides C<ansi0>
|
|
Packit Service |
d987f3 |
through C<ansi15>, which are the same as colors 0 through 15 in
|
|
Packit Service |
d987f3 |
sixteen-color emulators but use the 256-color escape syntax, C<grey0>
|
|
Packit Service |
d987f3 |
through C<grey23> ranging from nearly black to nearly white, and a set of
|
|
Packit Service |
d987f3 |
RGB colors. The RGB colors are of the form C<rgbI<RGB>> where I<R>, I<G>,
|
|
Packit Service |
d987f3 |
and I are numbers from 0 to 5 giving the intensity of red, green, and
|
|
Packit Service |
d987f3 |
blue. The grey and RGB colors are also available as C<ansi16> through
|
|
Packit Service |
d987f3 |
C<ansi255> if you want simple names for all 256 colors. C<on_> variants
|
|
Packit Service |
d987f3 |
of all of these colors are also provided. These colors may be ignored
|
|
Packit Service |
d987f3 |
completely on non-256-color terminals or may be misinterpreted and produce
|
|
Packit Service |
d987f3 |
random behavior. Additional attributes such as blink, italic, or bold may
|
|
Packit Service |
d987f3 |
not work with the 256-color palette.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
There is unfortunately no way to know whether the current emulator
|
|
Packit Service |
d987f3 |
supports more than eight colors, which makes the choice of colors
|
|
Packit Service |
d987f3 |
difficult. The most conservative choice is to use only the regular
|
|
Packit Service |
d987f3 |
colors, which are at least displayed on all emulators. However, they will
|
|
Packit Service |
d987f3 |
appear dark in sixteen-color terminal emulators, including most common
|
|
Packit Service |
d987f3 |
emulators in UNIX X environments. If you know the display is one of those
|
|
Packit Service |
d987f3 |
emulators, you may wish to use the bright variants instead. Even better,
|
|
Packit Service |
d987f3 |
offer the user a way to configure the colors for a given application to
|
|
Packit Service |
d987f3 |
fit their terminal emulator.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head2 Function Interface
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The function interface uses attribute strings to describe the colors and
|
|
Packit Service |
d987f3 |
text attributes to assign to text. The recognized non-color attributes
|
|
Packit Service |
d987f3 |
are clear, reset, bold, dark, faint, italic, underline, underscore, blink,
|
|
Packit Service |
d987f3 |
reverse, and concealed. Clear and reset (reset to default attributes),
|
|
Packit Service |
d987f3 |
dark and faint (dim and saturated), and underline and underscore are
|
|
Packit Service |
d987f3 |
equivalent, so use whichever is the most intuitive to you.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Note that not all attributes are supported by all terminal types, and some
|
|
Packit Service |
d987f3 |
terminals may not support any of these sequences. Dark and faint, italic,
|
|
Packit Service |
d987f3 |
blink, and concealed in particular are frequently not implemented.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The recognized normal foreground color attributes (colors 0 to 7) are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
black red green yellow blue magenta cyan white
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The corresponding bright foreground color attributes (colors 8 to 15) are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
bright_black bright_red bright_green bright_yellow
|
|
Packit Service |
d987f3 |
bright_blue bright_magenta bright_cyan bright_white
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The recognized normal background color attributes (colors 0 to 7) are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
on_black on_red on_green on yellow
|
|
Packit Service |
d987f3 |
on_blue on_magenta on_cyan on_white
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The recognized bright background color attributes (colors 8 to 15) are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
on_bright_black on_bright_red on_bright_green on_bright_yellow
|
|
Packit Service |
d987f3 |
on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
For 256-color terminals, the recognized foreground colors are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ansi0 .. ansi255
|
|
Packit Service |
d987f3 |
grey0 .. grey23
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
plus C<rgbI<RGB>> for I<R>, I<G>, and I values from 0 to 5, such as
|
|
Packit Service |
d987f3 |
C<rgb000> or C<rgb515>. Similarly, the recognized background colors are:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
on_ansi0 .. on_ansi255
|
|
Packit Service |
d987f3 |
on_grey0 .. on_grey23
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
plus C<on_rgbI<RGB>> for I<R>, I<G>, and I values from 0 to 5.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
For any of the above listed attributes, case is not significant.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Attributes, once set, last until they are unset (by printing the attribute
|
|
Packit Service |
d987f3 |
C<clear> or C<reset>). Be careful to do this, or otherwise your attribute
|
|
Packit Service |
d987f3 |
will last after your script is done running, and people get very annoyed
|
|
Packit Service |
d987f3 |
at having their prompt and typing changed to weird colors.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=over 4
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item color(ATTR[, ATTR ...])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
color() takes any number of strings as arguments and considers them to be
|
|
Packit Service |
d987f3 |
space-separated lists of attributes. It then forms and returns the escape
|
|
Packit Service |
d987f3 |
sequence to set those attributes. It doesn't print it out, just returns
|
|
Packit Service |
d987f3 |
it, so you'll have to print it yourself if you want to. This is so that
|
|
Packit Service |
d987f3 |
you can save it as a string, pass it to something else, send it to a file
|
|
Packit Service |
d987f3 |
handle, or do anything else with it that you might care to. color()
|
|
Packit Service |
d987f3 |
throws an exception if given an invalid attribute.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item colored(STRING, ATTR[, ATTR ...])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item colored(ATTR-REF, STRING[, STRING...])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
As an aid in resetting colors, colored() takes a scalar as the first
|
|
Packit Service |
d987f3 |
argument and any number of attribute strings as the second argument and
|
|
Packit Service |
d987f3 |
returns the scalar wrapped in escape codes so that the attributes will be
|
|
Packit Service |
d987f3 |
set as requested before the string and reset to normal after the string.
|
|
Packit Service |
d987f3 |
Alternately, you can pass a reference to an array as the first argument,
|
|
Packit Service |
d987f3 |
and then the contents of that array will be taken as attributes and color
|
|
Packit Service |
d987f3 |
codes and the remainder of the arguments as text to colorize.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Normally, colored() just puts attribute codes at the beginning and end of
|
|
Packit Service |
d987f3 |
the string, but if you set $Term::ANSIColor::EACHLINE to some string, that
|
|
Packit Service |
d987f3 |
string will be considered the line delimiter and the attribute will be set
|
|
Packit Service |
d987f3 |
at the beginning of each line of the passed string and reset at the end of
|
|
Packit Service |
d987f3 |
each line. This is often desirable if the output contains newlines and
|
|
Packit Service |
d987f3 |
you're using background colors, since a background color that persists
|
|
Packit Service |
d987f3 |
across a newline is often interpreted by the terminal as providing the
|
|
Packit Service |
d987f3 |
default background color for the next line. Programs like pagers can also
|
|
Packit Service |
d987f3 |
be confused by attributes that span lines. Normally you'll want to set
|
|
Packit Service |
d987f3 |
$Term::ANSIColor::EACHLINE to C<"\n"> to use this feature.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item uncolor(ESCAPE)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
uncolor() performs the opposite translation as color(), turning escape
|
|
Packit Service |
d987f3 |
sequences into a list of strings corresponding to the attributes being set
|
|
Packit Service |
d987f3 |
by those sequences. uncolor() will never return C<ansi16> through
|
|
Packit Service |
d987f3 |
C<ansi255>, instead preferring the C<grey> and C<rgb> names (and likewise
|
|
Packit Service |
d987f3 |
for C<on_ansi16> through C<on_ansi255>).
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item colorstrip(STRING[, STRING ...])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
colorstrip() removes all color escape sequences from the provided strings,
|
|
Packit Service |
d987f3 |
returning the modified strings separately in array context or joined
|
|
Packit Service |
d987f3 |
together in scalar context. Its arguments are not modified.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item colorvalid(ATTR[, ATTR ...])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
colorvalid() takes attribute strings the same as color() and returns true
|
|
Packit Service |
d987f3 |
if all attributes are known and false otherwise.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item coloralias(ALIAS[, ATTR])
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If ATTR is specified, coloralias() sets up an alias of ALIAS for the
|
|
Packit Service |
d987f3 |
standard color ATTR. From that point forward, ALIAS can be passed into
|
|
Packit Service |
d987f3 |
color(), colored(), and colorvalid() and will have the same meaning as
|
|
Packit Service |
d987f3 |
ATTR. One possible use of this facility is to give more meaningful names
|
|
Packit Service |
d987f3 |
to the 256-color RGB colors. Only ASCII alphanumerics, C<.>, C<_>, and
|
|
Packit Service |
d987f3 |
C<-> are allowed in alias names.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If ATTR is not specified, coloralias() returns the standard color name to
|
|
Packit Service |
d987f3 |
which ALIAS is aliased, if any, or undef if ALIAS does not exist.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This is the same facility used by the ANSI_COLORS_ALIASES environment
|
|
Packit Service |
d987f3 |
variable (see L</ENVIRONMENT> below) but can be used at runtime, not just
|
|
Packit Service |
d987f3 |
when the module is loaded.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Later invocations of coloralias() with the same ALIAS will override
|
|
Packit Service |
d987f3 |
earlier aliases. There is no way to remove an alias.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Aliases have no effect on the return value of uncolor().
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
B<WARNING>: Aliases are global and affect all callers in the same process.
|
|
Packit Service |
d987f3 |
There is no way to set an alias limited to a particular block of code or a
|
|
Packit Service |
d987f3 |
particular object.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=back
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head2 Constant Interface
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Alternately, if you import C<:constants>, you can use the following
|
|
Packit Service |
d987f3 |
constants directly:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
CLEAR RESET BOLD DARK
|
|
Packit Service |
d987f3 |
FAINT ITALIC UNDERLINE UNDERSCORE
|
|
Packit Service |
d987f3 |
BLINK REVERSE CONCEALED
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
BLACK RED GREEN YELLOW
|
|
Packit Service |
d987f3 |
BLUE MAGENTA CYAN WHITE
|
|
Packit Service |
d987f3 |
BRIGHT_BLACK BRIGHT_RED BRIGHT_GREEN BRIGHT_YELLOW
|
|
Packit Service |
d987f3 |
BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ON_BLACK ON_RED ON_GREEN ON_YELLOW
|
|
Packit Service |
d987f3 |
ON_BLUE ON_MAGENTA ON_CYAN ON_WHITE
|
|
Packit Service |
d987f3 |
ON_BRIGHT_BLACK ON_BRIGHT_RED ON_BRIGHT_GREEN ON_BRIGHT_YELLOW
|
|
Packit Service |
d987f3 |
ON_BRIGHT_BLUE ON_BRIGHT_MAGENTA ON_BRIGHT_CYAN ON_BRIGHT_WHITE
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
These are the same as color('attribute') and can be used if you prefer
|
|
Packit Service |
d987f3 |
typing:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print BOLD BLUE ON_WHITE "Text", RESET, "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
to
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print colored ("Text", 'bold blue on_white'), "\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(Note that the newline is kept separate to avoid confusing the terminal as
|
|
Packit Service |
d987f3 |
described above since a background color is being used.)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If you import C<:constants256>, you can use the following constants
|
|
Packit Service |
d987f3 |
directly:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ANSI0 .. ANSI255
|
|
Packit Service |
d987f3 |
GREY0 .. GREY23
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
RGBXYZ (for X, Y, and Z values from 0 to 5, like RGB000 or RGB515)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ON_ANSI0 .. ON_ANSI255
|
|
Packit Service |
d987f3 |
ON_GREY0 .. ON_GREY23
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ON_RGBXYZ (for X, Y, and Z values from 0 to 5)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Note that C<:constants256> does not include the other constants, so if you
|
|
Packit Service |
d987f3 |
want to mix both, you need to include C<:constants> as well. You may want
|
|
Packit Service |
d987f3 |
to explicitly import at least C<RESET>, as in:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
use Term::ANSIColor 4.00 qw(RESET :constants256);
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
When using the constants, if you don't want to have to remember to add the
|
|
Packit Service |
d987f3 |
C<, RESET> at the end of each print line, you can set
|
|
Packit Service |
d987f3 |
$Term::ANSIColor::AUTORESET to a true value. Then, the display mode will
|
|
Packit Service |
d987f3 |
automatically be reset if there is no comma after the constant. In other
|
|
Packit Service |
d987f3 |
words, with that variable set:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print BOLD BLUE "Text\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
will reset the display mode afterward, whereas:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print BOLD, BLUE, "Text\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
will not. If you are using background colors, you will probably want to
|
|
Packit Service |
d987f3 |
either use say() (in newer versions of Perl) or print the newline with a
|
|
Packit Service |
d987f3 |
separate print statement to avoid confusing the terminal.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If $Term::ANSIColor::AUTOLOCAL is set (see below), it takes precedence
|
|
Packit Service |
d987f3 |
over $Term::ANSIColor::AUTORESET, and the latter is ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The subroutine interface has the advantage over the constants interface in
|
|
Packit Service |
d987f3 |
that only two subroutines are exported into your namespace, versus
|
|
Packit Service |
d987f3 |
thirty-eight in the constants interface. On the flip side, the constants
|
|
Packit Service |
d987f3 |
interface has the advantage of better compile time error checking, since
|
|
Packit Service |
d987f3 |
misspelled names of colors or attributes in calls to color() and colored()
|
|
Packit Service |
d987f3 |
won't be caught until runtime whereas misspelled names of constants will
|
|
Packit Service |
d987f3 |
be caught at compile time. So, pollute your namespace with almost two
|
|
Packit Service |
d987f3 |
dozen subroutines that you may not even use that often, or risk a silly
|
|
Packit Service |
d987f3 |
bug by mistyping an attribute. Your choice, TMTOWTDI after all.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head2 The Color Stack
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
You can import C<:pushpop> and maintain a stack of colors using PUSHCOLOR,
|
|
Packit Service |
d987f3 |
POPCOLOR, and LOCALCOLOR. PUSHCOLOR takes the attribute string that
|
|
Packit Service |
d987f3 |
starts its argument and pushes it onto a stack of attributes. POPCOLOR
|
|
Packit Service |
d987f3 |
removes the top of the stack and restores the previous attributes set by
|
|
Packit Service |
d987f3 |
the argument of a prior PUSHCOLOR. LOCALCOLOR surrounds its argument in a
|
|
Packit Service |
d987f3 |
PUSHCOLOR and POPCOLOR so that the color resets afterward.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If $Term::ANSIColor::AUTOLOCAL is set, each sequence of color constants
|
|
Packit Service |
d987f3 |
will be implicitly preceded by LOCALCOLOR. In other words, the following:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
{
|
|
Packit Service |
d987f3 |
local $Term::ANSIColor::AUTOLOCAL = 1;
|
|
Packit Service |
d987f3 |
print BLUE "Text\n";
|
|
Packit Service |
d987f3 |
}
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
is equivalent to:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print LOCALCOLOR BLUE "Text\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If $Term::ANSIColor::AUTOLOCAL is set, it takes precedence over
|
|
Packit Service |
d987f3 |
$Term::ANSIColor::AUTORESET, and the latter is ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
When using PUSHCOLOR, POPCOLOR, and LOCALCOLOR, it's particularly
|
|
Packit Service |
d987f3 |
important to not put commas between the constants.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print PUSHCOLOR BLUE "Text\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
will correctly push BLUE onto the top of the stack.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print PUSHCOLOR, BLUE, "Text\n"; # wrong!
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
will not, and a subsequent pop won't restore the correct attributes.
|
|
Packit Service |
d987f3 |
PUSHCOLOR pushes the attributes set by its argument, which is normally a
|
|
Packit Service |
d987f3 |
string of color constants. It can't ask the terminal what the current
|
|
Packit Service |
d987f3 |
attributes are.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 DIAGNOSTICS
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=over 4
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Bad color mapping %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(W) The specified color mapping from ANSI_COLORS_ALIASES is not valid and
|
|
Packit Service |
d987f3 |
could not be parsed. It was ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Bad escape sequence %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) You passed an invalid ANSI escape sequence to uncolor().
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Bareword "%s" not allowed while "strict subs" in use
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) You probably mistyped a constant color name such as:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
$Foobar = FOOBAR . "This line should be blue\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
or:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
@Foobar = FOOBAR, "This line should be blue\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This will only show up under use strict (another good reason to run under
|
|
Packit Service |
d987f3 |
use strict).
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Cannot alias standard color %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) The alias name passed to coloralias() matches a standard color name.
|
|
Packit Service |
d987f3 |
Standard color names cannot be aliased.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Cannot alias standard color %s in %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(W) The same, but in ANSI_COLORS_ALIASES. The color mapping was ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Invalid alias name %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) You passed an invalid alias name to coloralias(). Alias names must
|
|
Packit Service |
d987f3 |
consist only of alphanumerics, C<.>, C<->, and C<_>.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Invalid alias name %s in %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(W) You specified an invalid alias name on the left hand of the equal sign
|
|
Packit Service |
d987f3 |
in a color mapping in ANSI_COLORS_ALIASES. The color mapping was ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Invalid attribute name %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) You passed an invalid attribute name to color(), colored(), or
|
|
Packit Service |
d987f3 |
coloralias().
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Invalid attribute name %s in %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(W) You specified an invalid attribute name on the right hand of the equal
|
|
Packit Service |
d987f3 |
sign in a color mapping in ANSI_COLORS_ALIASES. The color mapping was
|
|
Packit Service |
d987f3 |
ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item Name "%s" used only once: possible typo
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(W) You probably mistyped a constant color name such as:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print FOOBAR "This text is color FOOBAR\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
It's probably better to always use commas after constant names in order to
|
|
Packit Service |
d987f3 |
force the next error.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item No comma allowed after filehandle
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) You probably mistyped a constant color name such as:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print FOOBAR, "This text is color FOOBAR\n";
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Generating this fatal compile error is one of the main advantages of using
|
|
Packit Service |
d987f3 |
the constants interface, since you'll immediately know if you mistype a
|
|
Packit Service |
d987f3 |
color name.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item No name for escape sequence %s
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
(F) The ANSI escape sequence passed to uncolor() contains escapes which
|
|
Packit Service |
d987f3 |
aren't recognized and can't be translated to names.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=back
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 ENVIRONMENT
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=over 4
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item ANSI_COLORS_ALIASES
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This environment variable allows the user to specify custom color aliases
|
|
Packit Service |
d987f3 |
that will be understood by color(), colored(), and colorvalid(). None of
|
|
Packit Service |
d987f3 |
the other functions will be affected, and no new color constants will be
|
|
Packit Service |
d987f3 |
created. The custom colors are aliases for existing color names; no new
|
|
Packit Service |
d987f3 |
escape sequences can be introduced. Only alphanumerics, C<.>, C<_>, and
|
|
Packit Service |
d987f3 |
C<-> are allowed in alias names.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The format is:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ANSI_COLORS_ALIASES='newcolor1=oldcolor1,newcolor2=oldcolor2'
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Whitespace is ignored.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
For example the L<Solarized|http://ethanschoonover.com/solarized> colors
|
|
Packit Service |
d987f3 |
can be mapped with:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ANSI_COLORS_ALIASES='\
|
|
Packit Service |
d987f3 |
base00=bright_yellow, on_base00=on_bright_yellow,\
|
|
Packit Service |
d987f3 |
base01=bright_green, on_base01=on_bright_green, \
|
|
Packit Service |
d987f3 |
base02=black, on_base02=on_black, \
|
|
Packit Service |
d987f3 |
base03=bright_black, on_base03=on_bright_black, \
|
|
Packit Service |
d987f3 |
base0=bright_blue, on_base0=on_bright_blue, \
|
|
Packit Service |
d987f3 |
base1=bright_cyan, on_base1=on_bright_cyan, \
|
|
Packit Service |
d987f3 |
base2=white, on_base2=on_white, \
|
|
Packit Service |
d987f3 |
base3=bright_white, on_base3=on_bright_white, \
|
|
Packit Service |
d987f3 |
orange=bright_red, on_orange=on_bright_red, \
|
|
Packit Service |
d987f3 |
violet=bright_magenta,on_violet=on_bright_magenta'
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This environment variable is read and applied when the Term::ANSIColor
|
|
Packit Service |
d987f3 |
module is loaded and is then subsequently ignored. Changes to
|
|
Packit Service |
d987f3 |
ANSI_COLORS_ALIASES after the module is loaded will have no effect. See
|
|
Packit Service |
d987f3 |
coloralias() for an equivalent facility that can be used at runtime.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=item ANSI_COLORS_DISABLED
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
If this environment variable is set to a true value, all of the functions
|
|
Packit Service |
d987f3 |
defined by this module (color(), colored(), and all of the constants not
|
|
Packit Service |
d987f3 |
previously used in the program) will not output any escape sequences and
|
|
Packit Service |
d987f3 |
instead will just return the empty string or pass through the original
|
|
Packit Service |
d987f3 |
text as appropriate. This is intended to support easy use of scripts
|
|
Packit Service |
d987f3 |
using this module on platforms that don't support ANSI escape sequences.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=back
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 COMPATIBILITY
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Term::ANSIColor was first included with Perl in Perl 5.6.0.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The uncolor() function and support for ANSI_COLORS_DISABLED were added in
|
|
Packit Service |
d987f3 |
Term::ANSIColor 1.04, included in Perl 5.8.0.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Support for dark was added in Term::ANSIColor 1.08, included in Perl
|
|
Packit Service |
d987f3 |
5.8.4.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The color stack, including the C<:pushpop> import tag, PUSHCOLOR,
|
|
Packit Service |
d987f3 |
POPCOLOR, LOCALCOLOR, and the $Term::ANSIColor::AUTOLOCAL variable, was
|
|
Packit Service |
d987f3 |
added in Term::ANSIColor 2.00, included in Perl 5.10.1.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
colorstrip() was added in Term::ANSIColor 2.01 and colorvalid() was added
|
|
Packit Service |
d987f3 |
in Term::ANSIColor 2.02, both included in Perl 5.11.0.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Support for colors 8 through 15 (the C<bright_> variants) was added in
|
|
Packit Service |
d987f3 |
Term::ANSIColor 3.00, included in Perl 5.13.3.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Support for italic was added in Term::ANSIColor 3.02, included in Perl
|
|
Packit Service |
d987f3 |
5.17.1.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Support for colors 16 through 256 (the C<ansi>, C<rgb>, and C<grey>
|
|
Packit Service |
d987f3 |
colors), the C<:constants256> import tag, the coloralias() function, and
|
|
Packit Service |
d987f3 |
support for the ANSI_COLORS_ALIASES environment variable were added in
|
|
Packit Service |
d987f3 |
Term::ANSIColor 4.00, included in Perl 5.17.8.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
$Term::ANSIColor::AUTOLOCAL was changed to take precedence over
|
|
Packit Service |
d987f3 |
$Term::ANSIColor::AUTORESET, rather than the other way around, in
|
|
Packit Service |
d987f3 |
Term::ANSIColor 4.00, included in Perl 5.17.8.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
C<ansi16> through C<ansi255>, as aliases for the C<rgb> and C<grey>
|
|
Packit Service |
d987f3 |
colors, and the corresponding C<on_ansi> names and C<ANSI> and C<ON_ANSI>
|
|
Packit Service |
d987f3 |
constants, were added in Term::ANSIColor 4.06.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 RESTRICTIONS
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
It would be nice if one could leave off the commas around the constants
|
|
Packit Service |
d987f3 |
entirely and just say:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
print BOLD BLUE ON_WHITE "Text\n" RESET;
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
but the syntax of Perl doesn't allow this. You need a comma after the
|
|
Packit Service |
d987f3 |
string. (Of course, you may consider it a bug that commas between all the
|
|
Packit Service |
d987f3 |
constants aren't required, in which case you may feel free to insert
|
|
Packit Service |
d987f3 |
commas unless you're using $Term::ANSIColor::AUTORESET or
|
|
Packit Service |
d987f3 |
PUSHCOLOR/POPCOLOR.)
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
For easier debugging, you may prefer to always use the commas when not
|
|
Packit Service |
d987f3 |
setting $Term::ANSIColor::AUTORESET or PUSHCOLOR/POPCOLOR so that you'll
|
|
Packit Service |
d987f3 |
get a fatal compile error rather than a warning.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
It's not possible to use this module to embed formatting and color
|
|
Packit Service |
d987f3 |
attributes using Perl formats. They replace the escape character with a
|
|
Packit Service |
d987f3 |
space (as documented in L<perlform(1)>), resulting in garbled output from
|
|
Packit Service |
d987f3 |
the unrecognized attribute. Even if there were a way around that problem,
|
|
Packit Service |
d987f3 |
the format doesn't know that the non-printing escape sequence is
|
|
Packit Service |
d987f3 |
zero-length and would incorrectly format the output. For formatted output
|
|
Packit Service |
d987f3 |
using color or other attributes, either use sprintf() instead or use
|
|
Packit Service |
d987f3 |
formline() and then add the color or other attributes after formatting and
|
|
Packit Service |
d987f3 |
before output.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 NOTES
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The codes generated by this module are standard terminal control codes,
|
|
Packit Service |
d987f3 |
complying with ECMA-048 and ISO 6429 (generally referred to as "ANSI
|
|
Packit Service |
d987f3 |
color" for the color codes). The non-color control codes (bold, dark,
|
|
Packit Service |
d987f3 |
italic, underline, and reverse) are part of the earlier ANSI X3.64
|
|
Packit Service |
d987f3 |
standard for control sequences for video terminals and peripherals.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Note that not all displays are ISO 6429-compliant, or even X3.64-compliant
|
|
Packit Service |
d987f3 |
(or are even attempting to be so). This module will not work as expected
|
|
Packit Service |
d987f3 |
on displays that do not honor these escape sequences, such as cmd.exe,
|
|
Packit Service |
d987f3 |
4nt.exe, and command.com under either Windows NT or Windows 2000. They
|
|
Packit Service |
d987f3 |
may just be ignored, or they may display as an ESC character followed by
|
|
Packit Service |
d987f3 |
some apparent garbage.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Jean Delvare provided the following table of different common terminal
|
|
Packit Service |
d987f3 |
emulators and their support for the various attributes and others have
|
|
Packit Service |
d987f3 |
helped me flesh it out:
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
clear bold faint under blink reverse conceal
|
|
Packit Service |
d987f3 |
------------------------------------------------------------------------
|
|
Packit Service |
d987f3 |
xterm yes yes no yes yes yes yes
|
|
Packit Service |
d987f3 |
linux yes yes yes bold yes yes no
|
|
Packit Service |
d987f3 |
rxvt yes yes no yes bold/black yes no
|
|
Packit Service |
d987f3 |
dtterm yes yes yes yes reverse yes yes
|
|
Packit Service |
d987f3 |
teraterm yes reverse no yes rev/red yes no
|
|
Packit Service |
d987f3 |
aixterm kinda normal no yes no yes yes
|
|
Packit Service |
d987f3 |
PuTTY yes color no yes no yes no
|
|
Packit Service |
d987f3 |
Windows yes no no no no yes no
|
|
Packit Service |
d987f3 |
Cygwin SSH yes yes no color color color yes
|
|
Packit Service |
d987f3 |
Terminal.app yes yes no yes yes yes yes
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Windows is Windows telnet, Cygwin SSH is the OpenSSH implementation under
|
|
Packit Service |
d987f3 |
Cygwin on Windows NT, and Mac Terminal is the Terminal application in Mac
|
|
Packit Service |
d987f3 |
OS X. Where the entry is other than yes or no, that emulator displays the
|
|
Packit Service |
d987f3 |
given attribute as something else instead. Note that on an aixterm, clear
|
|
Packit Service |
d987f3 |
doesn't reset colors; you have to explicitly set the colors back to what
|
|
Packit Service |
d987f3 |
you want. More entries in this table are welcome.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Support for code 3 (italic) is rare and therefore not mentioned in that
|
|
Packit Service |
d987f3 |
table. It is not believed to be fully supported by any of the terminals
|
|
Packit Service |
d987f3 |
listed, although it's displayed as green in the Linux console, but it is
|
|
Packit Service |
d987f3 |
reportedly supported by urxvt.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Note that codes 6 (rapid blink) and 9 (strike-through) are specified in
|
|
Packit Service |
d987f3 |
ANSI X3.64 and ECMA-048 but are not commonly supported by most displays
|
|
Packit Service |
d987f3 |
and emulators and therefore aren't supported by this module at the present
|
|
Packit Service |
d987f3 |
time. ECMA-048 also specifies a large number of other attributes,
|
|
Packit Service |
d987f3 |
including a sequence of attributes for font changes, Fraktur characters,
|
|
Packit Service |
d987f3 |
double-underlining, framing, circling, and overlining. As none of these
|
|
Packit Service |
d987f3 |
attributes are widely supported or useful, they also aren't currently
|
|
Packit Service |
d987f3 |
supported by this module.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Most modern X terminal emulators support 256 colors. Known to not support
|
|
Packit Service |
d987f3 |
those colors are aterm, rxvt, Terminal.app, and TTY/VC.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 AUTHORS
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Original idea (using constants) by Zenin, reimplemented using subs by Russ
|
|
Packit Service |
d987f3 |
Allbery <rra@cpan.org>, and then combined with the original idea by
|
|
Packit Service |
d987f3 |
Russ with input from Zenin. 256-color support is based on work by Kurt
|
|
Packit Service |
d987f3 |
Starsinic. Russ Allbery now maintains this module.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
PUSHCOLOR, POPCOLOR, and LOCALCOLOR were contributed by openmethods.com
|
|
Packit Service |
d987f3 |
voice solutions.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 COPYRIGHT AND LICENSE
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Copyright 1996 Zenin
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2005, 2006, 2008, 2009, 2010,
|
|
Packit Service |
d987f3 |
2011, 2012, 2013, 2014, 2015, 2016 Russ Allbery <rra@cpan.org>
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
Copyright 2012 Kurt Starsinic <kstarsinic@gmail.com>
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
This program is free software; you may redistribute it and/or modify it
|
|
Packit Service |
d987f3 |
under the same terms as Perl itself.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=head1 SEE ALSO
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The CPAN module L<Term::ExtendedColor> provides a different and more
|
|
Packit Service |
d987f3 |
comprehensive interface for 256-color emulators that may be more
|
|
Packit Service |
d987f3 |
convenient. The CPAN module L<Win32::Console::ANSI> provides ANSI color
|
|
Packit Service |
d987f3 |
(and other escape sequence) support in the Win32 Console environment.
|
|
Packit Service |
d987f3 |
The CPAN module L<Term::Chrome> provides a different interface using
|
|
Packit Service |
d987f3 |
objects and operator overloading.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ECMA-048 is available on-line (at least at the time of this writing) at
|
|
Packit Service |
d987f3 |
L<http://www.ecma-international.org/publications/standards/Ecma-048.htm>.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
ISO 6429 is available from ISO for a charge; the author of this module
|
|
Packit Service |
d987f3 |
does not own a copy of it. Since the source material for ISO 6429 was
|
|
Packit Service |
d987f3 |
ECMA-048 and the latter is available for free, there seems little reason
|
|
Packit Service |
d987f3 |
to obtain the ISO standard.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The 256-color control sequences are documented at
|
|
Packit Service |
d987f3 |
L<http://invisible-island.net/xterm/ctlseqs/ctlseqs.html> (search for
|
|
Packit Service |
d987f3 |
256-color).
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
The current version of this module is always available from its web site
|
|
Packit Service |
d987f3 |
at L<https://www.eyrie.org/~eagle/software/ansicolor/>. It is also part
|
|
Packit Service |
d987f3 |
of the Perl core distribution as of 5.6.0.
|
|
Packit Service |
d987f3 |
|
|
Packit Service |
d987f3 |
=cut
|