.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "ReadKey 3pm" .TH ReadKey 3pm "2019-01-11" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Term::ReadKey \- A perl module for simple terminal control .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 7 \& use Term::ReadKey; \& ReadMode 4; # Turn off controls keys \& while (not defined ($key = ReadKey(\-1))) { \& # No key yet \& } \& print "Get key $key\en"; \& ReadMode 0; # Reset tty mode before exiting .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Term::ReadKey is a compiled perl module dedicated to providing simple control over terminal driver modes (cbreak, raw, cooked, etc.,) support for non-blocking reads, if the architecture allows, and some generalized handy functions for working with terminals. One of the main goals is to have the functions as portable as possible, so you can just plug in \*(L"use Term::ReadKey\*(R" on any architecture and have a good likelihood of it working. .PP 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. .IP "ReadMode \s-1MODE\s0 [, Filehandle]" 4 .IX Item "ReadMode MODE [, Filehandle]" Takes an integer argument or a string synonym (case insensitive), which can currently be one of the following values: .Sp .Vb 1 \& INT SYNONYM DESCRIPTION \& \& 0 \*(Aqrestore\*(Aq Restore original settings. \& \& 1 \*(Aqnormal\*(Aq Change to what is commonly the default mode, \& echo on, buffered, signals enabled, Xon/Xoff \& possibly enabled, and 8\-bit mode possibly disabled. \& \& 2 \*(Aqnoecho\*(Aq Same as 1, just with echo off. Nice for \& reading passwords. \& \& 3 \*(Aqcbreak\*(Aq Echo off, unbuffered, signals enabled, Xon/Xoff \& possibly enabled, and 8\-bit mode possibly enabled. \& \& 4 \*(Aqraw\*(Aq Echo off, unbuffered, signals disabled, Xon/Xoff \& disabled, and 8\-bit mode possibly disabled. \& \& 5 \*(Aqultra\-raw\*(Aq Echo off, unbuffered, signals disabled, Xon/Xoff \& disabled, 8\-bit mode enabled if parity permits, \& and CR to CR/LF translation turned off. .Ve .Sp These functions are automatically applied to the \s-1STDIN\s0 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 cause the next ReadMode call to save a new set of default settings. Mode 5 is similar to mode 4, except no \s-1CR/LF\s0 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.) .Sp 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 \s-1SIGINT\s0 or \s-1END\s0 handler to reset the terminal (via ReadMode 0) if the user aborts the program via \f(CW\*(C`^C\*(C'\fR. (For any mode, an \s-1END\s0 handler consisting of \*(L"ReadMode 0\*(R" is actually a good idea.) .Sp If you are executing another program that may be changing the terminal mode, you will either want to say .Sp .Vb 3 \& ReadMode 1; # same as ReadMode \*(Aqnormal\*(Aq \& system(\*(Aqsomeprogram\*(Aq); \& ReadMode 1; .Ve .Sp which resets the settings after the program has run, or: .Sp .Vb 4 \& $somemode=1; \& ReadMode 0; # same as ReadMode \*(Aqrestore\*(Aq \& system(\*(Aqsomeprogram\*(Aq); \& ReadMode 1; .Ve .Sp which records any changes the program may have made, before resetting the mode. .IP "ReadKey \s-1MODE\s0 [, Filehandle]" 4 .IX Item "ReadKey MODE [, Filehandle]" Takes an integer argument, which can currently be one of the following values: .Sp .Vb 3 \& 0 Perform a normal read using getc \& \-1 Perform a non\-blocked read \& >0 Perform a timed read .Ve .Sp If the filehandle is not supplied, it will default to \s-1STDIN.\s0 If there is nothing waiting in the buffer during a non-blocked read, then undef will be returned. In most situations, you will probably want to use \f(CW\*(C`ReadKey \-1\*(C'\fR. .Sp \&\fI\s-1NOTE\s0\fR that if the \s-1OS\s0 does not provide any known mechanism for non-blocking reads, then a \f(CW\*(C`ReadKey \-1\*(C'\fR can die with a fatal error. This will hopefully not be common. .Sp If \s-1MODE\s0 is greater then zero, then ReadKey will use it as a timeout value in seconds (fractional seconds are allowed), and won't return \f(CW\*(C`undef\*(C'\fR until that time expires. .Sp \&\fI\s-1NOTE\s0\fR, again, that some \s-1OS\s0's may not support this timeout behaviour. .Sp If \s-1MODE\s0 is less then zero, then this is treated as a timeout of zero, and thus will return immediately if no character is waiting. A \s-1MODE\s0 of zero, however, will act like a normal getc. .Sp \&\fI\s-1NOTE\s0\fR, 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. .IP "ReadLine \s-1MODE\s0 [, Filehandle]" 4 .IX Item "ReadLine MODE [, Filehandle]" Takes an integer argument, which can currently be one of the following values: .Sp .Vb 3 \& 0 Perform a normal read using scalar() \& \-1 Perform a non\-blocked read \& >0 Perform a timed read .Ve .Sp If there is nothing waiting in the buffer during a non-blocked read, then undef will be returned. .Sp \&\fI\s-1NOTE\s0\fR, that if the \s-1OS\s0 does not provide any known mechanism for non-blocking reads, then a \f(CW\*(C`ReadLine 1\*(C'\fR can die with a fatal error. This will hopefully not be common. .Sp \&\fI\s-1NOTE\s0\fR that a non-blocking test is only performed for the first character in the line, not the entire line. This call will probably \fBnot\fR do what you assume, especially with \f(CW\*(C`ReadMode\*(C'\fR \s-1MODE\s0 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. .Sp \&\fBThis call is currently not available under Windows\fR. .IP "GetTerminalSize [Filehandle]" 4 .IX 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.) .Sp \&\fI\s-1NOTE\s0\fR, under Windows, this function must be called with an \fBoutput\fR filehandle, such as \f(CW\*(C`STDOUT\*(C'\fR, or a handle opened to \f(CW\*(C`CONOUT$\*(C'\fR. .IP "SetTerminalSize \s-1WIDTH,HEIGHT,XPIX,YPIX\s0 [, Filehandle]" 4 .IX Item "SetTerminalSize WIDTH,HEIGHT,XPIX,YPIX [, Filehandle]" Return \-1 on failure, 0 otherwise. .Sp \&\fI\s-1NOTE\s0\fR that this terminal size is only for \fBinformative\fR value, and changing the size via this mechanism will \fBnot\fR 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 \&\s-1OS\s0 will probably send a \s-1SIGWINCH\s0 signal to anything reading that tty or pty. .Sp \&\fBThis call does not work under Windows\fR. .IP "GetSpeed [, Filehandle]" 4 .IX Item "GetSpeed [, Filehandle]" Returns either an empty array if the operation is unsupported, or a two value array containing the terminal in and out speeds, in \fBdecimal\fR. 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 \s-1OS\s0's. .Sp \&\fBNo speeds are reported under Windows\fR. .IP "GetControlChars [, Filehandle]" 4 .IX 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. .Sp \&\fBThis call does nothing under Windows\fR. .Sp Each key will be an entry from the following list: .Sp .Vb 10 \& DISCARD \& DSUSPEND \& EOF \& EOL \& EOL2 \& ERASE \& ERASEWORD \& INTERRUPT \& KILL \& MIN \& QUIT \& QUOTENEXT \& REPRINT \& START \& STATUS \& STOP \& SUSPEND \& SWITCH \& TIME .Ve .Sp Thus, the following will always return the current interrupt character, regardless of platform. .Sp .Vb 2 \& %keys = GetControlChars; \& $int = $keys{INTERRUPT}; .Ve .IP "SetControlChars [, Filehandle]" 4 .IX Item "SetControlChars [, Filehandle]" Takes an array containing key/value pairs, as a hash will produce. The pairs should consist of a key that is the name of a legal control character/signal, and the value should be either a single character, or a number in the range 0\-255. SetControlChars will die with a runtime error if an invalid character name is passed or there is an error changing the settings. The list of valid names is easily available via .Sp .Vb 2 \& %cchars = GetControlChars(); \& @cnames = keys %cchars; .Ve .Sp \&\fBThis call does nothing under Windows\fR. .SH "AUTHOR" .IX Header "AUTHOR" Kenneth Albanowski .PP Currently maintained by Jonathan Stowe .SH "SUPPORT" .IX Header "SUPPORT" The code is maintained at .PP .Vb 1 \& https://github.com/jonathanstowe/TermReadKey .Ve .PP Please feel free to fork and suggest patches. .SH "LICENSE" .IX Header "LICENSE" Prior to the 2.31 release the license statement was: .PP .Vb 2 \& Copyright (C) 1994\-1999 Kenneth Albanowski. \& 2001\-2005 Jonathan Stowe and others \& \& Unlimited distribution and/or modification is allowed as long as this \& copyright notice remains intact. .Ve .PP And was only stated in the \s-1README\s0 file. .PP Because I believe the original author's intent was to be more open than the other commonly used licenses I would like to leave that in place. However if you or your lawyers require something with some more words you can optionally choose to license this under the standard Perl license: .PP .Vb 4 \& This module is free software; you can redistribute it and/or modify it \& under the terms of the Artistic License. For details, see the full \& text of the license in the file "Artistic" that should have been provided \& with the version of perl you are using. \& \& This program is distributed in the hope that it will be useful, but \& without any warranty; without even the implied warranty of merchantability \& or fitness for a particular purpose. .Ve