1Term::ReadLine(3pm)    Perl Programmers Reference Guide    Term::ReadLine(3pm)
2
3
4

NAME

6       Term::ReadLine - Perl interface to various "readline" packages.  If no
7       real package is found, substitutes stubs instead of basic functions.
8

SYNOPSIS

10         use Term::ReadLine;
11         my $term = new Term::ReadLine 'Simple Perl calc';
12         my $prompt = "Enter your arithmetic expression: ";
13         my $OUT = $term->OUT ⎪⎪ \*STDOUT;
14         while ( defined ($_ = $term->readline($prompt)) ) {
15           my $res = eval($_);
16           warn $@ if $@;
17           print $OUT $res, "\n" unless $@;
18           $term->addhistory($_) if /\S/;
19         }
20

DESCRIPTION

22       This package is just a front end to some other packages. It's a stub to
23       set up a common interface to the various ReadLine implementations found
24       on CPAN (under the "Term::ReadLine::*" namespace).
25

Minimal set of supported functions

27       All the supported functions should be called as methods, i.e., either
28       as
29
30         $term = new Term::ReadLine 'name';
31
32       or as
33
34         $term->addhistory('row');
35
36       where $term is a return value of Term::ReadLine->new().
37
38       "ReadLine"  returns the actual package that executes the commands.
39                   Among possible values are "Term::ReadLine::Gnu",
40                   "Term::ReadLine::Perl", "Term::ReadLine::Stub".
41
42       "new"       returns the handle for subsequent calls to following func‐
43                   tions. Argument is the name of the application. Optionally
44                   can be followed by two arguments for "IN" and "OUT" file‐
45                   handles. These arguments should be globs.
46
47       "readline"  gets an input line, possibly with actual "readline" sup‐
48                   port. Trailing newline is removed. Returns "undef" on
49                   "EOF".
50
51       "addhistory"
52                   adds the line to the history of input, from where it can be
53                   used if the actual "readline" is present.
54
55       "IN", "OUT" return the filehandles for input and output or "undef" if
56                   "readline" input and output cannot be used for Perl.
57
58       "MinLine"   If argument is specified, it is an advice on minimal size
59                   of line to be included into history.  "undef" means do not
60                   include anything into history. Returns the old value.
61
62       "findConsole"
63                   returns an array with two strings that give most appropri‐
64                   ate names for files for input and output using conventions
65                   "<$in", ">out".
66
67       Attribs     returns a reference to a hash which describes internal con‐
68                   figuration of the package. Names of keys in this hash con‐
69                   form to standard conventions with the leading "rl_"
70                   stripped.
71
72       "Features"  Returns a reference to a hash with keys being features
73                   present in current implementation. Several optional fea‐
74                   tures are used in the minimal interface: "appname" should
75                   be present if the first argument to "new" is recognized,
76                   and "minline" should be present if "MinLine" method is not
77                   dummy.  "autohistory" should be present if lines are put
78                   into history automatically (maybe subject to "MinLine"),
79                   and "addhistory" if "addhistory" method is not dummy.
80
81                   If "Features" method reports a feature "attribs" as
82                   present, the method "Attribs" is not dummy.
83

Additional supported functions

85       Actually "Term::ReadLine" can use some other package, that will support
86       a richer set of commands.
87
88       All these commands are callable via method interface and have names
89       which conform to standard conventions with the leading "rl_" stripped.
90
91       The stub package included with the perl distribution allows some addi‐
92       tional methods:
93
94       "tkRunning" makes Tk event loop run when waiting for user input (i.e.,
95                   during "readline" method).
96
97       "ornaments" makes the command line stand out by using termcap data.
98                   The argument to "ornaments" should be 0, 1, or a string of
99                   a form "aa,bb,cc,dd".  Four components of this string
100                   should be names of terminal capacities, first two will be
101                   issued to make the prompt standout, last two to make the
102                   input line standout.
103
104       "newTTY"    takes two arguments which are input filehandle and output
105                   filehandle.  Switches to use these filehandles.
106
107       One can check whether the currently loaded ReadLine package supports
108       these methods by checking for corresponding "Features".
109

EXPORTS

111       None
112

ENVIRONMENT

114       The environment variable "PERL_RL" governs which ReadLine clone is
115       loaded. If the value is false, a dummy interface is used. If the value
116       is true, it should be tail of the name of the package to use, such as
117       "Perl" or "Gnu".
118
119       As a special case, if the value of this variable is space-separated,
120       the tail might be used to disable the ornaments by setting the tail to
121       be "o=0" or "ornaments=0".  The head should be as described above, say
122
123       If the variable is not set, or if the head of space-separated list is
124       empty, the best available package is loaded.
125
126         export "PERL_RL=Perl o=0"     # Use Perl ReadLine without ornaments
127         export "PERL_RL= o=0"         # Use best available ReadLine without ornaments
128
129       (Note that processing of "PERL_RL" for ornaments is in the discretion
130       of the particular used "Term::ReadLine::*" package).
131

CAVEATS

133       It seems that using Term::ReadLine from Emacs minibuffer doesn't work
134       quite right and one will get an error message like
135
136           Cannot open /dev/tty for read at ...
137
138       One possible workaround for this is to explicitly open /dev/tty like
139       this
140
141           open (FH, "/dev/tty" )
142             or eval 'sub Term::ReadLine::findConsole { ("&STDIN", "&STDERR") }';
143           die $@ if $@;
144           close (FH);
145
146       or you can try using the 4-argument form of Term::ReadLine->new().
147
148
149
150perl v5.8.8                       2001-09-21               Term::ReadLine(3pm)
Impressum