Template::Plugin::Filter::ANSIColor - colorizes text using ANSI colors
Version 0.03
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 %]
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
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.
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.
Template
Term::ANSIColor
Term::Terminfo
Template::Plugin::Filter
"Andrei V. Toutoukine", <"tut at isuct.ru">
<"tut at isuct.ru">
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.
bug-template-plugin-filter-ansicolor at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Template::Plugin::Filter::ANSIColor
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-Filter-ANSIColor
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Template-Plugin-Filter-ANSIColor
CPAN Ratings
http://cpanratings.perl.org/d/Template-Plugin-Filter-ANSIColor
Search CPAN
http://search.cpan.org/dist/Template-Plugin-Filter-ANSIColor/
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.
To install Template::Plugin::Filter::ANSIColor, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Plugin::Filter::ANSIColor
CPAN shell
perl -MCPAN -e shell install Template::Plugin::Filter::ANSIColor
For more information on module installation, please visit the detailed CPAN module installation guide.