Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How to change the color of the text

by PilotinControl25 (Initiate)
on Sep 26, 2012 at 01:23 UTC ( #995663=perlquestion: print w/ replies, xml ) Need Help??
PilotinControl25 has asked for the wisdom of the Perl Monks concerning the following question:

I would like to change the color of the output any suggestions instead of using print/printf/sprintf thanks.</>

#!/usr/bin/perl open (FILE, "railcardata.txt"); while (<FILE>) { chomp; ($roadname, $roadnumber, $cartype, $interrr) = split(":"); write; } close (FILE); format STDOUT_TOP = ====================================================================== ROAD NAME ROAD NUMBER CAR TYPE INTERCHANGE RAILROAD ====================================================================== . format STDOUT = @<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<< $roadname, $roadnumber, $cartype, $interrr . sleep 12;

Comment on How to change the color of the text
Download Code
Replies are listed 'Best First'.
Re: How to change the color of the text
by toolic (Bishop) on Sep 26, 2012 at 02:06 UTC
    instead of using print
    I don't understand your restriction, but I have used Term::ANSIColor

      I've inserted the ANSI code and it should display the whole output in another color correct? However it does not. What am I missing? Thanks.

      #!/usr/bin/perl use Term::ANSIColor qw(:constants); print GREEN, open (FILE, "railcardata.txt"); while (<FILE>) { chomp; ($roadname, $roadnumber, $cartype, $interrr) = split(":"); write; } close (FILE); format STDOUT_TOP = ====================================================================== ROAD NAME ROAD NUMBER CAR TYPE INTERCHANGE RAILROAD ====================================================================== . format STDOUT = @<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<< $roadname, $roadnumber, $cartype, $interrr . sleep 12;
        "ANSI doesn't take"

        What do you mean by that?

        I've used ANSI also with great success...however I am stuck in this scenario no matter how I try and code it ANSI doesn't take...any suggestions in the code? thanks

        Maybe you ought to show that code?

        Does your terminal support ANSI escapes?

      I inserted the ansi code and it is not displaying green text please explain? thanks

        What operating system, what shell, what code?
Re: How to change the color of the text
by Plankton (Priest) on Sep 27, 2012 at 02:57 UTC
    Does this code work, in color, on your system?
    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 ("Yellow on magenta.", 'yellow on_magenta'), "\n"; print "This text is normal.\n"; print colored ['yellow on_magenta'], 'Yellow on magenta.', "\n"; print colored ['red on_bright_yellow'], 'Red on bright yellow.', "\n"; print colored ['bright_red on_black'], 'Bright red on black.', "\n"; print "\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-08-30 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (348 votes), past polls