App-resistorcc
view release on metacpan or search on metacpan
#!/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
) ;
$o{'='} //= 1 if exists $o{'='} ;
$o{'='} //= 0 ;
my $c = 0 ; # è¡æ°ã®ã«ã¦ã³ã
while ( <> ) {
$c ++ ;
do { print $_ ; next } if $c <= $o{'='} ;
$_ = 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
æ°åã«ã黿°æµæã®ã«ã©ã¼ã³ã¼ãã«ä¼¼ãè²ã被ããã
ãã®ã³ãã³ãã¯ãæ¨æºå
¥åã¾ãã¯æå®ããããã¡ã¤ã«ããä¸èº«ãèªã¿åãããã®ä¸ãã
æ°å¤(0,1,2,3,4,5,6,7,8,9ã®10æå)ãè¦ã¤ãã¦ãä¸ççã«ä½¿ããã¦ãã黿°æµæå¨ã®
ã«ã©ã¼ã³ã¼ãã«å¿ããè²ãçè²ããããã®çµæãæ°å¤ã®å¤ããã¼ã¿ãé常ã«è¦ããããªã
å ´åãããã
æå 黿°æµæå¨ã«ã¼ã³ã¼ã å®éã«ãã®ã³ãã³ããçè²ããè²(ã«ã©ã¼ã³ã¼ãã¨ç°ãªãå ´å)
0 é» â æãç°è²ã¨ãã(8ã®ç°è²ããæã)ã
1 è¶
2 赤
3 æ©
4 é»
( run in 1.090 second using v1.01-cache-2.11-cpan-d7f47b0818f )