App-highlight
view release on metacpan or search on metacpan
lib/App/highlight.pm view on Meta::CPAN
my $ignore_case = '';
if ($opt->{'ignore_case'}) {
if ($^V lt v5.14.0) {
$ignore_case = '(?i)';
}
else {
$ignore_case = '(?^i)';
}
}
while (<STDIN>) {
my $i = 0;
foreach my $m (@matches) {
if ($opt->{'full_line'}) {
if (m/${ignore_case}$m/) {
s/^/$HIGHLIGHTS[$i][0]/;
s/$/$HIGHLIGHTS[$i][1]/;
}
}
else {
s/(${ignore_case}$m)/$HIGHLIGHTS[$i][0] . $1 . $HIGHLIGHTS[$i][1]/ge;
}
$i++;
$i %= @HIGHLIGHTS;
}
if ($opt->{'show_bad_spaces'}) {
if ($opt->{'color'} || !$opt->{'no_color'}) {
s{(\s+)(?=$/)$}{colored($1, "white on_red")}e;
#s{(\s+)(?=$/)$}{"[start-red]" . $1 . "[end-red]"}e;
}
else {
s{(\s+)(?=$/)$}{"X" x length($1)}e;
}
}
print;
}
return;
}
1;
__END__
=head1 NAME
App::highlight - simple grep-like highlighter app
=head1 VERSION
version 0.14
=head1 SYNOPSIS
=begin html
<a href="https://travis-ci.org/kaoru/App-highlight"><img src="https://travis-ci.org/kaoru/App-highlight.png" /></a>
=end html
highlight is similar to grep, except that instead of removing
non-matched lines it simply highlights words or lines which are
matched.
% cat words.txt
foo
bar
baz
qux
quux
corge
% cat words.txt | grep ba
bar
baz
% cat words.txt | highlight ba
foo
<<ba>>r
<<ba>>z
qux
quux
corge
If you give multiple match parameters highlight will highlight each of them in
a different color.
% cat words.txt | highlight ba qu
foo
<<ba>>r
<<ba>>z
[[qu]]x
[[qu]]ux
corge
=head1 Color Support
If you have Term::ANSIColor installed then the strings will be highlighted
using terminal colors rather than using brackets.
Installing color support by installing Term::ANSIColor is highly reccommended.
To get color support on Microsoft Windows you should install Term::ANSIColor
and Win32::Console::ANSI.
=head1 OPTIONS
=head2 color / c
This is the default if Term::ANSIColor is installed.
App::highlight will cycle through the colours:
red green yellow blue magenta cyan
If you do not have Term::ANSIColor installed and you specify --color or you do
not specify --no-color then you will receive a warning.
( run in 2.771 seconds using v1.01-cache-2.11-cpan-788537b7465 )