Mon Jan 10 23:38:52 2011: Request 64675 was acted upon.
Transaction: Ticket created by joev
       Queue: Win32-Console
     Subject: InputChar loses input in ENABLE_LINE_INPUT mode
   Broken in: 0.09
    Severity: Normal
       Owner: Nobody
  Requestors: jo...@vornehm.com
      Status: new
 Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=64675 >


When the InputChar method does not receive all the input characters
requested, it returns undef, inadvertently throwing away any characters
it may have received.  This makes it difficult to use when
ENABLE_LINE_MODE is on.

Running Strawberry Perl v5.12.1 on WinXP SP3.  To reproduce:

use Win32::Console;
$CONSOLE = Win32::Console->new(STD_INPUT_HANDLE);
$CONSOLE->Mode(ENABLE_LINE_INPUT
               | ENABLE_ECHO_INPUT 
               | ENABLE_PROCESSED_INPUT);
print "Type \"Perl is awesome\" and press Enter.\n";
$res = $CONSOLE->InputChar(10);
print "\nResults: \"$res\"\n";
print "Remaining chars: ", $CONSOLE->GetEvents(), "\n";
# will be 0, should be >0

As an aside, it appears that when InputChar is called, any input left
remaining in the console input buffer is flushed (discarded).  Ideally,
one would like to call some method $CONSOLE->InputLine() and have it
return the whole input line.  A workaround would be to call
$CONSOLE->InputChar(1024) or some other large number, except that such a
call fails presently when 1024 characters are not already waiting in the
input buffer.

Attached is a patch that makes InputChar return the characters received.

Attachment: Console.pm.diff
Description: Binary data

Reply via email to