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 = Term::ReadLine->new('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 = Term::ReadLine->new('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
43                   functions. Argument is the name of the application.
44                   Optionally can be followed by two arguments for "IN" and
45                   "OUT" filehandles. These arguments should be globs.
46
47       "readline"  gets an input line, possibly with actual "readline"
48                   support. 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
64                   appropriate names for files for input and output using
65                   conventions "<$in", ">out".
66
67                   The strings returned may not be useful for 3-argument
68                   open().
69
70       Attribs     returns a reference to a hash which describes internal
71                   configuration of the package. Names of keys in this hash
72                   conform to standard conventions with the leading "rl_"
73                   stripped.
74
75       "Features"  Returns a reference to a hash with keys being features
76                   present in current implementation. Several optional
77                   features are used in the minimal interface: "appname"
78                   should be present if the first argument to "new" is
79                   recognized, and "minline" should be present if "MinLine"
80                   method is not dummy.  "autohistory" should be present if
81                   lines are put into history automatically (maybe subject to
82                   "MinLine"), and "addhistory" if "addhistory" method is not
83                   dummy.
84
85                   If "Features" method reports a feature "attribs" as
86                   present, the method "Attribs" is not dummy.
87

Additional supported functions

89       Actually "Term::ReadLine" can use some other package, that will support
90       a richer set of commands.
91
92       All these commands are callable via method interface and have names
93       which conform to standard conventions with the leading "rl_" stripped.
94
95       The stub package included with the perl distribution allows some
96       additional methods:
97
98       "tkRunning" makes Tk event loop run when waiting for user input (i.e.,
99                   during "readline" method).
100
101       "event_loop"
102                   Registers call-backs to wait for user input (i.e., during
103                   "readline" method).  This supersedes tkRunning.
104
105                   The first call-back registered is the call back for
106                   waiting.  It is expected that the callback will call the
107                   current event loop until there is something waiting to get
108                   on the input filehandle.  The parameter passed in is the
109                   return value of the second call back.
110
111                   The second call-back registered is the call back for
112                   registration.  The input filehandle (often STDIN, but not
113                   necessarily) will be passed in.
114
115                   For example, with AnyEvent:
116
117                     $term->event_loop(sub {
118                       my $data = shift;
119                       $data->[1] = AE::cv();
120                       $data->[1]->recv();
121                     }, sub {
122                       my $fh = shift;
123                       my $data = [];
124                       $data->[0] = AE::io($fh, 0, sub { $data->[1]->send() });
125                       $data;
126                     });
127
128                   The second call-back is optional if the call back is
129                   registered prior to the call to $term->readline.
130
131                   Deregistration is done in this case by calling event_loop
132                   with "undef" as its parameter:
133
134                       $term->event_loop(undef);
135
136                   This will cause the data array ref to be removed, allowing
137                   normal garbage collection to clean it up.  With AnyEvent,
138                   that will cause $data->[0] to be cleaned up, and AnyEvent
139                   will automatically cancel the watcher at that time.  If
140                   another loop requires more than that to clean up a file
141                   watcher, that will be up to the caller to handle.
142
143       "ornaments" makes the command line stand out by using termcap data.
144                   The argument to "ornaments" should be 0, 1, or a string of
145                   a form "aa,bb,cc,dd".  Four components of this string
146                   should be names of terminal capacities, first two will be
147                   issued to make the prompt standout, last two to make the
148                   input line standout.
149
150       "newTTY"    takes two arguments which are input filehandle and output
151                   filehandle.  Switches to use these filehandles.
152
153       One can check whether the currently loaded ReadLine package supports
154       these methods by checking for corresponding "Features".
155

EXPORTS

157       None
158

ENVIRONMENT

160       The environment variable "PERL_RL" governs which ReadLine clone is
161       loaded. If the value is false, a dummy interface is used. If the value
162       is true, it should be tail of the name of the package to use, such as
163       "Perl" or "Gnu".
164
165       As a special case, if the value of this variable is space-separated,
166       the tail might be used to disable the ornaments by setting the tail to
167       be "o=0" or "ornaments=0".  The head should be as described above, say
168
169       If the variable is not set, or if the head of space-separated list is
170       empty, the best available package is loaded.
171
172         export "PERL_RL=Perl o=0" # Use Perl ReadLine sans ornaments
173         export "PERL_RL= o=0"     # Use best available ReadLine sans ornaments
174
175       (Note that processing of "PERL_RL" for ornaments is in the discretion
176       of the particular used "Term::ReadLine::*" package).
177
178
179
180perl v5.28.2                      2018-11-01               Term::ReadLine(3pm)
Impressum