View Full Version : Color reverse
vietboy505
03-10-2006, 11:53 PM
In Unix, there is reverse for colors of text, etc.
I found this from this web on Emacs.
Reverse color on emacs (http://kb.iu.edu/data/adzf.html)
In Unix perl script, with these code..
printf("Hey \33[0;0m Hi \n");
##<-[0;0m
printf(" ");
printf("\33[0;5;7m");
printf("%2s", " hmm ");
printf("\33[0;0m");
will produce the right color action as describe from that web.
But in Windows Perl, I got back the error numbers.
Hey ←[0;0m Hi
←[0;5;7m hmm ←[0;0m
Can Windows Perl does the same thing in Unix Perl? any help would be appreciate. thanks
FishMonger
03-11-2006, 01:33 AM
Windows NT/2000/XP does not support ANSI escape sequences in Win32 Console applications.
You need to use the Win32::Console::ANSI module along with Term::ANSIColor.
http://search.cpan.org/~jlmorel/Win32-Console-ANSI-1.00/lib/Win32/Console/ANSI.pm
use Win32::Console::ANSI;
use Term::ANSIColor;
print color 'bold blue';
print "This text is bold blue.\n";
print color 'reset';
print "This text is normal.\n";
print colored ("Bold yellow on magenta.\n", 'bold yellow on_magenta');
print "This text is normal.\n";
vietboy505
03-11-2006, 06:32 AM
color.pl
#!/usr/local/bin/perl
use Win32::Console::ANSI;
print "\e[1;34mThis text is bold blue.\e[0m\n";
print "This text is normal.\n";
print "\e[33;45;1mBold yellow on magenta.\e[0m\n";
print "This text is normal.\n";
use Term::ANSIColor;
print color 'bold blue';
print "This text is bold blue.\n";
print color 'reset';
print "This text is normal.\n";
print colored ("Bold yellow on magenta.\n", 'bold yellow on_magenta');
print "This text is normal.\n";
I have to install the module to get it to work, so this is not a built in module when you install ActivePerl like the other module?
C:\PERL>ppm install http://www.bribes.org/perl/ppm/Win32-Console-ANSI.ppd
====================
Install 'Win32-Console-ANSI' version 1.00 in ActivePerl 5.8.7.815.
====================
Installing C:\Perl\site\lib\auto\Win32\Console\ANSI\ANSI.bs
Installing C:\Perl\site\lib\auto\Win32\Console\ANSI\ANSI.dll
Installing C:\Perl\site\lib\auto\Win32\Console\ANSI\ANSI.exp
Installing C:\Perl\site\lib\auto\Win32\Console\ANSI\ANSI.lib
Installing C:\Perl\html\site\lib\Win32\Console\ANSI.html
Files found in blib\arch: installing files in blib\lib into architecture depende
nt library tree
Installing C:\Perl\site\lib\Win32\Console\ANSI.pm
Successfully installed Win32-Console-ANSI version 1.00 in ActivePerl 5.8.7.815.
Can't locate Win32/Console/ANSI.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .) at color.pl line 3.
BEGIN failed--compilation aborted at color.pl line 3.
Do I need to install on UNIX server too?
I thought CPAN will work both on UNIX & Windows.
I want it to work the same in UNIX & Windows without doing an if statement to detemine OS $^O for each code.
such as
#!/usr/local/bin/perl
if ($^O =~ /Win/) {
use Win32::Console::ANSI;
print "\e[1;34mThis text is bold blue.\e[0m\n";
print "This text is normal.\n";
print "\e[33;45;1mBold yellow on magenta.\e[0m\n";
print "This text is normal.\n";
use Term::ANSIColor;
print color 'bold blue';
print "This text is bold blue.\n";
print color 'reset';
print "This text is normal.\n";
print colored ("Bold yellow on magenta.\n", 'bold yellow on_magenta');
print "This text is normal.\n";
} else {
printf("Hey \33[0;0m Hi \n");
##<-[0;0m
printf(" ");
printf("\33[0;5;7m");
printf("%2s", " hmm ");
printf("\33[0;0m");
}
Thanks.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.