.\" -*- 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 3pm" .TH Term::ReadLine 3pm 2023-11-28 "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).