X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FIO-Pipeline.git;a=blobdiff_plain;f=lib%2FIO%2FPipeline.pm;fp=lib%2FIO%2FPipeline.pm;h=165dadbecc864890bbf49a1d3a3b08a915ec1c2b;hp=55a1fcd232510ef6fd17282724426741ae3d4cef;hb=eef5e44f3ea35cc476b6fdbbd0299b4cbdcae3fb;hpb=d6633b53653929a2b8ba1b2c565c13b3061c7243 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