perl reverse color

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

perl reverse color

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
Last edited by timvw on Fri Mar 10, 2006 5:23 pm, edited 2 times in total.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Check out Win32::Console and WriteAttr().
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

Post by vietboy505 »

thank you guys..

i'll look at those.. I am sure I will ask for help later. thx alot
vietboy505
Forum Commoner
Posts: 53
Joined: Wed Feb 22, 2006 9:30 am

Post 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.
Post Reply