Skip Menu |

This queue is for tickets about the IO-Prompter CPAN distribution.

Report information
The Basics
Id: 102365
Status: open
Priority: 0/
Queue: IO-Prompter

People
Owner: Nobody in particular
Requestors: 'ddjones [...] riddlemaster.org'
danjone3 [...] cisco.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: IO::Prompter returning literal keystrokes
Date: Wed, 25 Feb 2015 20:17:17 -0500
To: bug-io-prompter [...] rt.cpan.org
From: ddjones <ddjones [...] riddlemaster.org>
I'm using IO::Prompter under Strawberry Perl on Windows 7 and seeing what I believe is buggy behavior. The return string contains the literal keystrokes pressed, including editing keys. For example, if I type ABC then hit the backspace key, the cursor moves to the left, between the B and C, but the C isn't deleted. Hitting the Return key, the returned string then contains ABC followed by hex value 0x8, the ASCII value for the backspace key. Expected behavior, of course, would be for the backspace key to delete the C and neither to be present in the returned string. The string also contains a \r at the end, regardless of whether I use the -line argument or not. I'm not at all sure this is a bug in IO::Prompter. It may very well lie in an underlying library or in Strawberry Perl itself. But I thought I'd at least report the behavior here. If you have any knowledge that might help me identify the location of the bug if it isn't in the IO:;Prompter code, I'd appreciate a response so I can file a bug to the correct project. -- "Politics is the art of looking for trouble, finding it everywhere, diagnosing it incorrectly and applying the wrong remedies." - Groucho Marx
Subject: Re: [rt.cpan.org #102365] IO::Prompter returning literal keystrokes
Date: Sat, 28 Feb 2015 00:52:25 +1100
To: bug-IO-Prompter [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks for the report. Definitely buggy behaviour, and I think the most likely culprit is Term::ReadKey. Specifically, Term::ReadKey::GetControlChars() may not be returning the appropriate value for 'ERASE'. Or not returning *any* value, in which case IO::Prompter defaults to the Unixish 0x7F (i.e. ASCII DELETE). The following code tests for that issue: use Term::ReadKey; use Data::Dumper 'Dumper'; say 'Hit the backspace/delete/erase key on your keyboard...'; Term::ReadKey::ReadMode('raw', *STDIN); my $input = Term::ReadKey::ReadKey; Term::ReadKey::ReadMode('restore', *STDIN); my %controls = Term::ReadKey::GetControlChars(*STDIN); say 'Term::ReadKey thinks ERASE is ASCII ', ord($controls{ERASE}); say ' Your system thinks ERASE is ASCII ', ord($input); say "That's a problem" if $input ne $controls{ERASE}; Let me know what it tells you under Strawberry Perl. Damian (who doesn't have--and doesn't want--access to Windows himself ;-)
Subject: Bug 102365
Date: Mon, 2 Mar 2015 19:04:13 +0000
To: "bug-IO-Prompter [...] rt.cpan.org" <bug-IO-Prompter [...] rt.cpan.org>
From: "Daniel Jones -X (danjone3 - INSIGHT GLOBAL INC at Cisco)" <danjone3 [...] cisco.com>
I ran the code requested and received the following results: Hitting the backspace key: Hit the backspace/delete/erase key on your keyboard... Use of uninitialized value $controls{"ERASE"} in ord at temp.pl line 34. Term::ReadKey thinks ERASE is ASCII 0 Your system thinks ERASE is ASCII 8 Use of uninitialized value in string ne at temp.pl line 36. That's a problem Hitting the delete key: Hit the backspace/delete/erase key on your keyboard... Use of uninitialized value $controls{"ERASE"} in ord at temp.pl line 34. Term::ReadKey thinks ERASE is ASCII 0 Your system thinks ERASE is ASCII 27 Use of uninitialized value in string ne at temp.pl line 36. That's a problem [http://www.cisco.com/web/europe/images/email/signature/logo05.jpg] Daniel D Jones Engineer - Network danjone3@cisco.com Cell: 910-382-7095 Cisco Systems Limited US Cisco.com<http://www.cisco.com/> [Think before you print.]Think before you print. This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/index.html
Download image001.jpg
image/jpeg 5.5k
image001.jpg
Download image002.gif
image/gif 134b
image002.gif
Subject: Re: [rt.cpan.org #102456] Bug 102365
Date: Mon, 2 Mar 2015 20:30:03 +0100
To: bug-IO-Prompter [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Hi Dan, Thanks for the diagnostic feedback. As controls{"ERASE"} is consistently undefined, i's clear that Term::ReadKey is not providing the necessary key information to allow IO::Prompter to handle character deletions. under Strawberry Perl (as it does successfully under Linux and MacOS). The value you got back when hitting DELETE is weird. ASCII 27 is ESCAPE, so it's quite likely that's just the start of a multi-character sequence (or else something is horribly broken under Strawberry Perl). Could I prevail upon you to rerun the diagnostic tests with the following (enhanced) version of my test code: -----cut----------cut----------cut----------cut----------cut----------cut----------cut----- use Term::ReadKey; use Data::Dumper 'Dumper'; say 'Hit the backspace/delete/erase key on your keyboard...'; Term::ReadKey::ReadMode('raw', *STDIN); my $input = Term::ReadKey::ReadKey; while (defined( my $nextchar = Term::ReadKey::ReadKey(-1) )) { $input .= $nextchar; } Term::ReadKey::ReadMode('restore', *STDIN); my %controls = Term::ReadKey::GetControlChars(*STDIN); if (!defined $controls{ERASE}) { say 'Term::ReadKey doesn\'t know what character ERASE is'; } else { say 'Term::ReadKey thinks ERASE is ASCII ', join ',', map {ord} split //,$controls{ERASE}; } say ' Your system thinks ERASE is ASCII ', join ',', map {ord} split //, $input; say "That's a problem" if $input ne ($controls{ERASE} // 127); -----end----------end----------end----------end----------end----------end----------end----- Much appreciated! Damian
Subject: RE: [rt.cpan.org #102365] Re: [rt.cpan.org #102456] Bug 102365
Date: Mon, 2 Mar 2015 19:36:45 +0000
To: "bug-IO-Prompter [...] rt.cpan.org" <bug-IO-Prompter [...] rt.cpan.org>
From: "Daniel Jones -X (danjone3 - INSIGHT GLOBAL INC at Cisco)" <danjone3 [...] cisco.com>
No problem at all. Results follow, first with backspace and then with delete: C:\Users\danjone3 λ perl temp.pl Hit the backspace/delete/erase key on your keyboard... Term::ReadKey doesn't know what character ERASE is Your system thinks ERASE is ASCII 8 That's a problem C:\Users\danjone3 λ perl temp.pl Hit the backspace/delete/erase key on your keyboard... Term::ReadKey doesn't know what character ERASE is Your system thinks ERASE is ASCII 27,91,51,126 That's a problem (BTW, for what it's worth, I'd prefer not to be using Windows either but it's a work machine. I don't have a choice!) Daniel D Jones Engineer - Network danjone3@cisco.com Cell: 910-382-7095 Cisco Systems Limited US Cisco.com Think before you print. This email may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply email and delete all copies of this message. For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/index.html Show quoted text
-----Original Message----- From: damian@conway.org via RT [mailto:bug-IO-Prompter@rt.cpan.org] Sent: Monday, March 02, 2015 2:31 PM To: 'ddjones@riddlemaster.org'; Daniel Jones -X (danjone3 - INSIGHT GLOBAL INC at Cisco) Subject: [rt.cpan.org #102365] Re: [rt.cpan.org #102456] Bug 102365 <URL: https://rt.cpan.org/Ticket/Display.html?id=102365 > Hi Dan, Thanks for the diagnostic feedback. As controls{"ERASE"} is consistently undefined, i's clear that Term::ReadKey is not providing the necessary key information to allow IO::Prompter to handle character deletions. under Strawberry Perl (as it does successfully under Linux and MacOS). The value you got back when hitting DELETE is weird. ASCII 27 is ESCAPE, so it's quite likely that's just the start of a multi-character sequence (or else something is horribly broken under Strawberry Perl). Could I prevail upon you to rerun the diagnostic tests with the following (enhanced) version of my test code: -----cut----------cut----------cut----------cut----------cut----------cut----------cut----- use Term::ReadKey; use Data::Dumper 'Dumper'; say 'Hit the backspace/delete/erase key on your keyboard...'; Term::ReadKey::ReadMode('raw', *STDIN); my $input = Term::ReadKey::ReadKey; while (defined( my $nextchar = Term::ReadKey::ReadKey(-1) )) { $input .= $nextchar; } Term::ReadKey::ReadMode('restore', *STDIN); my %controls = Term::ReadKey::GetControlChars(*STDIN); if (!defined $controls{ERASE}) { say 'Term::ReadKey doesn\'t know what character ERASE is'; } else { say 'Term::ReadKey thinks ERASE is ASCII ', join ',', map {ord} split //,$controls{ERASE}; } say ' Your system thinks ERASE is ASCII ', join ',', map {ord} split //, $input; say "That's a problem" if $input ne ($controls{ERASE} // 127); -----end----------end----------end----------end----------end----------end----------end----- Much appreciated! Damian
Subject: Re: [rt.cpan.org #102365] Re: [rt.cpan.org #102456] Bug 102365
Date: Mon, 2 Mar 2015 21:15:43 +0100
To: bug-IO-Prompter [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Thanks again, Dan. I don't see any way within the current IO::Prompter architecture for me to handle an ERASE that produces a multi-character escape sequence (such as when you hit DELETE). On the other hand, handling the BACKSPACE behaviour should not be a problem: I'll simply change the default to "\10" when $^O is "MSWin32". The attached beta implements that proposed change. If you'd like to test whether it (at least partially) solves your original problem with the module, I'd be grateful. As for handling DELETE under Strawberry Perl, I currently have no idea. Maybe report the behaviour to the Term::ReadKey maintainer, to see if it's as expected or possibly a bug? Otherwise, for the moment I will just have to document it along with the failure to handle the multi-character escape sequences produced by arrow keys. :-( Damian

Message body is not shown because sender requested not to inline it.