Blame README

Packit 910689
 Term::ReadKey 2.36 - Change terminal modes, and perform non-blocking reads.
Packit 910689
Packit 910689
 Copyright (C) 1994-1999 Kenneth Albanowski.
Packit 910689
               2001-2016 Jonathan Stowe and others
Packit 910689
Packit 910689
This package is dual licensed.  You can either choose to license it under
Packit 910689
the original terms which were:
Packit 910689
Packit 910689
 Unlimited distribution and/or modification is allowed as long as this
Packit 910689
 copyright notice remains intact.
Packit 910689
Packit 910689
Or the standard Perl terms:
Packit 910689
Packit 910689
  This module is free software; you can redistribute it and/or modify it
Packit 910689
  under the terms of the Artistic License. For details, see the full
Packit 910689
  text of the license in the file "Artistic" that should have been provided
Packit 910689
  with the version of perl you are using.
Packit 910689
Packit 910689
  This program is distributed in the hope that it will be useful, but
Packit 910689
  without any warranty; without even the implied warranty of merchantability
Packit 910689
  or fitness for a particular purpose.
Packit 910689
Packit 910689
Packit 910689
Packit 910689
This module, ReadKey, provides ioctl control for terminals and Win32
Packit 910689
consoles so the input modes can be changed (thus allowing reads of a single
Packit 910689
character at a time), and also provides non-blocking reads of stdin, as well
Packit 910689
as several other terminal related features, including retrieval/modification
Packit 910689
of the screen size, and retrieval/modification of the control characters.
Packit 910689
Installation requires MakeMaker 3.5 or higher (MakeMaker 3.7 is included
Packit 910689
with perl 5.001, so now is a good time to upgrade if you haven't already.)
Packit 910689
Packit 910689
To install, unpack somewhere, type "perl Makefile.PL", and then "make test".
Packit 910689
If the compilation and the tests are successful, then change to root and run
Packit 910689
"make install".
Packit 910689
Packit 910689
As of 2.17 the interactive test has been removed as the default for the
Packit 910689
convenience of automated installers, CPAN-Testers and so on.  The non
Packit 910689
interactive tests whilst confirming that the module has built correctly
Packit 910689
and has a good chance of working correctly cannot determine whether the
Packit 910689
effect as observed on the screen is correct so you might want to run:
Packit 910689
Packit 910689
   perl -Mblib example/test.pl interactive
Packit 910689
Packit 910689
before you run 'make install'.
Packit 910689
Packit 910689
Also from 2.17 this module has to provide its own support for compilers
Packit 910689
that can't take function prototypes as with Perl 5.8.0 this last vestige
Packit 910689
of support for non-ANSI compilers will disappear.  The requirement for
Packit 910689
an ANSI C compiler has been present since Perl 5.005 so it is likely that
Packit 910689
at some point in the future this module will follow that requirement too.
Packit 910689
If you have any difficulties with older Perl's please contact the maintainer.
Packit 910689
Packit 910689
The module has support for Win32 since version 2.10. Version 2.17 has been
Packit 910689
tested with ActivePerl build 623 and Visual Studio 6 and found to work
Packit 910689
as expected, but do not be surprised if it fails with another compiler
Packit 910689
or distribution.  There are  some limitations, with the ReadLine call
Packit 910689
being unavailable, and ReadKey possibly generating bad results if you
Packit 910689
are reading from multiple consoles, and key repeat is used.  For Win32
Packit 910689
users without a C compiler there is a precompiled version of this module
Packit 910689
available as a package for ActivePerl, it is probably a few versions
Packit 910689
behind the latest release but has been reported to work well.
Packit 910689
Packit 910689
VERY IMPORTANT: In 2.00, the ReadKey/ReadLine arguments changed. Now, if
Packit 910689
you want a call that is non-blocking and returns immediately if no
Packit 910689
character is waiting, please call it with -1, instead of 1. Positive
Packit 910689
arguments now indicate a timeout, so 1 would wait a second before timing
Packit 910689
out.
Packit 910689
Packit 910689
As older versions will accept -1, it is reccomended to change all code
Packit 910689
that uses ReadMode.
Packit 910689
Packit 910689
Packit 910689
The terminal mode function is controlled by the "ReadMode" function, which
Packit 910689
takes a single numeric argument, and an optional filehandle. This argument
Packit 910689
should be one of the following:
Packit 910689
Packit 910689
	0: (Reset) Restore original settings.
Packit 910689
Packit 910689
	1: (Cooked) Change to what is commonly the default mode, echo on,
Packit 910689
           buffered, signals enabled, Xon/Xoff possibly enabled, and 8-bit mode
Packit 910689
	   possibly disabled.
Packit 910689
Packit 910689
	2: (Cooked-Invisible) Same as 1, just with echo off. Nice for reading
Packit 910689
           passwords.
Packit 910689
Packit 910689
	3: (CBreak) Echo off, unbuffered, signals enabled, Xon/Xoff possibly
Packit 910689
           enabled, and 8-bit mode possibly enabled.
Packit 910689
Packit 910689
	4: (Raw) Echo off, unbuffered, signals disabled, Xon/Xoff disabled,
Packit 910689
           and 8-bit mode possibly disabled.
Packit 910689
Packit 910689
	5: (Really-Raw) Echo off, unbuffered, signals disabled, Xon/Xoff
Packit 910689
           disabled, 8-bit mode enabled if parity permits, and CR to CR/LF
Packit 910689
           translation turned off.
Packit 910689
Packit 910689
If you just need to read a key at a time, then modes 3 or 4 are probably
Packit 910689
sufficient. Mode 4 is a tad more flexible, but needs a bit more work to
Packit 910689
control. If you use ReadMode 3, then you should install a SIGINT or END
Packit 910689
handler to reset the terminal (via ReadMode 0) if the user aborts the
Packit 910689
program via ^C. (For any mode, an END handler consisting of "ReadMode 0" is
Packit 910689
actually a good idea.)
Packit 910689
Packit 910689
Non-blocking support is provided via the ReadKey and ReadLine functions. If
Packit 910689
they are passed no argument, or an argument of zero, they will act like a
Packit 910689
normal getc(STDIN) or scalar(<STDIN>). If they are passed a negative
Packit 910689
argument, then they will immediatly return undef if no input is present. If
Packit 910689
passed a positive argument, then they will wait until that time in seconds
Packit 910689
has passed before returning undef. In most situations, you will probably
Packit 910689
want to use "ReadKey -1".
Packit 910689
Packit 910689
Note that a non-blocking ReadLine probably won't do what you expect,
Packit 910689
although it is perfectly predictable, and that the ReadMode will have to be
Packit 910689
1 or 0 for it to make sense at all.
Packit 910689
Packit 910689
A routine is also provided to get the current terminal size,
Packit 910689
"GetTerminalSize". This will either return a four value array containing the
Packit 910689
width and height of the screen in characters and then in pixels, or nothing
Packit 910689
( if the OS can't return that info). SetTerminalSize allows the stored
Packit 910689
settings to be modified. Note that this does _not_ change the physical size
Packit 910689
of the screen, it will only change the size reported by GetTerminalSize, and
Packit 910689
other programs that check the terminal size in the same manner.
Packit 910689
Packit 910689
GetControlChars returns a hash containing all of the valid control
Packit 910689
characters, such as ("INTERRUPT" => "\x3", etc.). SetControlChars takes an
Packit 910689
array (or a hash) as a parameter that should consist of similar name/value
Packit 910689
pairs and will modify the control character settings.
Packit 910689
Packit 910689
Note that it is entirely possible that there are portability problems with
Packit 910689
the routines in ReadKey.xs. If you find any problems, including compilation
Packit 910689
failures, or control characters not supported by Set/GetControlChars,
Packit 910689
_please_ tell me about them, by mailing the maintainer at jns@gellyfish.co.uk,
Packit 910689
 or lastly contacting perl5-porters@perl.org. Any problems
Packit 910689
will get fixed if at all possible, but that's not going to happen if I don't
Packit 910689
know about them.
Packit 910689
Packit 910689
The code is available at https://github.com/jonathanstowe/TermReadKey so
Packit 910689
as ever patches are kindly welcomed, especially for platforms such as
Packit 910689
Windows that I am unable to test on.
Packit 910689
Packit 910689
Oh, you may also be interested in the Configure.pm module. It provides tools
Packit 910689
to make porting stuff easier -- calling the compiler, finding headers, etc.
Packit 910689
It contains documentation inside it, and you are welcome to use it in your
Packit 910689
own modules. If you make use of it, I'd be grateful for a message sent to
Packit 910689
the above address.