Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

IO::Prompter on Windows

by Brutha (Friar)
on Nov 05, 2013 at 08:51 UTC ( #1061273=perlquestion: print w/replies, xml ) Need Help??
Brutha has asked for the wisdom of the Perl Monks concerning the following question:

When I found the module IO::Prompter I just went wow on the features. Great work.

As already others said and open bugs tell, this is not working completely under Windows, but still is usefull. What seems to work for me with version 0.004010 is:

  • simple Input of strings,
  • password entry
  • menues
  • style (with Win32::Console::ANSI)
  • -num and partly -filenames
  • completion (mostly)

So this is quite a lot to make it usefull, even if I just did only quick testing.

What did not work are some editing features (to be expected under windows), but more disappointing were some constraints failures. The -guarantee works until you press return and always get "invalid input":

my $animal = prompt -guarantee=>['cat','dog','cow'];

Also the '-must' constraints always seem to fail, e.g.:

my $file = prompt "Select file: ", -must => {'File must exist' => sub { -e } }, -complete => 'filenames';

after completion always gives "File must exist". So I tried debugging, but failed as the keyboard is turned off on verifying constraints.

Anybody has some hints how I could continue?
Did anybody has some success with possible other combinations?
It would be great to have the cats/dogs example running.

Oh, I use x86 ActivePerl 5.14 on Windows7 64-bit with use 5.014; and Term::ReadKey installed

And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
(Terry Pratchett, Small Gods)

Replies are listed 'Best First'.
Re: IO::Prompter on Windows
by Corion (Pope) on Nov 05, 2013 at 08:56 UTC

    I would guess that the most likely candidate is unix-centric newline handling of the input as read from the console. Depending on how it works on Windows resp. how Windows Perl treats stuff read from STDIN, you might end up with \r\n in your input. A (very) cursory glance at the source code of IO::Prompter only reveals \n newline treatment.

    If you can fake input to IO::Prompter, or inspect the value of $_ for the -must callback, maybe you find some whitespace at the end of the (supposed) filename...

      Uaaah, the obvious thing.

      You are correct, every returned input has '\cM' appended, with the obvious exception of the menues.

      Thank You. Now I have a hint to continue.


      Looking at the code, the regex "/\A\R\z/" is used to identify the return key. Of course, this matches '\r'. Afterwards exactly this character is appended to the input and spoils enter-handling.

      As a quick hack, I modified, line 1379, the following way:

      # Add newline to the accumulated input string... #$input .= $next; $input .= "\n";

      This seems to help me, but is a hack

      And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
      (Terry Pratchett, Small Gods)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2018-03-23 17:32 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (295 votes). Check out past polls.