Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Term::ReadLine.3pm

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