Text::Colorizer - Create colored text from text and color descrition. An ANSI to HTML tranformation is provided
my $c= Text::Colorizer->new ( NAME => '' , INTERACTION => { INFO => sub {print @_}, WARN => \&Carp::carp, DIE => \&Carp::confess, } FORMAT => 'HTML' | 'ANSI' |'ASCII', DEFAULT_COLOR => 'bright_white on_black', COLOR_NAMES => { HTML => { white => "color:#888;", black => "color:#000;", ... } ANSI => ... ASCII => ... } ) ; # or my $c= Text::Colorizer->new() ; my $colored_text = $c->color ( 'red on_black' => 'string', $color => [... many strings..], 'user_defined_color_name' => 'string' ) ;
This module defined methods to produce colored html from ANSI color description. The generated code use pre tags. The generated HTML can be embeded in your pod documentation.
Valid colors:
black red green yellow blue magenta cyan white bright_black bright_red bright_green bright_yellow bright_blue bright_magenta bright_cyan bright_white on_black on_red on_green on yellow on_blue on_magenta on_cyan on_white on_bright_black on_bright_red on_bright_green on_bright_yellow on_bright_blue on_bright_magenta on_bright_cyan on_bright_white
on_white on_black on_green on_yellow on_cyan on_red on_blue on_magenta white text text text text text text text text black text text text text text text text text green text text text text text text text text yellow text text text text text text text text cyan text text text text text text text text red text text text text text text text text blue text text text text text text text text magenta text text text text text text text text bright_white text text text text text text text text bright_black text text text text text text text text bright_green text text text text text text text text bright_yellow text text text text text text text text bright_cyan text text text text text text text text bright_red text text text text text text text text bright_blue text text text text text text text text bright_magenta text text text text text text text text on_bright_white on_bright_black on_bright_green on_bright_yellowon_bright_cyan on_bright_red on_bright_blue on_bright_magent white text text text text text text text text black text text text text text text text text green text text text text text text text text yellow text text text text text text text text cyan text text text text text text text text red text text text text text text text text blue text text text text text text text text magenta text text text text text text text text bright_white text text text text text text text text bright_black text text text text text text text text bright_green text text text text text text text text bright_yellow text text text text text text text text bright_cyan text text text text text text text text bright_red text text text text text text text text bright_blue text text text text text text text text bright_magenta text text text text text text text text
bright_white on_black
Create a Text::Colorizer object.
my $c= Text::Colorizer->new() ;
Arguments - a list of pairs - Option => Value
NAME - String - Name of the Data::HexDump::Range object, set to 'Anonymous' by default
INTERACTION - Hash reference - Set of subs that are used to display information to the user
Useful if you use Data::HexDump::Range in an application without terminal.
VERBOSE - Boolean - Display information about the creation of the object. Default is false
JOIN - String - string used to join colored elements. Default is an empty string.
JOIN_FLAT - String - string used to join colored elements passed in array references. Default is an empty string.
FORMAT - String - format of the dump string generated by Data::HexDump::Range.
Default is ANSI which allows for colors. Other formats are 'ASCII' and 'HTML'.
DEFAULT_COLOR - the color used if no color is defined
DEFAULT_COLOR => {ANSI => 'bright_white', HTML => 'color:#aaa; '} ;
COLOR - String 'bw' or 'cycle'.
Ranges for which no color has been defined, in 'ANSI' or 'HTML' format mode, will be rendered in black and white or with a color picked from a cyclic color list. Default is 'bw'.
COLOR_NAMES - A hash reference or a file name
{ HTML => { white => "color:#888;", black => "color:#000;", ... } ANSI => ... ASCII => ... }
Returns - Text::Colorizer
Exceptions - Dies if the color description are not valid
Helper sub called by new. This is a private sub.
Verifies the named options passed to the members of this class. Calls {INTERACTION}{DIE} in case of error. This shall not be used directly.
Returns the colors defined in the object
my $colors = $c->get_colors( ) ;
Arguments - None
Returns - A hash reference
Exceptions - None
Copies
my %colors = ( HTML => { white => "style='color:#888;'", black => "style='color:#000;'", ... bright_white => "style='color:#fff;'", bright_black => "style='color:#000;'", bright_green => "style='color:#0f0;'", ... } ) ; $c->set_color(\%colors) ;
Arguments
\%colors - A hash reference
Returns - Nothing
Exceptions - dies if the color definitions are invalid
Transforms array references to a flat list
Arguments -
$scalar -
Returns - a lsit of scalars
Returns colored text. according to the object setting. Default is HTML color coded.
my $colored_text = $c->color ( 'red on_black' => 'string', $color => [... many strings..] 'user_defined_color_name' => 'string' ) ;
Arguments - A list of colors and text pairs
$color -
$text -
Returns - A single string
Exceptions - Dies if the color is invalid
Uses a single color to colorize all the strings
my $colored_text = $c->color_all($color, $string, \@many_text_strings, ...) ;
$xxx -
Exceptions
Colors a text, temporarely overridding the colors defined in the object.
my %colors = { HTML => { white => "style='color:#888;'", black => "style='color:#000;'", ... bright_white => "style='color:#fff;'", bright_black => "style='color:#000;'", bright_green => "style='color:#0f0;'", ... } }, my $colored_text = $c->color ( 'red on_black' => 'string', 'blue on_yellow' => [... many strings..] 'user_defined_color_name' => 'string' ) ;
$ -
Exceptions - Dies if any argument is invalid
Uses a single color to colorize all the strings, using a temporary color definition
my $temporary_colors = { HTML => { white => "style='color:#888;'", black => "style='color:#000;'", ... bright_white => "style='color:#fff;'", bright_black => "style='color:#000;'", bright_green => "style='color:#0f0;'", ... } }, my $colored_text = $c->color_all_with($temporary_colors, $color, 'string', [... many strings..], ...) ;
Returns - A colorized string
Exceptions Dies if invalid input is received
None so far.
Nadim ibn hamouda el Khemir CPAN ID: NKH mailto: nadim@cpan.org
Copyright 2010 Nadim Khemir.
This program is free software; you can redistribute it and/or modify it under the terms of either:
the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or
the Artistic License version 2.0.
You can find documentation for this module with the perldoc command.
perldoc Text::Colorizer
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Color::ANSI-ToHTML
RT: CPAN's request tracker
Please report any bugs or feature requests to L <bug-Color::ANSI-tohtml@rt.cpan.org>.
We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
Search CPAN
http://search.cpan.org/dist/Color::ANSI-ToHTML
"HTML::FromANSI first"
To install Text::Colorizer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Colorizer
CPAN shell
perl -MCPAN -e shell install Text::Colorizer
For more information on module installation, please visit the detailed CPAN module installation guide.