Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: How to print colored word in text file

by hdb (Prior)
on Jun 21, 2013 at 13:11 UTC ( #1040160=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How to print colored word in text file
in thread How to print colored word in text file

Thanks a lot this works for me. Example I tried from the documentation:

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";


Comment on Re^5: How to print colored word in text file
Download Code
Re^6: How to print colored word in text file
by Khen1950fx (Canon) on Jun 22, 2013 at 14:07 UTC
    ++hdb. For something different, I would use Win32::Console::ANSI and Term::ANSIColor::Print.
    #!/usr/bin/perl BEGIN { $| = 1; $^W = 1; eval { require Readonly; }; } use strict; use warnings; use Win32::Console::ANSI; use Term::ANSIColor::Print; my $print = Term::ANSIColor::Print->new(); $print->bold_blue( "This text is bold blue." ); $print->normal( "This text is normal" ); $print->bold_yellow_on_magenta( "This text is bold yellow on magenta", ); $print->normal( "This text is normal." ); print "To print a specific word such as ERROR in red: "; $print->red("ERROR");
    I don't have access to a Windows machine, so it isn't tested. Please let me know if it works for you.

      Bold and Normal did work, colors didn't...
      (Win 7 Pro 64bit, Strawberry PortableZIP version 5.16.2)

      However, as I recall, under MSDOS you had to enable ANSI.SYS for color codes to work.

      Wikipedia says this still holds true up to Vista. Obviusly, Win 7 is no different...

      Update: seems like
          use Win32::Console::ANSI;
      changes the behaviour of Term::ANSIColor, but not the behaviour of Term::ANSIColor::Print ...

        Thanks for the feedback. I'll remember ANSI.SYS now:-).

      Thanks for the example. I get the same effect as soonix. What is quite interesting I find, is that use Win32::Console::ANSI; is not used explicitly and the script runs without it as well, but no effect on the appearance of the text, it prints the escape codes instead. With this line, at least bold works.



Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1040160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-12-18 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls