Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Term::ANSIColor not displaying BRIGHT colors

by g_speran (Beadle)
on Mar 06, 2018 at 15:50 UTC ( #1210411=perlquestion: print w/replies, xml ) Need Help??
g_speran has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have the following code that I am testing on windows at the cmd prompt. I am trying to display bright colors, but when the bright color is called to print, it displays in white. So the first line displaysin green, but the 2nd line which I want to display in Bright Green, displays white. Any ideas on how to get it to be bright green?

#!/usr/bin/perl use if $^O eq 'MSWin32', Win32::Console::ANSI; use if $^O eq 'MSWin32', Term::ANSIColor => qw(:constants); if ($^O eq 'MSWin32') { $SUCCESS=GREEN; $BRIGHT_SUCCESS=BRIGHT_GREEN; $FAILURE=RED; $WARNING=YELLOW; $NORMAL=RESET; $cls='cls'; } else { $FAILURE=`echo -en "\\033[1;31m"`; $SUCCESS=`echo -en "\\033[1;32m"`; $WARNING=`echo -en "\\033[1;33m"`; $NORMAL=`echo -en "\\033[0;39m"`; $cls='clear'; } $RESULT="Test Line"; $line=sprintf("%s%s%s\n",$SUCCESS,$RESULT,$NORMAL); print $line; # <== This will print Green $line=sprintf("%s%s%s\n",$BRIGHT_SUCCESS,$RESULT,$NORMAL); print $line; # <== This will print White...not Bright Green

Replies are listed 'Best First'.
Re: Term::ANSIColor not displaying BRIGHT colors
by Anonymous Monk on Mar 06, 2018 at 17:51 UTC


      eh no! Anonymous Monk,

      this is cheating! I've loosed an hour trying all possible combinations and reading obfuscated docs..

      from where this dotted syntax come from? Are the very same constants exported by :constants of Term::ANSIColor ?


      PS after the below Anonymous Monks's explanation (++ for the hint) I searched a bit and I found here 1     Bold/Bright     Applies brightness/intensity flag to foreground color so it seems that for them are synonymouses...

      And reading more carefully Term::ANSIColor notes:

      > Note that not all displays are ISO 6429-compliant, or even X3.64-compliant (or are even attempting to be so). This module will not work as expected on displays that do not honor these escape sequences, such as cmd.exe ..

      This may explains why :constants exports unuseful stuffs when on windows: perhaps Win32::Console::ANSI needs some mention in it's docs..

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Dotted syntax is just string concatenation. I'd even say my $BRIGHT_SUCCESS = $^O eq 'MSWin32' ? BOLD.GREEN : BRIGHT_GREEN; and use Term::ANSIColor qw/:constants/; unconditionally. Can see no need in OP's coding escape sequences manually. Short answer, above, because I "always" knew it's bold to be used to get bright, on Windows, and don't remember/lazy to search for sources.

      BOLD.GREEN did the job. Thank you

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1210411]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2018-03-20 06:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.