in reply to Re^3: 'rgb_palette' - Term::ANSIColor Helper -- errors on strawberry
in thread 'rgb_palette' - Term::ANSIColor Helper

G'day Discipulus,

Unfortunately, it looks like you don't have a true color terminal. See "Term::ANSIColor - Supported Colors" for more about that.

I got similar errors to what you're seeing when making a typo while developing and testing. This sort of thing:

$ perl -E 'use Term::ANSIColor; say colored("black on white", "r0g0v0 +on_white")' Invalid attribute name r0g0v0 at -e line 1.

However, there's no typo that I can see in what you've posted. You could do a couple of tests outside of my script.

$ perl -E 'use Term::ANSIColor; use Data::Dump; my $x = colored("black + on white", "r0g0b0 on_white"); say $x; dd $x' black on white "\e[38;2;0;0;0;47mblack on white\e[0m" $ perl -E 'say "\e[38;2;0;0;0;47mblack on white\e[0m"' black on white

Both of those give me the text "black on white" in black on a white background.

I don't have a Perl on an MSWin platform to test. I don't know about dumb and not dumb TERM values. For what it's worth:

$ echo $TERM xterm

Sorry I can't be of more help. Is there anything in AM's post that's useful for you?

Edit (stupid typo fix): s/white foreground/white background/.

— Ken

Replies are listed 'Best First'.
Re^5: 'rgb_palette' - Term::ANSIColor Helper -- errors on strawberry
by afoken (Chancellor) on Aug 17, 2022 at 05:09 UTC

    terminfo knows what your terminal is capable of. The max_colors capability looks right ("maximum number of colors on screen").


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      G'day Alexander,

      I had read about terminfo, tput, and friends recently. What I found was that there are many variations depending on terminal type, and the manpages don't always get it right.

      The manpage to which you linked, and the one on my system, seem to agree; at least with respect to numeric capabilities. Here's a selection (which I've doctored a bit for those with narrower screens than me):

      These are the numeric capabilities: Variable Cap- TCap Description Numeric name Code columns cols co number of columns in a line ... lines lines li number of lines on screen or page ... max_colors colors Co maximum number of colors on screen ...

      Now consider these:

      $ tput cols 120 $ tput lines 63 $ tput colors 8

      The first two give absolutely correct results. The third is very wrong: I have 16,581,375 colours, not 8. Perhaps there's a better capability to use, but I don't know what that might be (and I'm certainly no expert — I've only been looking at these features very recently).

      I didn't mention terminfo, tput, etc. to Discipulus because I'm unsure of the validity of the information and I don't even know if MSWin has them (or, if it does, perhaps they're under a different name).

      — Ken

Re^5: 'rgb_palette' - Term::ANSIColor Helper -- errors on strawberry
by pryrt (Abbot) on Aug 17, 2022 at 20:38 UTC
    It's down to the version of Term::ANSIColor.

    I had Strawberry's default Term::ANSIColor v4.06, and it gave me the same error Discipulus saw. I tried

    @echo =================== 8 v 16 perl -E "use Term::ANSIColor; say my $x=colored('red text', 'red on_wh +ite'); use Data::Dump; dd $x" perl -E "use Term::ANSIColor; say my $x=colored('red text', 'bright_re +d on_white'); use Data::Dump; dd $x" perl -E "use Term::ANSIColor; use Data::Dump; my $x = colored('black o +n white', 'black on_white'); say $x; dd $x" @echo =================== 256 vs 8 or 16 perl -E "use Term::ANSIColor; use Data::Dump; my $x = colored('black o +n white', 'rgb000 on_white'); say $x; dd $x" @echo =================== [id://11146167] perl -E "use Term::ANSIColor; use Data::Dump; my $x = colored('black o +n white', 'r0g0b0 on_white'); say $x; dd $x" perl -E "say qq(\e[38;5;16;47mblack on white\e[0m)" perl -E "say qq(\e[38;2;0;0;0;47mblack on white\e[0m)" perl -E "say qq(\e[38;2;255;0;0;47mred on white\e[0m)" perl -E "say qq(\e[38;2;0;127;0;47mgreen on white\e[0m)" perl -E "say qq(\e[38;2;0;0;255;47mblue on white\e[0m)" perl -E "say qq(\e[38;2;191;127;191;47mpurple on white\e[0m)" perl -E "use Term::ANSIColor; use Config; say for $Term::ANSIColor::VE +RSION, $], $Config{myuname};"
    ... And everything but the r0g0b0 worked†; the r0g0b0 gave Invalid attribute name r0g0b0 at -e line 1.

    I then realized that since kcott was using v5.36, there was probably a newer Term::ANSIColor , so then I ran cpanm Term::ANSIColor, which installed 5.01. When I ran my same batch script with the updated module, it worked without the error.

    So Discipulus, you need to update Term::ANSIColor. Per their change list, rNNNgNNNbNNN notation was added in 5.00.

    (To get the colors to work, I did use the VirtualTerminalLevel = 1 that the AM recommended)

    edit: †: with full 24 bit color working fine for the red, green, blue, and purple, using manual escape sequences.
      Hello pryrt and kcott,

      yes the upgrade did the trick:

      cpan> upgrade Term::ANSIColor Package namespace installed latest in CPAN file Term::ANSIColor 4.06 5.01 RRA/Term-ANSIColor-5.01 +.tar.gz


      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.

      G'day pryrt,

      Thanks for your research and discovery.

      Yes, I am using Perl v5.36 and Term::ANSIColor v5.01 came with that (it's a dual-life module).

      The first stable version of Perl with Term::ANSIColor v5.00 (or later) is Perl v5.32.0 (with Term::ANSIColor v5.01): The most recent version of Perl offered by "Strawberry Perl" is v5.32.1.1. So, presumably, updating Strawberry Perl would be another way to get the required version of Term::ANSIColor.

      [I sent a /msg to Discipulus with a link to your post.]

      — Ken