• Home
  • History
  • Annotate
  • only in this directory
NameDateSize

..11-Apr-2013244

Configure.pmH A D20-Apr-200927 KiB

genchars.plH A D20-Apr-200910.4 KiB

Makefile.PLH A D20-Apr-20091.2 KiB

MANIFESTH A D20-Apr-2009170

META.ymlH A D20-Apr-2009354

ppport.hH A D20-Apr-200915.4 KiB

ReadKey.pmH A D20-Apr-200916.1 KiB

ReadKey.xsH A D20-Apr-200943.6 KiB

READMEH A D20-Apr-20096.2 KiB

test.plH A D20-Apr-20097.5 KiB

README

1 Term::ReadKey 2.30 - Change terminal modes, and perform non-blocking reads.
2
3 Copyright (C) 1994-1999 Kenneth Albanowski. 
4               2001-2005 Jonathan Stowe and others
5
6 Unlimited distribution and/or modification is allowed as long as this 
7 copyright notice remains intact.
8
9This module, ReadKey, provides ioctl control for terminals and Win32
10consoles so the input modes can be changed (thus allowing reads of a single
11character at a time), and also provides non-blocking reads of stdin, as well
12as several other terminal related features, including retrieval/modification
13of the screen size, and retrieval/modification of the control characters.
14Installation requires MakeMaker 3.5 or higher (MakeMaker 3.7 is included
15with perl 5.001, so now is a good time to upgrade if you haven't already.)
16
17To install, unpack somewhere, type "perl Makefile.PL", and then "make test".
18If the compilation and the tests are successful, then change to root and run
19"make install".
20
21As of 2.17 the interactive test has been removed as the default for the
22convenience of automated installers, CPAN-Testers and so on.  The non
23interactive tests whilst confirming that the module has built correctly
24and has a good chance of working correctly cannot determine whether the
25effect as observed on the screen is correct so you might want to run:
26
27   perl -Mblib test.pl interactive
28
29before you run 'make install'.
30
31Also from 2.17 this module has to provide its own support for compilers
32that can't take function prototypes as with Perl 5.8.0 this last vestige
33of support for non-ANSI compilers will disappear.  The requirement for
34an ANSI C compiler has been present since Perl 5.005 so it is likely that
35at some point in the future this module will follow that requirement too.
36If you have any difficulties with older Perl's please contact the maintainer.
37
38The module has support for Win32 since version 2.10. Version 2.17 has been
39tested with ActivePerl build 623 and Visual Studio 6 and found to work
40as expected, but do not be surprised if it fails with another compiler
41or distribution.  There are  some limitations, with the ReadLine call
42being unavailable, and ReadKey possibly generating bad results if you
43are reading from multiple consoles, and key repeat is used.  For Win32
44users without a C compiler there is a precompiled version of this module
45available as a package for ActivePerl, it is probably a few versions
46behind the latest release but has been reported to work well.
47
48VERY IMPORTANT: In 2.00, the ReadKey/ReadLine arguments changed. Now, if
49you want a call that is non-blocking and returns immediately if no
50character is waiting, please call it with -1, instead of 1. Positive
51arguments now indicate a timeout, so 1 would wait a second before timing
52out.
53
54As older versions will accept -1, it is reccomended to change all code 
55that uses ReadMode.
56
57
58The terminal mode function is controlled by the "ReadMode" function, which
59takes a single numeric argument, and an optional filehandle. This argument
60should be one of the following:
61
62	0: (Reset) Restore original settings.
63
64	1: (Cooked) Change to what is commonly the default mode, echo on,
65           buffered, signals enabled, Xon/Xoff possibly enabled, and 8-bit mode 
66	   possibly disabled.
67
68	2: (Cooked-Invisible) Same as 1, just with echo off. Nice for reading 
69           passwords.
70
71	3: (CBreak) Echo off, unbuffered, signals enabled, Xon/Xoff possibly 
72           enabled, and 8-bit mode possibly enabled.
73
74	4: (Raw) Echo off, unbuffered, signals disabled, Xon/Xoff disabled, 
75           and 8-bit mode possibly disabled.
76
77	5: (Really-Raw) Echo off, unbuffered, signals disabled, Xon/Xoff 
78           disabled, 8-bit mode enabled if parity permits, and CR to CR/LF 
79           translation turned off. 
80
81If you just need to read a key at a time, then modes 3 or 4 are probably
82sufficient. Mode 4 is a tad more flexible, but needs a bit more work to
83control. If you use ReadMode 3, then you should install a SIGINT or END
84handler to reset the terminal (via ReadMode 0) if the user aborts the
85program via ^C. (For any mode, an END handler consisting of "ReadMode 0" is
86actually a good idea.)
87
88Non-blocking support is provided via the ReadKey and ReadLine functions. If
89they are passed no argument, or an argument of zero, they will act like a
90normal getc(STDIN) or scalar(<STDIN>). If they are passed a negative
91argument, then they will immediatly return undef if no input is present. If
92passed a positive argument, then they will wait until that time in seconds
93has passed before returning undef. In most situations, you will probably
94want to use "ReadKey -1".
95
96Note that a non-blocking ReadLine probably won't do what you expect,
97although it is perfectly predictable, and that the ReadMode will have to be
981 or 0 for it to make sense at all.
99
100A routine is also provided to get the current terminal size,
101"GetTerminalSize". This will either return a four value array containing the
102width and height of the screen in characters and then in pixels, or nothing
103( if the OS can't return that info). SetTerminalSize allows the stored
104settings to be modified. Note that this does _not_ change the physical size
105of the screen, it will only change the size reported by GetTerminalSize, and
106other programs that check the terminal size in the same manner.
107
108GetControlChars returns a hash containing all of the valid control
109characters, such as ("INTERRUPT" => "\x3", etc.). SetControlChars takes an
110array (or a hash) as a parameter that should consist of similar name/value
111pairs and will modify the control character settings.
112
113Note that it is entirely possible that there are portability problems with
114the routines in ReadKey.xs. If you find any problems, including compilation
115failures, or control characters not supported by Set/GetControlChars,
116_please_ tell me about them, by mailing the maintainer at jns@gellyfish.com,
117 or lastly contacting perl5-porters@perl.org. Any problems
118will get fixed if at all possible, but that's not going to happen if I don't
119know about them.
120
121Oh, you may also be interested in the Configure.pm module. It provides tools
122to make porting stuff easier -- calling the compiler, finding headers, etc.
123It contains documentation inside it, and you are welcome to use it in your
124own modules. If you make use of it, I'd be grateful for a message sent to
125the above address.
126