NAME

Text::Colorizer - Create colored text from text and color descrition. An ANSI to HTML tranformation is provided

SYNOPSIS

  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',
		COLORS => 
			{
			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'
			   ) ;

DESCRIPTION

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.

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

#256 colors terminals
rgbRGB on_rgbRGB
greyX  on_greyX

SUBROUTINES/METHODS

new(NAMED_ARGUMENTS)

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; '} ;
  • COLORS - 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

Setup

Helper sub called by new. This is a private sub.

GetDefaultColor

CheckOptionNames

Verifies the named options passed to the members of this class. Calls {INTERACTION}{DIE} in case of error. This shall not be used directly.

get_colors( )

Returns the colors defined in the object

my $colors = $c->get_colors( ) ;

Arguments - None

Returns - A hash reference

Exceptions - None

set_colors(\%colors)

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

[P] flatten($scalar || \@array)

Transforms array references to a flat list

Arguments -

  • $scalar -

Returns - a lsit of scalars

color($color_name, $text, $color_name, \@many_text_strings, ...) ;

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

color_all($color, $string, \@many_text_strings, ...)

Uses a single color to colorize all the strings

my $colored_text = $c->color_all($color, $string, \@many_text_strings, ...) ;

Arguments

  • $xxx -

Returns - Nothing

Exceptions

color_with(\%color_definitions, 'color' => 'text', $color => \@many_text_strings, ...) ;

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_with
			   (
			   \%colors, 
			   'red on_black' => 'string',
			   'blue on_yellow' => [... many strings..]
			   'user_defined_color_name' => 'string'
			   ) ;

Arguments

  • $ -

  • $color -

  • $xxx -

Returns - Nothing

Exceptions - Dies if any argument is invalid

color_all_with($temporary_colors, $color, $text | \@many_text_string, ...) ;

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..], ...) ;

Arguments

  • $xxx -

Returns - A colorized string

Exceptions Dies if invalid input is received

BUGS AND LIMITATIONS

None so far.

AUTHOR

Nadim ibn hamouda el Khemir
CPAN ID: NKH
mailto: nadim@cpan.org

COPYRIGHT & LICENSE

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Text::Colorizer

You can also look for information at:

SEE ALSO

"HTML::FromANSI first"