Term::ANSIColorx::AutoFilterFH - automatically color-highlight a stream
use Term::ANSIColorx::ColorNicknames; # optional use Term::ANSIColorx::AutoFilterFH qw(filtered_handle); my $filtered_stdout = filtered_handle(\*STDOUT, 'jettero' => 'bold-blue', 'nobody' => 'sky', # same as jettero under ColorNicks, or error 'root' => 'red', ); print "This has colors: jettero nobody root\n"; select $filtered_stdout; print "This also has colors. -jettero\n"; $filtered_stdout->set_truncate(80); print "This line is only 80 characters... ", ("." x 120), "\n";
I wanted a way to inject colors into places that didn't otherwise support it. I also wanted to make my hi utility as short as possible -- and it worked. hi is barely three lines, not including the options.
filter_handle()
This function returns a tied handle with some magic installed. You can print to it and select it. It has one method you can invoke as well.
set_truncate()
Use this method to set a characters-per-line limit. Give it an undef or a 0 to disable it again. Caveat: The truncator assumes input to PRINT() is a line and as such, the results will seem incorrect when the printing non-lines. For example, this will not work right:
undef
0
PRINT()
$truncated_handle->set_truncate(80) select $truncated_handle; print "neato: ", ("." x 120); # this will gain a newline at char 81 print "\n";
Q: You don't seem to understand Tie::Handle, shouldn't you fix it using my immense knowledge of perl FH globs?
A: You got that right -- although the module functions correctly -- if you want to help, let me know, or fork the project on github.
You can report bugs either via rt.cpan.org or via the issue tracking system on github. I'm likely to notice either fairly quickly.
Paul Miller <jettero@cpan.org>
<jettero@cpan.org>
Copyright 2009 Paul Miller -- released under the GPL
perl(1), Term::ANSIColor, Tie::Handle
To install Term::ANSIColorx::ColorNicknames, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::ANSIColorx::ColorNicknames
CPAN shell
perl -MCPAN -e shell install Term::ANSIColorx::ColorNicknames
For more information on module installation, please visit the detailed CPAN module installation guide.