#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Getopt::Long qw(HelpMessage VersionMessage); | |
our $VERSION = '0.01'; | |
$VERSION = eval $VERSION; | |
Getopt::Long::Configure('bundling', 'no_ignore_case', 'auto_help', 'auto_version'); | |
GetOptions( | |
\my %opts, | |
'k', # word color is black | |
'K', # background color is black | |
'r', # word color is red | |
'R', # background color is red | |
'g', # word color is green | |
'G', # background color is green | |
'y', # word color is yellow | |
'Y', # background color is yellow | |
'b', # word color is blue | |
'B', # background color is blue | |
'p', # word color is purple | |
'P', # background color is purple | |
'l', # word color is light blue | |
'L', # background color is light blue | |
'w', # word color is white | |
'W', # background color is white | |
# 'return', | |
'strong', | |
# 'perpendicular', | |
'underscore|u', # `u' is enabled for short hand | |
'blink', | |
'reverse', | |
'invisible', | |
# 'bell', | |
'h' => \&HelpMessage, | |
'v' => \&VersionMessage, | |
); | |
my %map = ( | |
'k' => 30, | |
'K' => 40, | |
'r' => 31, | |
'R' => 41, | |
'g' => 32, | |
'G' => 42, | |
'y' => 33, | |
'Y' => 43, | |
'b' => 34, | |
'B' => 44, | |
'p' => 35, | |
'P' => 45, | |
'l' => 36, | |
'L' => 46, | |
'w' => 37, | |
'W' => 47, | |
# 'return', | |
'strong' => 1, | |
# 'perpendicular' => 2, | |
'underscore' => 4, | |
'blink' => 5, | |
'reverse' => 7, | |
'invisible' => 8, | |
# 'bell', | |
); | |
my $esc = join ';', map { $map{$_} } keys %opts; | |
my $word = shift || ''; | |
while (<>) { | |
if ($word) { | |
s/($word)/[${esc}m$1[m/g; | |
} | |
print; | |
} | |
__END__ | |
=head1 NAME | |
escfilter - wrap `word' by escape sequence | |
=head1 SYNOPSIS | |
$ escfilter -ru [word] < /etc/passwd | |
options: | |
short options: (lower for word, upper for background) | |
-k/-K black | |
-r/-R red | |
-g/-G green | |
-y/-Y yellow | |
-b/-B blue | |
-p/-P purple | |
-l/-L light blue | |
-w/-W white | |
long options: | |
--strong | |
--underscore | |
--blink | |
--reverse | |
--invisible | |
-h, -?, --help print help message | |
-v, --version print version string | |
=head1 SEE ALSO | |
L<http://d.hatena.ne.jp/rx7/20100827/p1> | |
=head1 AUTHOR | |
Kensuke Kaneko | |
=head1 LICENSE | |
This library is free software; you can redistribute it and/or modify | |
it under the same terms as Perl itself. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment