Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: using colors with print()

by tachyon (Chancellor)
on Jun 20, 2004 at 05:30 UTC ( [id://368258]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^3: using colors with print()
in thread using colors with print()

Actually the ANSI escapes span lines so newline position is really immaterial (except from a neatness point of view). In fact AFAIK they remain active until reset, and this status outlives the life of your program as you are effectively manipulating defaults on your term.

 
$ cat col.pl
#!/usr/bin/perl

# default black background
use constant BLUE => "\e[0;34;40m";
use constant RED  => "\e[0;31;40m";
use constant DEFAULT  => "\e[0;37;40m";

print "The flag is:
", RED, "
red
", DEFAULT, "
white &
", BLUE,"
blue.

ANSI color escapes
will span", DEFAULT, " at least with
putty as the terminal emulation.
", BLUE;

$ ./col.pl
The flag is:

red

white &

blue.

ANSI color escapes
will span at least with
putty as the terminal emulation.
$
$ echo Oops forgot to reset blue mode
Oops forgot to reset blue mode
$ perl -e 'print "\e[0;37;40m"';
$ echo Fixed....
Fixed....

cheers

tachyon

Replies are listed 'Best First'.
Re^5: using colors with print()
by pbeckingham (Parson) on Jun 20, 2004 at 11:50 UTC

    Oh, you're absolutely right, the sequences do span lines, and indeed should, but I had problems on Solaris 8/xterm when I relied on this. Perhaps I shouldn't have even mentioned this.

    I will mention though, that the longer those sequences remain active, the greater the chance of the userr hitting Crtl-C and having their terminal in need of an \e[0m.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://368258]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.