This queue is for tickets about the TermReadKey CPAN distribution.

Report information
The Basics
Id:
93292
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
chm [...] cpan.org
Cc:
AdminCc:

BugTracker
Severity:
Important
Broken in:
2.31
Fixed in:
2.33

Attachments


Subject: need improved usage in POD
The output of 'perldoc Term::ReadKey' is not very complete with regards to usage and what the various mode settings really do.  Imagine my surprise to discover that most of my unanswered questions in this regard are actually covered in the README file instead.

It would be much more useful and accessible if the usage and definition/descriptions from README were in the module POD.  As an example, the POD gives this list of values for ReadMode:

                   0    Restore original settings.
                   1    Change to cooked mode.
                   2    Change to cooked mode with echo off.
                         (Good for passwords)
                   3    Change to cbreak mode.
                   4    Change to raw mode.
                   5    Change to ultra-raw mode.
                         (LF to CR/LF translation turned off)


While the corresponding part from README is much more detailed;

        0: (Reset) Restore original settings.

        1: (Cooked) Change to what is commonly the default mode, echo on,
           buffered, signals enabled, Xon/Xoff possibly enabled, and 8-bit mode
           possibly disabled.

        2: (Cooked-Invisible) Same as 1, just with echo off. Nice for reading
           passwords.

        3: (CBreak) Echo off, unbuffered, signals enabled, Xon/Xoff possibly
           enabled, and 8-bit mode possibly enabled.

        4: (Raw) Echo off, unbuffered, signals disabled, Xon/Xoff disabled,
           and 8-bit mode possibly disabled.

        5: (Really-Raw) Echo off, unbuffered, signals disabled, Xon/Xoff
           disabled, 8-bit mode enabled if parity permits, and CR to CR/LF
           translation turned off.


Subject: Re: [rt.cpan.org #93292] need improved usage in POD
Date: Sun, 23 Feb 2014 22:22:00 +0000
To: bug-TermReadKey@rt.cpan.org
From: Jonathan Stowe <jonathan.stowe@gmail.com>
Hi, thanks for that. If you can see you way clear a pull request against https://github.com/jonathanstowe/TermReadKey would certainly expidite matters :) On Sun, 2014-02-23 at 16:38 -0500, Chris Marshall via RT wrote:
Show quoted text
> Sun Feb 23 16:38:53 2014: Request 93292 was acted upon. > Transaction: Ticket created by CHM > Queue: TermReadKey > Subject: need improved usage in POD > Broken in: 2.31 > Severity: Important > Owner: Nobody > Requestors: chm@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=93292 > > > > The output of 'perldoc Term::ReadKey' is not very complete with regards to > usage and what the various mode settings really do. Imagine my surprise to > discover that most of my unanswered questions in this regard are actually > covered in the README file instead. > > It would be much more useful and accessible if the usage and > definition/descriptions from README were in the module POD. As an example, the > POD gives this list of values for ReadMode: > > 0 Restore original settings. > 1 Change to cooked mode. > 2 Change to cooked mode with echo off. > (Good for passwords) > 3 Change to cbreak mode. > 4 Change to raw mode. > 5 Change to ultra-raw mode. > (LF to CR/LF translation turned off) > > > While the corresponding part from README is much more detailed; > > 0: (Reset) Restore original settings. > > 1: (Cooked) Change to what is commonly the default mode, echo on, > buffered, signals enabled, Xon/Xoff possibly enabled, and 8-bit mode > possibly disabled. > > 2: (Cooked-Invisible) Same as 1, just with echo off. Nice for reading > passwords. > > 3: (CBreak) Echo off, unbuffered, signals enabled, Xon/Xoff possibly > enabled, and 8-bit mode possibly enabled. > > 4: (Raw) Echo off, unbuffered, signals disabled, Xon/Xoff disabled, > and 8-bit mode possibly disabled. > > 5: (Really-Raw) Echo off, unbuffered, signals disabled, Xon/Xoff > disabled, 8-bit mode enabled if parity permits, and CR to CR/LF > translation turned off. >
CC: chm@cpan.org
Subject: Re: [rt.cpan.org #93292] need improved usage in POD
Date: Sun, 23 Feb 2014 17:31:39 -0500
To: bug-TermReadKey@rt.cpan.org
From: Chris Marshall <devel.chm.01@gmail.com>
Sure it may be a while. I've spent most of the weekend trying to figure out how to provide syntax highlighting for a perl CLI. Understanding the Term::ReadKey gives me hope but there is still a lot to go in terms of interfacing with the various options for readline() et. al. I'll defnitely contribute a patch when I get back to this (unless someone beats me to it :-) On Sun, Feb 23, 2014 at 5:22 PM, Jonathan Stowe via RT <bug-TermReadKey@rt.cpan.org> wrote:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=93292 > > > Hi, > thanks for that. > > If you can see you way clear a pull request against > > https://github.com/jonathanstowe/TermReadKey > > would certainly expidite matters :) > > On Sun, 2014-02-23 at 16:38 -0500, Chris Marshall via RT wrote:
>> Sun Feb 23 16:38:53 2014: Request 93292 was acted upon. >> Transaction: Ticket created by CHM >> Queue: TermReadKey >> Subject: need improved usage in POD >> Broken in: 2.31 >> Severity: Important >> Owner: Nobody >> Requestors: chm@cpan.org >> Status: new >> Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=93292 > >> >> >> The output of 'perldoc Term::ReadKey' is not very complete with regards to >> usage and what the various mode settings really do. Imagine my surprise to >> discover that most of my unanswered questions in this regard are actually >> covered in the README file instead. >> >> It would be much more useful and accessible if the usage and >> definition/descriptions from README were in the module POD. As an example, the >> POD gives this list of values for ReadMode: >> >> 0 Restore original settings. >> 1 Change to cooked mode. >> 2 Change to cooked mode with echo off. >> (Good for passwords) >> 3 Change to cbreak mode. >> 4 Change to raw mode. >> 5 Change to ultra-raw mode. >> (LF to CR/LF translation turned off) >> >> >> While the corresponding part from README is much more detailed; >> >> 0: (Reset) Restore original settings. >> >> 1: (Cooked) Change to what is commonly the default mode, echo on, >> buffered, signals enabled, Xon/Xoff possibly enabled, and 8-bit mode >> possibly disabled. >> >> 2: (Cooked-Invisible) Same as 1, just with echo off. Nice for reading >> passwords. >> >> 3: (CBreak) Echo off, unbuffered, signals enabled, Xon/Xoff possibly >> enabled, and 8-bit mode possibly enabled. >> >> 4: (Raw) Echo off, unbuffered, signals disabled, Xon/Xoff disabled, >> and 8-bit mode possibly disabled. >> >> 5: (Really-Raw) Echo off, unbuffered, signals disabled, Xon/Xoff >> disabled, 8-bit mode enabled if parity permits, and CR to CR/LF >> translation turned off. >>
> > >
Patch against latest git repo with minor tweak to make MODE value string synonyms case insensitive.  Fold in some better explanation from README into POD as well.
Subject: term-readkey-readmode-usage.patch
diff --git a/ReadKey.pm b/ReadKey.pm index 79b5c68..d3dd58b 100644 --- a/ReadKey.pm +++ b/ReadKey.pm @@ -5,15 +5,15 @@ package Term::ReadKey; Term::ReadKey - A perl module for simple terminal control =head1 SYNOPSIS - use Term::ReadKey; - ReadMode 4; # Turn off controls keys - while (not defined ($key = ReadKey(-1))) { - # No key yet - } - print "Get key $key\n"; - ReadMode 0; # Reset tty mode before exiting + use Term::ReadKey; + ReadMode 4; # Turn off controls keys + while (not defined ($key = ReadKey(-1))) { + # No key yet + } + print "Get key $key\n"; + ReadMode 0; # Reset tty mode before exiting =head1 DESCRIPTION Term::ReadKey is a compiled perl module dedicated to providing simple @@ -27,32 +27,36 @@ Version 2.30.01: Added handling of arrows, page up/down, home/end, insert/delete keys under Win32. These keys emit xterm-compatible sequences. Works with Term::ReadLine::Perl. -=over 8 +=over 4 =item ReadMode MODE [, Filehandle] -Takes an integer argument, which can currently be one of the following -values: +Takes an integer argument or a string synonym (case insensitive), which +can currently be one of the following values: + + INT SYNONYM DESCRIPTION + + 0 'restore' Restore original settings. + + 1 'normal' Change to what is commonly the default mode, + echo on, buffered, signals enabled, Xon/Xoff + possibly enabled, and 8-bit mode possibly disabled. + + 2 'noecho' Same as 1, just with echo off. Nice for + reading passwords. + + 3 'cbreak' Echo off, unbuffered, signals enabled, Xon/Xoff + possibly enabled, and 8-bit mode possibly enabled. + + 4 'raw' Echo off, unbuffered, signals disabled, Xon/Xoff + disabled, and 8-bit mode possibly disabled. + + 5 'ultra-raw' Echo off, unbuffered, signals disabled, Xon/Xoff + disabled, 8-bit mode enabled if parity permits, + and CR to CR/LF translation turned off. - 0 Restore original settings. - 1 Change to cooked mode. - 2 Change to cooked mode with echo off. - (Good for passwords) - 3 Change to cbreak mode. - 4 Change to raw mode. - 5 Change to ultra-raw mode. - (LF to CR/LF translation turned off) - - Or, you may use the synonyms: - - restore - normal - noecho - cbreak - raw - ultra-raw These functions are automatically applied to the STDIN handle if no other handle is supplied. Modes 0 and 5 have some special properties worth mentioning: not only will mode 0 restore original settings, but it @@ -60,22 +64,29 @@ cause the next ReadMode call to save a new set of default settings. Mode 5 is similar to mode 4, except no CR/LF translation is performed, and if possible, parity will be disabled (only if not being used by the terminal, however. It is no different from mode 4 under Windows.) +If you just need to read a key at a time, then modes 3 or 4 are probably +sufficient. Mode 4 is a tad more flexible, but needs a bit more work to +control. If you use ReadMode 3, then you should install a SIGINT or END +handler to reset the terminal (via ReadMode 0) if the user aborts the +program via C<^C>. (For any mode, an END handler consisting of "ReadMode 0" +is actually a good idea.) + If you are executing another program that may be changing the terminal mode, you will either want to say - ReadMode 1 + ReadMode 1; # same as ReadMode 'normal' system('someprogram'); ReadMode 1; - + which resets the settings after the program has run, or: $somemode=1; - ReadMode 0; + ReadMode 0; # same as ReadMode 'restore' system('someprogram'); ReadMode 1; - + which records any changes the program may have made, before resetting the mode. =item ReadKey MODE [, Filehandle] @@ -86,24 +97,30 @@ values: 0 Perform a normal read using getc -1 Perform a non-blocked read >0 Perform a timed read -(If the filehandle is not supplied, it will default to STDIN.) If there is +If the filehandle is not supplied, it will default to STDIN. If there is nothing waiting in the buffer during a non-blocked read, then undef will be -returned. Note that if the OS does not provide any known mechanism for -non-blocking reads, then a C<ReadKey -1> can die with a fatal error. This -will hopefully not be common. +returned. In most situations, you will probably want to use C<ReadKey -1>. + +I<NOTE> that if the OS does not provide any known mechanism for non-blocking +reads, then a C<ReadKey -1> can die with a fatal error. This will hopefully +not be common. If MODE is greater then zero, then ReadKey will use it as a timeout value in seconds (fractional seconds are allowed), and won't return C<undef> until -that time expires. (Note, again, that some OS's may not support this timeout -behaviour.) If MODE is less then zero, then this is treated as a timeout +that time expires. + +I<NOTE>, again, that some OS's may not support this timeout behaviour. + +If MODE is less then zero, then this is treated as a timeout of zero, and thus will return immediately if no character is waiting. A MODE of zero, however, will act like a normal getc. -There are currently some limitations with this call under Windows. It may be -possible that non-blocking reads will fail when reading repeating keys from -more then one console. +I<NOTE>, there are currently some limitations with this call under Windows. +It may be possible that non-blocking reads will fail when reading repeating +keys from more then one console. + =item ReadLine MODE [, Filehandle] Takes an integer argument, which can currently be one of the following @@ -113,52 +130,61 @@ values: -1 Perform a non-blocked read >0 Perform a timed read If there is nothing waiting in the buffer during a non-blocked read, then -undef will be returned. Note that if the OS does not provide any known -mechanism for non-blocking reads, then a C<ReadLine 1> can die with a fatal -error. This will hopefully not be common. Note that a non-blocking test is -only performed for the first character in the line, not the entire line. -This call will probably B<not> do what you assume, especially with -ReadMode's higher then 1. For example, pressing Space and then Backspace -would appear to leave you where you started, but any timeouts would now -be suspended. +undef will be returned. -This call is currently not available under Windows. +I<NOTE>, that if the OS does not provide any known mechanism for +non-blocking reads, then a C<ReadLine 1> can die with a fatal +error. This will hopefully not be common. + +I<NOTE> that a non-blocking test is only performed for the first character +in the line, not the entire line. This call will probably B<not> do what +you assume, especially with C<ReadMode> MODE values higher then 1. For +example, pressing Space and then Backspace would appear to leave you +where you started, but any timeouts would now be suspended. + +B<This call is currently not available under Windows>. =item GetTerminalSize [Filehandle] Returns either an empty array if this operation is unsupported, or a four element array containing: the width of the terminal in characters, the height of the terminal in character, the width in pixels, and the height in pixels. (The pixel size will only be valid in some environments.) -Under Windows, this function must be called with an "output" filehandle, -such as STDOUT, or a handle opened to CONOUT$. +I<NOTE>, under Windows, this function must be called with an B<output> +filehandle, such as C<STDOUT>, or a handle opened to C<CONOUT$>. =item SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle] -Return -1 on failure, 0 otherwise. Note that this terminal size is only for -B<informative> value, and changing the size via this mechanism will B<not> -change the size of the screen. For example, XTerm uses a call like this when +Return -1 on failure, 0 otherwise. + +I<NOTE> that this terminal size is only for B<informative> value, and +changing the size via this mechanism will B<not> change the size of +the screen. For example, XTerm uses a call like this when it resizes the screen. If any of the new measurements vary from the old, the OS will probably send a SIGWINCH signal to anything reading that tty or pty. -This call does not work under Windows. +B<This call does not work under Windows>. =item GetSpeeds [, Filehandle] Returns either an empty array if the operation is unsupported, or a two value array containing the terminal in and out speeds, in B<decimal>. E.g, an in speed of 9600 baud and an out speed of 4800 baud would be returned as (9600,4800). Note that currently the in and out speeds will always be -identical in some OS's. No speeds are reported under Windows. +identical in some OS's. + +B<No speeds are reported under Windows>. =item GetControlChars [, Filehandle] Returns an array containing key/value pairs suitable for a hash. The pairs consist of a key, the name of the control character/signal, and the value -of that character, as a single character. This call does nothing under Windows. +of that character, as a single character. + +B<This call does nothing under Windows>. Each key will be an entry from the following list: DISCARD @@ -198,9 +224,9 @@ settings. The list of valid names is easily available via %cchars = GetControlChars(); @cnames = keys %cchars; -This call does nothing under Windows. +B<This call does nothing under Windows>. =back =head1 AUTHOR @@ -287,9 +313,9 @@ bootstrap Term::ReadKey; $UseEnv = 1; $CurrentMode = 0; -%modes = ( +%modes = ( # lowercase is canonical original => 0, restore => 0, normal => 1, noecho => 2, @@ -299,9 +325,9 @@ $CurrentMode = 0; ); sub ReadMode { - my ($mode) = $modes{ $_[0] }; + my ($mode) = $modes{ lc $_[0] }; # lowercase is canonical my ($fh) = normalizehandle( ( @_ > 1 ? $_[1] : \*STDIN ) ); if ( defined($mode) ) { $CurrentMode = $mode } elsif ( $_[0] =~ /^\d/ ) { $CurrentMode = $_[0] } else { croak("Unknown terminal mode `$_[0]'"); }
Jonathan, I don't know how the pull request thing works with github but a patch against the latest git is attached to this ticket.
Subject: Re: [rt.cpan.org #93292] need improved usage in POD
Date: Mon, 03 Mar 2014 18:32:47 +0000
To: bug-TermReadKey@rt.cpan.org
From: Jonathan Stowe <jonathan.stowe@gmail.com>
Hi, I've applied that in https://github.com/jonathanstowe/TermReadKey/commit/70fb9f65965d405a5c978d564913f772c527b5e3 I'll give it a couple of days before I release to let the peanut gallery chime in :) On Sun, 2014-03-02 at 14:12 -0500, Chris Marshall via RT wrote:
Show quoted text
> Queue: TermReadKey > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=93292 > > > Jonathan, I don't know how the pull request thing works with github but a patch > against the latest git is attached to this ticket. >
Hi, that has been released now and as I haven't heard otherwise I'll close this.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.