From: Arthur Axel 'fREW' Schmidt Date: Tue, 6 Jul 2010 19:56:48 +0000 (-0500) Subject: tail colorize X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FIO-Pipeline.git;a=commitdiff_plain;h=eef5e44f3ea35cc476b6fdbbd0299b4cbdcae3fb tail colorize --- diff --git a/Changes b/Changes index fb9545d..a612ba5 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Add "COOL EXAMPLES" section to the doc - various minor documentation fixes 0.009002 2010-04-04 diff --git a/lib/IO/Pipeline.pm b/lib/IO/Pipeline.pm index 55a1fcd..165dadb 100644 --- a/lib/IO/Pipeline.pm +++ b/lib/IO/Pipeline.pm @@ -327,15 +327,40 @@ a variable so that we can examine the results: | psink { $out .= $_ }; +=head1 COOL EXAMPLES + +=head2 tail colorize + +The following example simply colors the lines that match a given regular +expression. It watches C, so the typical usage would be + + tail -f foo | perl tail-color.pl + +If you are on a Windows system take a look at L to +make the colors work and L for a pure-Perl implementation of tail. + + use IO::Pipeline; + use Term::ANSIColor; + + my $reset = color 'reset'; + + sub colorize { + my ($regex, $color) = @_; + pmap { return colored([$color], $_) if $_ =~ $regex; $_ } + } + +\*STDIN | + colorize(qr/^INFO: .*$/, 'blue') | + colorize(qr/^HELP: .*$/, 'bright_red on_magenta') | +\*STDOUT; + =head1 AUTHOR Matt S. Trout (mst) =head1 CONTRIBUTORS -None as yet, though I'm sure that'll change as soon as people spot the -giant gaping holes that inevitably exist in any software only used by -the author so far. +frew: Arthr Axel "fREW" Schmidt =head1 COPYRIGHT