man Term::ReadLine () - Perl interface to various CWreadline packages. If no real package is found, substitutes stubs instead of basic functions.
NAME
Term::ReadLine - Perl interface to various CWreadline packages. If no real package is found, substitutes stubs instead of basic functions.
SYNOPSIS
use Term::ReadLine; my $term = new Term::ReadLine 'Simple Perl calc'; my $prompt = "Enter your arithmetic expression: "; my $OUT = $term->OUT || \*STDOUT; while ( defined ($_ = $term->readline($prompt)) ) { my $res = eval($_); warn $@ if $@; print $OUT $res, "\n" unless $@; $term->addhistory($_) if /\S/; }
DESCRIPTION
This package is just a front end to some other packages. At the moment this description is written, the only such package is Term-ReadLine, available on CPAN near you. The real target of this stub package is to set up a common interface to whatever Readline emerges with time.
Minimal set of supported functions
All the supported functions should be called as methods, i.e., either as
$term = new Term::ReadLine 'name';
or as
$term->addhistory('row');
where CW$term is a return value of Term::ReadLine->new(). returns the actual package that executes the commands. Among possible values are CWTerm::ReadLine::Gnu, CWTerm::ReadLine::Perl, CWTerm::ReadLine::Stub. returns the handle for subsequent calls to following functions. Argument is the name of the application. Optionally can be followed by two arguments for CWIN and CWOUT filehandles. These arguments should be globs. gets an input line, possibly with actual CWreadline support. Trailing newline is removed. Returns CWundef on CWEOF. adds the line to the history of input, from where it can be used if the actual CWreadline is present. return the filehandles for input and output or CWundef if CWreadline input and output cannot be used for Perl. If argument is specified, it is an advice on minimal size of line to be included into history. CWundef means do not include anything into history. Returns the old value. returns an array with two strings that give most appropriate names for files for input and output using conventions CW"<$in", CW">out".
- Attribs
- returns a reference to a hash which describes internal configuration of the package. Names of keys in this hash conform to standard conventions with the leading CWrl_ stripped. Returns a reference to a hash with keys being features present in current implementation. Several optional features are used in the minimal interface: CWappname should be present if the first argument to CWnew is recognized, and CWminline should be present if CWMinLine method is not dummy. CWautohistory should be present if lines are put into history automatically (maybe subject to CWMinLine), and CWaddhistory if CWaddhistory method is not dummy. If CWFeatures method reports a feature CWattribs as present, the method CWAttribs is not dummy.
Additional supported functions
Actually CWTerm::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 CWrl_ stripped.
The stub package included with the perl distribution allows some additional methods: makes Tk event loop run when waiting for user input (i.e., during CWreadline method). makes the command line stand out by using termcap data. The argument to CWornaments should be 0, 1, or a string of a form CW"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. takes two arguments which are input filehandle and output filehandle. Switches to use these filehandles.
One can check whether the currently loaded ReadLine package supports these methods by checking for corresponding CWFeatures.
EXPORTS
None
ENVIRONMENT
The environment variable CWPERL_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 CWPerl or CWGnu.
As a special case, if the value of this variable is space-separated, the tail might be used to disable the ornaments by setting the tail to be CWo=0 or CWornaments=0. The head should be as described above, say
If the variable is not set, or if the head of space-separated list is empty, the best available package is loaded.
export "PERL_RL=Perl o=0" # Use Perl ReadLine without ornaments export "PERL_RL= o=0" # Use best available ReadLine without ornaments
(Note that processing of CWPERL_RL for ornaments is in the discretion of the particular used CWTerm::ReadLine::* package).
CAVEATS
It seems that using Term::ReadLine from Emacs minibuffer doesn't work quite right and one will get an error message like
Cannot open /dev/tty for read at ...
One possible workaround for this is to explicitly open /dev/tty like this
open (FH, "/dev/tty" ) or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }'; die $@ if $@; close (FH);
or you can try using the 4-argument form of Term::ReadLine->new().