The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Template::Plugin::Filter::ANSIColor - colorizes text using ANSI colors

VERSION

Version 0.03

SYNOPSIS

This is a Template Toolkit filter that colors the text using Term::ANSIColor. It works on terminals that support at least 8 colors.

        use Template;
        
        my $engine = Template->new(
                PLUGIN_BASE => 'Template::Plugin::Filter'
        ) || die Template->error();

        $engine->process(\*DATA)
                || die $engine->error();
                
        __DATA__
        [% USE ANSIColor 'color' %]
        [% "this is red on bright yellow " | color 'red' 'on_bright_yellow' %]
        [% "this is simply green " | color 'green' %]
        [% "this is default on bright magenta" | color 'on_bright_magenta' %]
        [% "this is default on deault since nocolor=1" | color 'red' nocolor = 1 %]             

METHODS

init

This method is invoked when Template Toolkit finds a directive [% USE ANSIColor 'color' %]. The argument 'color' is the name for the filter. You may change it if you need. It has an option 'nocolor', which turns off colors (filter will not modify the text). Probably you would like to use it the following way:

        # .....
        $engine->process(\*DATA, { colors_off => 1 })
                || die $engine->error();
        
        __DATA__
        [% USE ANSIColor 'color' nocolor = colors_off %]
        ...

See 'TO COLOR OR NOT TO COLOR' below

filter

This is the filter itself. It returns colored text if colors are not turned off. It accepts one or two parameters, the foreground and/or background color names. You may also use nocolor option. See SYNOPSIS above. See TO COLOR OR NOT TO COLOR.

TO COLOR OR NOT TO COLOR

Text is not modified if

  • nocolor option is on

  • Term::Terminfo says that the maximum number of colors supported by current terminal is less than 8 or undefined.

SEE ALSO

AUTHOR

"Andrei V. Toutoukine", <"tut at isuct.ru">

BUGS

Please report any bugs or feature requests to bug-template-plugin-filter-ansicolor at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Plugin-Filter-ANSIColor. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

    perldoc Template::Plugin::Filter::ANSIColor

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright 2011 "Andrei V. Toutoukine".

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; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.