On Thu, Sep 4, 2008 at 4:17 PM, Shlomi Fish <[EMAIL PROTECTED]> wrote:
> On Thursday 04 September 2008, Amos Shapira wrote: > > 2008/9/4 Amos Shapira <[EMAIL PROTECTED]>: > > > 2008/9/4 Maxim Veksler <[EMAIL PROTECTED]>: > > >> That would actually be great and is exactly the kind of solution I'm > > >> searching for. The only problem with the grep --color apporoach is > > >> that It would only show me the lines that contain the search term. I > > >> want to see the whole scrolling log and highlight what interested me. > > > > Also, a quick CPAN search turned up > > http://search.cpan.org/~rra/ANSIColor-1.12/ANSIColor.pm > > If you are a Perl programmer, I'd reckon a 15 minute work will get you > > what you want (but I don't have them right now to do this for you, > > sorry). > > Here's a Proof-of-Concept script I wrote to implement this: > > <<<<<<<<<<<< > #!/usr/bin/perl > > # Written by Shlomi Fish - http://www.shlomifish.org/ - 2008 > # Licensed under the MIT/X11 License. > # > # Example: > # perl color-patterns.pl --pat hello=red --pat '(?i:maxim)'=blue > > use strict; > use warnings; > > use Getopt::Long; > use Term::ANSIColor; > > my %patterns; > GetOptions("pat=s" => \%patterns); > > my @p; > while (my ($k, $v) = each (%patterns)) > { > push @p, { pat => qr{$k}, color => $v }; > } > > while (my $l = <>) > { > foreach my $pat (@p) > { > my $re = $pat->{pat}; > my $c = $pat->{color}; > $l =~ s/($re)/colored($1, $c)/eg; > } > print $l; > } > >>>>>>>>>>>>>>>> > > Regards, > > Shlomi Fish > > ----------------------------------------------------------------- > Shlomi Fish http://www.shlomifish.org/ > Why I Love Perl - http://xrl.us/bjn88 > > Shlomi, so what are you working on? Working on a new wiki about unit > testing > fortunes in freecell? -- Ran Eilam > > I mainly write in Python / Java but the above work from Shlomi is just great !This is exactly what I've been after, quick dirty and works. Thanks a-lot !! Shlomi and Amos -- You are the man's ;) // OT Note: I must admit that to some one who is accustomed to logic... the above code is completely unreadable. Could someone please explain where in the above code the ANSI module / method / operator / what ever they do in Perl... is called to the actually coloring that was read from stdin? -- Cheers, Maxim Veksler "Free as in Freedom" - Do u GNU ?