1N/ATerm::ReadLine - Perl interface to various C<readline> packages. 1N/AIf no real package is found, substitutes stubs instead of basic functions. 1N/A my $term = new Term::ReadLine 'Simple Perl calc'; 1N/A my $prompt = "Enter your arithmetic expression: "; 1N/A my $OUT = $term->OUT || \*STDOUT; 1N/A while ( defined ($_ = $term->readline($prompt)) ) { 1N/A print $OUT $res, "\n" unless $@; 1N/A $term->addhistory($_) if /\S/; 1N/AThis package is just a front end to some other packages. At the moment 1N/Athis description is written, the only such package is Term-ReadLine, 1N/Aavailable on CPAN near you. The real target of this stub package is to 1N/Aset up a common interface to whatever Readline emerges with time. 1N/A=head1 Minimal set of supported functions 1N/AAll the supported functions should be called as methods, i.e., either as 1N/A $term = new Term::ReadLine 'name'; 1N/A $term->addhistory('row'); 1N/Awhere $term is a return value of Term::ReadLine-E<gt>new(). 1N/Areturns the actual package that executes the commands. Among possible 1N/Avalues are C<Term::ReadLine::Gnu>, C<Term::ReadLine::Perl>, 1N/AC<Term::ReadLine::Stub>. 1N/Areturns the handle for subsequent calls to following 1N/Afunctions. Argument is the name of the application. Optionally can be 1N/Afollowed by two arguments for C<IN> and C<OUT> filehandles. These 1N/Aarguments should be globs. 1N/Agets an input line, I<possibly> with actual C<readline> 1N/Asupport. Trailing newline is removed. Returns C<undef> on C<EOF>. 1N/Aadds the line to the history of input, from where it can be used if 1N/Athe actual C<readline> is present. 1N/Areturn the filehandles for input and output or C<undef> if C<readline> 1N/Ainput and output cannot be used for Perl. 1N/AIf argument is specified, it is an advice on minimal size of line to 1N/Abe included into history. C<undef> means do not include anything into 1N/Ahistory. Returns the old value. 1N/Areturns an array with two strings that give most appropriate names for 1N/Afiles for input and output using conventions C<"E<lt>$in">, C<"E<gt>out">. 1N/Areturns a reference to a hash which describes internal configuration 1N/Aof the package. Names of keys in this hash conform to standard 1N/Aconventions with the leading C<rl_> stripped. 1N/AReturns a reference to a hash with keys being features present in 1N/Acurrent implementation. Several optional features are used in the 1N/Aminimal interface: C<appname> should be present if the first argument 1N/Ato C<new> is recognized, and C<minline> should be present if 1N/AC<MinLine> method is not dummy. C<autohistory> should be present if 1N/Alines are put into history automatically (maybe subject to 1N/AC<MinLine>), and C<addhistory> if C<addhistory> method is not dummy. 1N/AIf C<Features> method reports a feature C<attribs> as present, the 1N/Amethod C<Attribs> is not dummy. 1N/A=head1 Additional supported functions 1N/AActually C<Term::ReadLine> can use some other package, that will 1N/Asupport reacher set of commands. 1N/AAll these commands are callable via method interface and have names 1N/Awhich conform to standard conventions with the leading C<rl_> stripped. 1N/AThe stub package included with the perl distribution allows some 1N/Amakes Tk event loop run when waiting for user input (i.e., during 1N/Amakes the command line stand out by using termcap data. The argument 1N/Ato C<ornaments> should be 0, 1, or a string of a form 1N/AC<"aa,bb,cc,dd">. Four components of this string should be names of 1N/AI<terminal capacities>, first two will be issued to make the prompt 1N/Astandout, last two to make the input line standout. 1N/Atakes two arguments which are input filehandle and output filehandle. 1N/ASwitches to use these filehandles. 1N/AOne can check whether the currently loaded ReadLine package supports 1N/Athese methods by checking for corresponding C<Features>. 1N/AThe environment variable C<PERL_RL> governs which ReadLine clone is 1N/Aloaded. If the value is false, a dummy interface is used. If the value 1N/Ais true, it should be tail of the name of the package to use, such as 1N/AAs a special case, if the value of this variable is space-separated, 1N/Athe tail might be used to disable the ornaments by setting the tail to 1N/Abe C<o=0> or C<ornaments=0>. The head should be as described above, say 1N/AIf the variable is not set, or if the head of space-separated list is 1N/Aempty, the best available package is loaded. 1N/A export "PERL_RL=Perl o=0" # Use Perl ReadLine without ornaments 1N/A export "PERL_RL= o=0" # Use best available ReadLine without ornaments 1N/A(Note that processing of C<PERL_RL> for ornaments is in the discretion of the 1N/Aparticular used C<Term::ReadLine::*> package). 1N/AIt seems that using Term::ReadLine from Emacs minibuffer doesn't work 1N/Aquite right and one will get an error message like 1N/AOne possible workaround for this is to explicitly open /dev/tty like this 1N/A or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }'; 1N/Aor you can try using the 4-argument form of Term::ReadLine->new(). 1N/Aour @
ISA =
qw'Term::ReadLine::Tk Term::ReadLine::TermCap';
1N/A #$str = scalar <$in>; 1N/A # bug in 5.000: chomping empty string creats length -1: 1N/A if ($^O
eq 'MacOS') {
1N/A }
elsif (-e
"con" or $^O
eq 'MSWin32') {
1N/A if (($^O
eq 'amigaos') || ($^O
eq 'beos') || ($^O
eq 'epoc')) {
1N/A elsif ($^O
eq 'os2') {
1N/A die "method new called with wrong number of arguments" 1N/A unless @_==
2 or @_==
4;
1N/A #local (*FIN, *FOUT); 1N/A #OUT->autoflush(1); # Conflicts with debugger? 1N/A $| =
1;
# for DB::OUT 1N/A }
else {
# Filehandles supplied 1N/A #OUT->autoflush(1); # Conflicts with debugger? 1N/A $| =
1;
# for DB::OUT 1N/A $| =
1;
# for DB::OUT 1N/A eval "use Term::ReadLine::Gnu;";
1N/A eval "use Term::ReadLine::Perl;";
1N/A eval "use Term::ReadLine::$which;";
1N/A eval "use Term::ReadLine::Gnu; 1" or eval "use Term::ReadLine::Perl; 1";
1N/A# To make possible switch off RL in debugger: (Not needed, work done 1N/A}
elsif (
defined $
which &&
defined &{
"Term::ReadLine::$which\::readline"}) {
1N/A @
ISA =
"Term::ReadLine::$which";
1N/A# Prompt-start, prompt-end, command-line-start, command-line-end 1N/A# -- zero-width beautifies to emit around prompt and the command line. 1N/A # Tk->tkwait('variable',\$giveup); # needs Widget