Bin-Text-Color-Plus
view release on metacpan or search on metacpan
scripts/resistorcc view on Meta::CPAN
#!/usr/bin/perl
use 5.014 ;
use warnings ;
use Encode qw[ encode_utf8 decode_utf8 ];
use Term::ANSIColor qw[ :constants color ] ;
$Term::ANSIColor::AUTORESET = 1 ;
use Getopt::Std ;
getopts '' , \my %o ;
my @givecolor = map { color ( $_ ) }
(
'dark white' , 'faint bold red', # 'dark on_bright_red black', # 0 1
'red ', 'bright_red' , 'yellow' , # 2 3 4
'green', 'bright_blue', 'bold magenta', # 5 6 7
'white', 'bold bright_white' # 8 9
) ;
while ( <> ) {
$_ = decode_utf8 $_ ;
my @cha = split /([0-9]|\e\[[\d;]*m)/, $_ , -1 ; # "\e" = "\x1b"
#my @cha = split /([0-9])/, $_ , -1 ;
my $prevnum = 0 ; # ç´åã®æåãæ°åã ã£ãã©ããã®ãã©ã°
for ( @cha ) {
if ( m/^[0-9]$/ ) {
$prevnum = 1 ;
#$_ = color ( 'reset' ) . $givecolor [ $_ ] . $_ ;
$_ = $givecolor [ $_ ] . $_ ;
} elsif ( $prevnum -- ) {
$_ = color ('reset') . $_ ;
}
}
my $out = join '' , @cha ;
print encode_utf8 ( $out ) ;
}
## ãã«ãã®æ±ã
sub VERSION_MESSAGE {}
sub HELP_MESSAGE {
use FindBin qw[ $Script ] ;
$ARGV[1] //= '' ;
open my $FH , '<' , $0 ;
while(<$FH>){
s/\$0/$Script/g ;
print $_ if s/^=head1// .. s/^=cut// and $ARGV[1] =~ /^o(p(t(i(o(ns?)?)?)?)?)?$/i ? m/^\s+\-/ : 1;
}
close $FH ;
exit 0 ;
}
=encoding utf8
=head1
ã³ãã³ã
$0
æ°åã«ã黿°æµæã®ã«ã©ã¼ã³ã¼ãã«ä¼¼ãè²ã被ããã
ãªãã·ã§ã³:
ã¾ã ç¡ãã
éçºã¡ã¢:
* 8è²ã使ãåãã¦ããã256è²ã使ããå ´åã®æå®ãå¯è½ã¨ãããã
* ãã®ããã°ã©ã ãutf8ãåæã«ãã¦ãããã¨ã¯åé¡ããããã
* cat ?? | resistorcc | resistorcc ã®ããã«2åéãã¦å®è¡ãã¦ãã¬ã¤ã¢ã¦ããå´©ããªãããã«ãããããã¤ãæ°ãã©ãã©ãè¨ããã
=cut
( run in 1.207 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )