summaryrefslogtreecommitdiffstats
path: root/upstream/debian-unstable/man3/Term::ReadLine.3perl
blob: b60a0c51f9ec9652853c4ec43ef879a7c4e6ea39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Term::ReadLine 3perl"
.TH Term::ReadLine 3perl 2024-05-30 "perl v5.38.2" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
Term::ReadLine \- Perl interface to various "readline" packages.
If no real package is found, substitutes stubs instead of basic functions.
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 10
\&  use Term::ReadLine;
\&  my $term = Term::ReadLine\->new(\*(AqSimple Perl calc\*(Aq);
\&  my $prompt = "Enter your arithmetic expression: ";
\&  my $OUT = $term\->OUT || \e*STDOUT;
\&  while ( defined ($_ = $term\->readline($prompt)) ) {
\&    my $res = eval($_);
\&    warn $@ if $@;
\&    print $OUT $res, "\en" unless $@;
\&    $term\->addhistory($_) if /\eS/;
\&  }
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
This package is just a front end to some other packages. It's a stub to
set up a common interface to the various ReadLine implementations found on
CPAN (under the \f(CW\*(C`Term::ReadLine::*\*(C'\fR namespace).
.SH "Minimal set of supported functions"
.IX Header "Minimal set of supported functions"
All the supported functions should be called as methods, i.e., either as
.PP
.Vb 1
\&  $term = Term::ReadLine\->new(\*(Aqname\*(Aq);
.Ve
.PP
or as
.PP
.Vb 1
\&  $term\->addhistory(\*(Aqrow\*(Aq);
.Ve
.PP
where \f(CW$term\fR is a return value of Term::ReadLine\->\fBnew()\fR.
.ie n .IP """ReadLine""" 12
.el .IP \f(CWReadLine\fR 12
.IX Item "ReadLine"
returns the actual package that executes the commands. Among possible
values are \f(CW\*(C`Term::ReadLine::Gnu\*(C'\fR, \f(CW\*(C`Term::ReadLine::Perl\*(C'\fR,
\&\f(CW\*(C`Term::ReadLine::Stub\*(C'\fR.
.ie n .IP """new""" 12
.el .IP \f(CWnew\fR 12
.IX Item "new"
returns the handle for subsequent calls to following
functions. Argument is the name of the application. Optionally can be
followed by two arguments for \f(CW\*(C`IN\*(C'\fR and \f(CW\*(C`OUT\*(C'\fR filehandles. These
arguments should be globs.
.ie n .IP """readline""" 12
.el .IP \f(CWreadline\fR 12
.IX Item "readline"
gets an input line, \fIpossibly\fR with actual \f(CW\*(C`readline\*(C'\fR
support. Trailing newline is removed. Returns \f(CW\*(C`undef\*(C'\fR on \f(CW\*(C`EOF\*(C'\fR.
.ie n .IP """addhistory""" 12
.el .IP \f(CWaddhistory\fR 12
.IX Item "addhistory"
adds the line to the history of input, from where it can be used if
the actual \f(CW\*(C`readline\*(C'\fR is present.
.ie n .IP """IN"", ""OUT""" 12
.el .IP "\f(CWIN\fR, \f(CWOUT\fR" 12
.IX Item "IN, OUT"
return the filehandles for input and output or \f(CW\*(C`undef\*(C'\fR if \f(CW\*(C`readline\*(C'\fR
input and output cannot be used for Perl.
.ie n .IP """MinLine""" 12
.el .IP \f(CWMinLine\fR 12
.IX Item "MinLine"
If argument is specified, it is an advice on minimal size of line to
be included into history.  \f(CW\*(C`undef\*(C'\fR means do not include anything into
history. Returns the old value.
.ie n .IP """findConsole""" 12
.el .IP \f(CWfindConsole\fR 12
.IX Item "findConsole"
returns an array with two strings that give most appropriate names for
files for input and output using conventions \f(CW"<$in"\fR, \f(CW">out"\fR.
.Sp
The strings returned may not be useful for 3\-argument \fBopen()\fR.
.IP Attribs 12
.IX Item "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 \f(CW\*(C`rl_\*(C'\fR stripped.
.ie n .IP """Features""" 12
.el .IP \f(CWFeatures\fR 12
.IX Item "Features"
Returns a reference to a hash with keys being features present in
current implementation. Several optional features are used in the
minimal interface: \f(CW\*(C`appname\*(C'\fR should be present if the first argument
to \f(CW\*(C`new\*(C'\fR is recognized, and \f(CW\*(C`minline\*(C'\fR should be present if
\&\f(CW\*(C`MinLine\*(C'\fR method is not dummy.  \f(CW\*(C`autohistory\*(C'\fR should be present if
lines are put into history automatically (maybe subject to
\&\f(CW\*(C`MinLine\*(C'\fR), and \f(CW\*(C`addhistory\*(C'\fR if \f(CW\*(C`addhistory\*(C'\fR method is not dummy.
.Sp
If \f(CW\*(C`Features\*(C'\fR method reports a feature \f(CW\*(C`attribs\*(C'\fR as present, the
method \f(CW\*(C`Attribs\*(C'\fR is not dummy.
.SH "Additional supported functions"
.IX Header "Additional supported functions"
Actually \f(CW\*(C`Term::ReadLine\*(C'\fR can use some other package, that will
support a richer set of commands.
.PP
All these commands are callable via method interface and have names
which conform to standard conventions with the leading \f(CW\*(C`rl_\*(C'\fR stripped.
.PP
The stub package included with the perl distribution allows some
additional methods:
.ie n .IP """tkRunning""" 12
.el .IP \f(CWtkRunning\fR 12
.IX Item "tkRunning"
makes Tk event loop run when waiting for user input (i.e., during
\&\f(CW\*(C`readline\*(C'\fR method).
.ie n .IP """event_loop""" 12
.el .IP \f(CWevent_loop\fR 12
.IX Item "event_loop"
Registers call-backs to wait for user input (i.e., during \f(CW\*(C`readline\*(C'\fR
method).  This supersedes tkRunning.
.Sp
The first call-back registered is the call back for waiting.  It is
expected that the callback will call the current event loop until
there is something waiting to get on the input filehandle.  The parameter
passed in is the return value of the second call back.
.Sp
The second call-back registered is the call back for registration.  The
input filehandle (often STDIN, but not necessarily) will be passed in.
.Sp
For example, with AnyEvent:
.Sp
.Vb 10
\&  $term\->event_loop(sub {
\&    my $data = shift;
\&    $data\->[1] = AE::cv();
\&    $data\->[1]\->recv();
\&  }, sub {
\&    my $fh = shift;
\&    my $data = [];
\&    $data\->[0] = AE::io($fh, 0, sub { $data\->[1]\->send() });
\&    $data;
\&  });
.Ve
.Sp
The second call-back is optional if the call back is registered prior to
the call to \f(CW$term\fR\->readline.
.Sp
Deregistration is done in this case by calling event_loop with \f(CW\*(C`undef\*(C'\fR
as its parameter:
.Sp
.Vb 1
\&    $term\->event_loop(undef);
.Ve
.Sp
This will cause the data array ref to be removed, allowing normal garbage
collection to clean it up.  With AnyEvent, that will cause \f(CW$data\fR\->[0] to
be cleaned up, and AnyEvent will automatically cancel the watcher at that
time.  If another loop requires more than that to clean up a file watcher,
that will be up to the caller to handle.
.ie n .IP """ornaments""" 12
.el .IP \f(CWornaments\fR 12
.IX Item "ornaments"
makes the command line stand out by using termcap data.  The argument
to \f(CW\*(C`ornaments\*(C'\fR should be 0, 1, or a string of a form
\&\f(CW"aa,bb,cc,dd"\fR.  Four components of this string should be names of
\&\fIterminal capacities\fR, first two will be issued to make the prompt
standout, last two to make the input line standout.
.ie n .IP """newTTY""" 12
.el .IP \f(CWnewTTY\fR 12
.IX Item "newTTY"
takes two arguments which are input filehandle and output filehandle.
Switches to use these filehandles.
.PP
One can check whether the currently loaded ReadLine package supports
these methods by checking for corresponding \f(CW\*(C`Features\*(C'\fR.
.SH EXPORTS
.IX Header "EXPORTS"
None
.SH ENVIRONMENT
.IX Header "ENVIRONMENT"
The environment variable \f(CW\*(C`PERL_RL\*(C'\fR 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
\&\f(CW\*(C`Perl\*(C'\fR or \f(CW\*(C`Gnu\*(C'\fR.
.PP
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 \f(CW\*(C`o=0\*(C'\fR or \f(CW\*(C`ornaments=0\*(C'\fR.  The head should be as described above, say
.PP
If the variable is not set, or if the head of space-separated list is
empty, the best available package is loaded.
.PP
.Vb 2
\&  export "PERL_RL=Perl o=0" # Use Perl ReadLine sans ornaments
\&  export "PERL_RL= o=0"     # Use best available ReadLine sans ornaments
.Ve
.PP
(Note that processing of \f(CW\*(C`PERL_RL\*(C'\fR for ornaments is in the discretion of the 
particular used \f(CW\*(C`Term::ReadLine::*\*(C'\fR package).