Term::ANSIColor

1 查看ANSIColor.pm可以得知作者是利用ANSI转义序列,改变终端字符颜色的。

print "\e[34m\n";        # 改变前景色为blue;

shell命令为echo -e"\033[31m";       # 改变前景色为红色。

(freeBSD,Solaris下此命令测试OK) 

#!/usr/bin/perl 
use strict; 
use Term::ANSIColor qw(:constants); 

$Term::ANSIColor::AUTORESET = 1; 

$| = 1; 
my $str = "Welcome to chinaunix ^_^!\n"; 

for my $i(0..length($str)-1) 
{ 
   print BOLD RED substr($str, $i, 1); 
   select(undef, undef, undef, 0.3); 
} 
exit 0;

2 转义序列echo -e"\033[20;40H";可以改变光标位置。

perl中就可以:print"\e[20;40H"; 

#!/usr/bin/perl 
use strict; 
use Term::ANSIColor qw(:constants); 

$Term::ANSIColor::AUTORESET = 1; 

$| = 1; 

print "\e[20;40H"; 
my $str = "Welcome to chinaunix ^_^!\n"; 

print BOLD BLINK $str; 
exit 0;


你可能感兴趣的:(Term::ANSIColor)