use Term::ReadLine; $term = new Term::ReadLine 'Simple Perl calc'; $prompt = "Enter your arithmetic expression: "; $OUT = $term->OUT || STDOUT; while ( defined ($_ = $term->readline($prompt)) ) { $res = eval($_), "\n"; warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; }
$term = new Term::ReadLine 'name';
or as
$term->addhistory('row');
where $term
is a return value of Term::ReadLine->Init.
Term::ReadLine::Gnu
, Term::ReadLine::Perl
,
Term::ReadLine::Stub Exporter
.
OUT
filehandles. These arguments should be globs.
EOF
.
"<$in"
, ">out"
.
rl_
stripped.
appname
should be present if the first argument to new is recognized, and minline
should be present if
MinLine method is not dummy. autohistory
should be present if lines are put into history automatically (maybe
subject to
MinLine), and addhistory if addhistory method is not dummy.
If Features method reports a feature attribs
as present, the method Attribs is not dummy.
Term::ReadLine
can use some other package, that will support reacher set of commands.
All these commands are callable via method interface and have names which
conform to standard conventions with the leading rl_
stripped.
The stub package included with the perl distribution allows two additional
methods: tkRunning
and ornaments
. The first one makes Tk event loop run when waiting for user input (i.e.,
during
readline method), the second one makes the command line stand out by using termcap
data. The argument to ornaments
should be 0, 1, or a string of a form ``aa,bb,cc,dd''. Four components of
this string should be names of terminal capacities, first two will be issued to make the prompt standout, last two to make
the input line standout.
PERL_RL
governs which ReadLine clone is loaded. If the value is false, a dummy
interface is used. If the value is true, it should be tail of the name of
the package to use, such as Perl
or
Gnu
.
If the variable is not set, the best available package is loaded.