Page 1 of 1

perl reverse color

Posted: Fri Mar 10, 2006 4:54 pm
by vietboy505
In Unix, there is reverse for colors of text, etc.

I found this from this web on Emacs.
Reverse color on emacs

In Unix perl script, with these code..

Code: Select all

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.

Code: Select all

Hey  &#8592;[0;0m  Hi
 &#8592;[0;5;7m hmm &#8592;[0;0m
Can Windows Perl does the same thing in Unix Perl? any help would be appreciate. thanks

Posted: Fri Mar 10, 2006 5:18 pm
by timvw
http://en.wikipedia.org/wiki/ANSI_escape_code.. It comes down to the fact that you need to get a better CLI than cmd.exe Try it in a win32 port of bash.. or whatever shell that pleases u ;)

Posted: Fri Mar 10, 2006 5:19 pm
by Buddha443556
Check out Win32::Console and WriteAttr().

Posted: Fri Mar 10, 2006 5:24 pm
by timvw

Posted: Fri Mar 10, 2006 7:04 pm
by vietboy505
thank you guys..

i'll look at those.. I am sure I will ask for help later. thx alot

Posted: Fri Mar 10, 2006 11:35 pm
by vietboy505
color.pl

Code: Select all

#!/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?

Code: Select all

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.

Code: Select all

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

Code: Select all

#!/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.