http://qs321.pair.com?node_id=11146204


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

Two further notes on win32:

  1. Anecdotally, I recommend you don't use Win32::Console::ANSI; if you've got the VirtualTerminalLevel = 1 registry setting. It reduced the functionality of the colors when I enabled that line.
  2. IO::Prompter's prompt() command doesn't seem to handle win32 CRLF newlines correctly: when I hit ENTER like it told me to, it said "' is invalid. Six hexadecimal characters are expected; such as in the table above.". Then when I typed a 6 digit string like 123456 , it said the same thing. I added in some debug statements, and found out the CR was still there. I added $rgb =~ s/[\r]*$//; after $rgb = prompt ... and that fixed the interface for me.

Replies are listed 'Best First'.
Re^5: 'rgb_palette' - Term::ANSIColor Helper -- errors on strawberry
by kcott (Archbishop) on Aug 18, 2022 at 00:34 UTC

    ++ Thanks for the bug report.

    I found an existing bug report, #118255, which refers to a problem when -echo is used with prompt. It looks like -return, as I've used, has the same issue.

    I've changed

    $rgb = prompt 'Convert hex to decimal rgb (or just hit "Enter" to +quit): ', -return => '';

    to

    $rgb = prompt 'Convert hex to decimal rgb (or just hit "Enter" to +quit): ', -return => ''; # Fix for MSWin -- see https://rt.cpan.org/Public/Bug/Display.html +?id=118255 $rgb =~ s/\R\z//;

    The s/\R\z// is a little more generic than s/[\r]*$//; but otherwise it's pretty much the same as your fix.

    I've tested it on my machine (Cygwin) and it hasn't changed the functionality for me. Could you test that for me on your MSWin machine? Assuming it works OK, I'll update the code in the OP. Thanks.

    — Ken

      Hello,

      yes it works nice for me: the following version is also agnostic about the perl version:

      L*

      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.

        Firstly, I'm glad this finally worked for you.

        "the following version is also agnostic about the perl version"

        Leaving out a "use VERSION;" statement does not achieve this; nor does adding a "use feature LIST;" statement.

        Your code will have problems with older Perl versions. Here's a non-exhaustive list:

        • Subroutine signatures were introduced in v5.20.0 (see "perl5200delta: Experimental Subroutine signatures"). I added information in the OP on how to deal with this.
        • I didn't really expect anyone to wind back v5.36 to a pre-5.10 version, so I made no comment about that in the OP; however, say() was introduced in v5.10.0 (see "perl5100delta: say()").
        • And for the same reason as the above point, I didn't mention that IO::Prompter requires v5.10.0 (see the first line of its source).
        • And, in the later fix for the MSWin bug, \R requires v5.10.0 (see "perlrebackslash: \R").

        — Ken