tail colorize
[p5sagit/IO-Pipeline.git] / lib / IO / Pipeline.pm
index 48aa238..165dadb 100644 (file)
@@ -11,7 +11,7 @@ our @ISA = qw(Exporter);
 
 our @EXPORT = qw(pmap pgrep psink);
 
-our $VERSION = '0.009001'; # 0.9.1
+our $VERSION = '0.009002'; # 0.9.2
 
 $VERSION = eval $VERSION;
 
@@ -191,7 +191,7 @@ the pipe to the output until the input filehandle is exhausted.
 Non-completed pipeline objects are completely re-usable though - so you can
 (and are expected to) do things like:
 
-  my $combined_to_stoud = $combined | \*STDOUT;
+  my $combined_to_stdout = $combined | \*STDOUT;
   
   foreach my $file (@files_to_process) {
   
@@ -327,19 +327,44 @@ 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<STDIN>, 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<Win32::Console::ANSI> to
+make the colors work and L<tail> 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) <mst@shadowcat.co.uk>
 
-=head2 CONTRIBUTORS
+=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 <frioux@gmail.com>
 
 =head1 COPYRIGHT
 
-Copyright (c) 2010 the App::FatPacker L</AUTHOR> and L</CONTRIBUTORS>
+Copyright (c) 2010 the IO::Pipeline L</AUTHOR> and L</CONTRIBUTORS>
 as listed above.
 
 =head1 LICENSE