Term::Screen::ReadLine - Term::Screen extended with ReadLine
use lib "./blib/lib"; use Term::Screen::ReadLine; $scr = new Term::Screen::ReadLine; $scr->clrscr(); $a=$scr->getch(); print $a," ",length $a," ",ord($a),"\n"; $scr->two_esc; $a=$scr->getch(); print $a," ",length $a," ",ord($a),"\n"; $scr->one_esc; $scr->clrscr(); $scr->at(4,4)->puts("input? "); $line=$scr->readline(ROW => 4, COL => 12); $line=$scr->readline(ROW => 5, COL => 12, DISPLAYLEN => 20); $scr->at(10,4)->puts($line); $scr->two_esc; $line=$scr->readline(ROW => 6, COL => 12, DISPLAYLEN => 20, ONLYVALID => "[ieIE]+", CONVERT => "up"); print "\n"; print $scr->lastkey(),"\n"; $r=$scr->getch(); print $r,ord($r),"\n"; $r=ord($r); print $r,"\n"; if ($r eq 13) { print "aja!\n"; }
exit;
This module extends Term::Screen with a readline() function. It also makes it possible to use a *single* Esc to escape instead of the Term::Screen double Esc.
readline( ROW => 0, COL => 0, LEN => 40, DISPLAYLEN => undef, LINE => "", ONLYVALID => undef, CONVERT => undef, PASSWORD => undef, OVERWRITE => undef, )
Parameters
'at(ROW,COL) readline()...'.
The maximum length of the line to read.
The maximum length of the displayed field. The display will scroll if DISPLAYLEN is exceeded.
DISPLAYLEN
Explained below.
A default value for readline to use.
A regex to validate the input.
"up" or "lo" for uppercase or lowercase. Empty ("") if not used. Note: conversion will take place after validation.
Display stars ('*') instead of what is being typed in.
By default readline will clear characters from the current position to the end of the given field length. By setting OVERWRITE to a non-zero value will any characters visible in the field to be overwritten rather than removed.
Return value
Returns The inputted line.
Notes
The readline() function does always return on the following keys: Enter, Arrow Up, Arrow Down, Esc, Tab and Ctrl-Enter/F4.
Enter
Arrow Up
Arrow Down
Esc
Tab
Ctrl-Enter/F4
This can be extended using the EXITS argument, which must be a hash of keys (see Term::Screen) and a description that will be returned for that key.
example: EXITS => { "k1" => "help", "k3" => "cancel" }.
EXITS => { "k1" => "help", "k3" => "cancel" }
This will bind 'F1' to a 'help' message and 'F3' to a 'cancel' message.
The readline() function will issue an exit(100), if a '\0' character is read. This is what usually happens when reading from STDIN does not give 'eof()' condition as would be nice, if a telnet session is suddenly killed. Not exiting on a '\0' character will result in a racing perl script.
exit(100)
returns the last key pressed, that made the readline function return.
Makes it possible to press only one time Esc to make readline return. This is the default for Term::Screen::ReadLine.
Revert back to the standard Term::Screen behaviour for the Esc key.
Hans Dijkema <oesterhol@cpan.org>
Artistic
To install Term::Screen::ReadLine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::Screen::ReadLine
CPAN shell
perl -MCPAN -e shell install Term::Screen::ReadLine
For more information on module installation, please visit the detailed CPAN module installation guide.