| 1 | # -*- Perl -*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Term::ReadLine::Perl5; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 Name | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | Term::ReadLine::Perl5 - A Perl5 implementation GNU Readline | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head2 Overview | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | This is a implementation of the GNU Readline/History Library written | ||||||||||||||||||||||||||||||||||||||||||
| 12 | in Perl5. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | GNU Readline reads lines from an interactive terminal with I<emacs> or | ||||||||||||||||||||||||||||||||||||||||||
| 15 | I<vi> editing capabilities. It provides as mechanism for saving | ||||||||||||||||||||||||||||||||||||||||||
| 16 | history of previous input. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | This package typically used in command-line interfaces and REPLs (Read, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | Eval, Print, Loop). | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head2 Demo program | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | Another package, L<Term::ReadLine::Perl5::Demo> is available to let | ||||||||||||||||||||||||||||||||||||||||||
| 24 | you run I<Term::ReadLine::Perl5> to experiment with its capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 25 | and show how to use the API. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =head1 Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | use Term::ReadLine::Perl5; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | $term = Term::ReadLine::Perl5->new('ProgramName'); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | while ( defined ($_ = $term->readline('prompt>')) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | ▶ | use warnings; use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | use Term::ReadLine::Perl5::readline; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | our $VERSION = '1.43'; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | eval "use rlib '.' "; # rlib is now optional | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | use Term::ReadLine::Perl5::History; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | use Term::ReadLine::Perl5::OO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | ▶ | use Term::ReadLine::Perl5::OO::History; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | use Term::ReadLine::Perl5::Tie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | use Term::ReadLine::Perl5::readline; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | if (require Term::ReadLine) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | our @ISA = qw(Term::ReadLine::Stub Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | my (%attribs, $term); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | our @EXPORT = qw(IN OUT); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head2 Variables | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Following GNU Readline/History Library variables can be accessed from | ||||||||||||||||||||||||||||||||||||||||||
| 61 | Perl program. See 'GNU Readline Library Manual' and ' GNU History | ||||||||||||||||||||||||||||||||||||||||||
| 62 | Library Manual' for each variable. You can access them via the | ||||||||||||||||||||||||||||||||||||||||||
| 63 | C<Attribs> method. Names of keys in this hash conform to standard | ||||||||||||||||||||||||||||||||||||||||||
| 64 | conventions with the leading C<rl_> stripped. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | Example: | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | $term = Term::ReadLine::Perl5->new('ReadLineTest'); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | $attribs = $term->Attribs; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | $v = $attribs->{history_base}; # history_base | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head3 Attribute Names | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | completion_suppress_append (bool) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | history_base (int) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | history_stifled (int) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | max_input_history (int) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | outstream (file handle) | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | my %features = ( | |||||||||||||||||||||||||||||||||||||||||
| 83 | appname => 1, # "new" is recognized | ||||||||||||||||||||||||||||||||||||||||||
| 84 | minline => 1, # we have a working MinLine() | ||||||||||||||||||||||||||||||||||||||||||
| 85 | autohistory => 1, # lines are put into history automatically, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # subject to MinLine() | ||||||||||||||||||||||||||||||||||||||||||
| 87 | getHistory => 1, # we have a working getHistory() | ||||||||||||||||||||||||||||||||||||||||||
| 88 | setHistory => 1, # we have a working setHistory() | ||||||||||||||||||||||||||||||||||||||||||
| 89 | addHistory => 1, # we have a working add_history(), addhistory(), | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # or addHistory() | ||||||||||||||||||||||||||||||||||||||||||
| 91 | readHistory => 1, # we have read_history() or readHistory() | ||||||||||||||||||||||||||||||||||||||||||
| 92 | writeHistory => 1, # we have writeHistory() | ||||||||||||||||||||||||||||||||||||||||||
| 93 | preput => 1, # the second argument to readline is processed | ||||||||||||||||||||||||||||||||||||||||||
| 94 | attribs => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | newTTY => 1, # we have newTTY() | ||||||||||||||||||||||||||||||||||||||||||
| 96 | stiflehistory => 1, # we have stifle_history() | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | ▶ | tie %attribs, 'Term::ReadLine::Perl5::Tie' or die ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | sub Attribs { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | \%attribs; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Attribs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 Subroutine | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head2 Standard Term::ReadLine Methods | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | These methods are standard methods defined by | ||||||||||||||||||||||||||||||||||||||||||
| 109 | L<Term::ReadLine>. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | =head3 C<ReadLine> | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | Readline() -> 'Term::ReadLine::Perl5' | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | returns the actual package that executes the commands. If this package | ||||||||||||||||||||||||||||||||||||||||||
| 116 | is used, the value is C<Term::ReadLine::Perl5>. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | sub ReadLine {'Term::ReadLine::Perl5'} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ReadLine: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head3 readline | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | $bool = $term->readline($prompt, $default) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | The main routine to call interactively read lines. Parameter | ||||||||||||||||||||||||||||||||||||||||||
| 127 | I<$prompt> is the text you want to prompt with If it is empty string, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | no preceding prompt text is given. It is I<undef> a default value of | ||||||||||||||||||||||||||||||||||||||||||
| 129 | "INPUT> " is used. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | Parameter I<$default> is the default value; it can be can be | ||||||||||||||||||||||||||||||||||||||||||
| 132 | omitted. The next input line is returned or I<undef> on EOF. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub readline { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | &Term::ReadLine::Perl5::readline::readline(@_); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =head3 new | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | B<new>(I<$name>,[I<IN>[,I<OUT>]]) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | returns the handle for subsequent calls to following functions. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | Argument is the name of the application. Optionally can be followed | ||||||||||||||||||||||||||||||||||||||||||
| 147 | by two arguments for C<IN> and C<OUT> file handles. These arguments | ||||||||||||||||||||||||||||||||||||||||||
| 148 | should be globs. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | I<$name> is the name of the application. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | This routine may also get called via | ||||||||||||||||||||||||||||||||||||||||||
| 153 | C<Term::ReadLine-E<gt>new($term_name)> if you have | ||||||||||||||||||||||||||||||||||||||||||
| 154 | C<$ENV{PERL_RL}> set to 'Perl5'; | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | At present, because this code has lots of global state, we currently don't | ||||||||||||||||||||||||||||||||||||||||||
| 157 | support more than one readline instance. | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 160 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=42.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | ▶ | if (require Term::ReadLine) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | $features{tkRunning} = Term::ReadLine::Stub->Features->{'tkRunning'}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | $features{ornaments} = Term::ReadLine::Stub->Features->{'ornaments'}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | if (defined $term) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $stderr = $Term::ReadLine::Perl5::readline::term_OUT; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | print $stderr "Cannot create second readline interface\n"; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | print "Using experimental OO interface based on Caroline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my ($name, $in, $out) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $opts = { | |||||||||||||||||||||||||||||||||||||||||
| 172 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | in => $in, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | out => $out, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return Term::ReadLine::Perl5::OO->new($opts); | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | shift; # Package name | |||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ($term) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | warn "Ignoring name of second readline interface.\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | if defined $term; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # Set Name | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $Term::ReadLine::Perl5::readline::rl_readline_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | if (!@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | ▶ | if (!defined $term) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | my ($IN,$OUT) = Term::ReadLine->findConsole(); | |||||||||||||||||||||||||||||||||||||||||
| 192 | # Old Term::ReadLine did not have a workaround for a bug | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # in Win devdriver | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | $IN = 'CONIN$' if $^O eq 'MSWin32' and "\U$IN" eq 'CON'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$^O eq "MSWin32" and uc $IN eq "CON"
MC/DC0%0/2
$^O eq "MSWin32" and uc $IN eq "CON"
$^O eq "MSWin32"
uc $IN eq "CON"
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= uc $IN eq "CON"
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | open(my $in_fh, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$IN eq "CONIN\$" and $^O eq "MSWin32"
MC/DC0%0/2
$IN eq "CONIN\$" and $^O eq "MSWin32"
$IN eq "CONIN\$"
$^O eq "MSWin32"
Truth table33%1/3
A and B
A= $IN eq "CONIN\$"B= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | # A workaround for another bug in Win device driver | ||||||||||||||||||||||||||||||||||||||||||
| 197 | (($IN eq 'CONIN$' and $^O eq 'MSWin32') ? "+< $IN" : "< $IN")) | ||||||||||||||||||||||||||||||||||||||||||
| 198 | or croak "Cannot open $IN for read"; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | ▶ | open(my $out_fh, ">$OUT") || croak "Cannot open $OUT for write: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | $Term::ReadLine::Perl5::readline::term_IN = $in_fh; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | $Term::ReadLine::Perl5::readline::term_OUT = $out_fh; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (defined $term and ($term->IN ne $_[0] or $term->OUT ne $_[1]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $term and $term->IN ne $_[0] || $term->OUT ne $_[1]
$term->IN ne $_[0] or $term->OUT ne $_[1]
MC/DC0%0/3
defined $term and $term->IN ne $_[0] || $term->OUT ne $_[1]
defined $term
$term->IN ne $_[0]
$term->OUT ne $_[1]
Truth table0%0/4
A and B or C
A= defined $termB= $term->IN ne $_[0]C= $term->OUT ne $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | croak "Request for a second readline interface with different terminal"; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $Term::ReadLine::Perl5::readline::term_IN = shift; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $Term::ReadLine::readline::term_OUT = shift | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # The following is here since it is mostly used for perl input: | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # $readline::rl_basic_word_break_characters .= '-:+/*,[])}'; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | $term = bless [$readline::term_IN,$readline::term_OUT]; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 214 | 'IN' => $readline::term_IN, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 'OUT' => $readline::term_OUT, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | ▶ | unless ($ENV{PERL_RL} and $ENV{PERL_RL} =~ /\bo\w*=0/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{"PERL_RL"} and $ENV{"PERL_RL"} =~ /\bo\w*=0/
MC/DC0%0/2
$ENV{"PERL_RL"} and $ENV{"PERL_RL"} =~ /\bo\w*=0/
$ENV{"PERL_RL"}
$ENV{"PERL_RL"} =~ /\bo\w*=0/
Truth table66%2/3
A and B
A= $ENV{"PERL_RL"}B= $ENV{"PERL_RL"} =~ /\bo\w*=0/
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | local $Term::ReadLine::termcap_nowarn = 1; # With newer Perls | |||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | local $SIG{__WARN__} = sub {}; # With older Perls | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | $term->ornaments(1); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | # FIXME: something rl_term_set in here causes terminal attributes | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # like bold and underline to work. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | Term::ReadLine::Perl5::readline::rl_term_set(); | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | =head3 IN | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | B<Term::ReadLine::Perl5-E<gt>IN> | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | Returns the input filehandle | ||||||||||||||||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 238 | sub IN { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
IN: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->{IN}; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | =head3 OUT | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | B<Term::ReadLine::Perl5-E<gt>OUT> | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | Returns the output filehandle | ||||||||||||||||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 249 | sub OUT { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
OUT: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | $self->{OUT}; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | =head3 newTTY | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | B<Term::ReadLine::Perl5-E<gt>newTTY>(I<IN>, I<OUT>) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | takes two arguments which are input filehandle and output filehandle. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | Switches to use these filehandles. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 262 | sub newTTY($$$) { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | my ($self, $in, $out) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newTTY: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $Term::ReadLine::Perl5::readline::term_IN = $self->{'IN'} = $in; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $Term::ReadLine::Perl5::readline::term_OUT = $self->{'OUT'} = $out; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $sel = select($out); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $| = 1; # for DB::OUT | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | select($sel); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | =head3 Minline | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | B<MinLine>([I<$minlength>])> | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | If B<$minlength> is given, set C<$readline::minlength> the minimum | ||||||||||||||||||||||||||||||||||||||||||
| 276 | length a $line for it to go into the readline history. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | The previous value is returned. | ||||||||||||||||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 280 | sub MinLine($;$) { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | my $old = $minlength; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MinLine: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | $minlength = $_[1] if @_ == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return $old; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | #################### History ########################################## | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | =head3 add_history | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | $term->add_history>($line1, $line2, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | adds the lines, I<$line1>, etc. to the input history list. | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | I<AddHistory> is an alias for this function. | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # GNU ReadLine names | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | *add_history = \&Term::ReadLine::Perl5::History::add_history; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 9 | *remove_history = \&Term::ReadLine::Perl5::History::remove_history; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 9 | *replace_history_entry = \&Term::ReadLine::Perl5::History::replace_history_entry; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | *clear_history = \&Term::ReadLine::Perl5::History::clear_history; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | *history_is_stifled = \&Term::ReadLine::Perl5::History::history_is_stifled; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 9 | *read_history = \&Term::ReadLine::Perl5::History::read_history; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 9 | *unstifle_history = \&Term::ReadLine::Perl5::History::unstifle_history; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | *write_history = \&Term::ReadLine::Perl5::History::write_history; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Not sure about the difference between history_list and GetHistory. | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | *history_list = \&Term::ReadLine::Perl5::OO::GetHistory; | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 9 | *rl_History = *Term::ReadLine::Perl5::rl_History; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | # Some Term::ReadLine::Gnu names | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 9 | *AddHistory = \&add_history; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 9 | *GetHistory = \&Term::ReadLine::Perl5::History::GetHistory; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 9 | *SetHistory = \&Term::ReadLine::Perl5::History::SetHistory; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 9 | *ReadHistory = \&Term::ReadLine::Perl5::History::ReadHistory; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 9 | *WriteHistory = \&Term::ReadLine::Perl5::History::WriteHistory; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | # Backward compatibility: | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 9 | *addhistory = \&add_history; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 9 | *StifleHistory = \&stifle_history; | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | =head3 stifle_history | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | $term->stifle_history($max) | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | Stifle or put a cap on the history list, remembering only C<$max> | ||||||||||||||||||||||||||||||||||||||||||
| 332 | number of lines. | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | I<StifleHistory> is an alias for this function. | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 337 | ### FIXME: stifle_history is still here because it updates $attribs. | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ## Pass a reference? | ||||||||||||||||||||||||||||||||||||||||||
| 339 | sub stifle_history($$) { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | ▶ | my ($self, $max) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stifle_history: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | ▶ | $max = 0 if !defined($max) || $max < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $max or $max < 0
MC/DC50%1/2
not defined $max or $max < 0
not defined $max
$max < 0
Truth table66%2/3
not(A) or B
A= not defined $maxB= $max < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | ▶ | if (scalar @rl_History > $max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | splice @rl_History, $max; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | $attribs{history_length} = scalar @rl_History; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | $Term::ReadLine::Perl5::History::history_stifled = 1; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | $attribs{max_input_history} = $self->{rl_max_input_history} = $max; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | =head3 Features | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | B<Features()> | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | Returns a reference to a hash with keys being features present in | ||||||||||||||||||||||||||||||||||||||||||
| 357 | current implementation. Several optional features are used in the | ||||||||||||||||||||||||||||||||||||||||||
| 358 | minimal interface: | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 363 | I<addHistory> is present if you can add lines to history list via | ||||||||||||||||||||||||||||||||||||||||||
| 364 | the I<addHistory()> method | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 367 | I<appname> is be present if a name, the first argument | ||||||||||||||||||||||||||||||||||||||||||
| 368 | to I<new()> was given | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 371 | I<autohistory> is present if lines are put into history automatically | ||||||||||||||||||||||||||||||||||||||||||
| 372 | subject to the line being longer than I<MinLine>. | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 375 | I<getHistory> is present if we get retrieve history via the I<getHistory()> | ||||||||||||||||||||||||||||||||||||||||||
| 376 | method | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 379 | I<minline> is present if the I<MinLine> method available. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 382 | I<preput> is present if the second argument to I<readline> method can | ||||||||||||||||||||||||||||||||||||||||||
| 383 | append text to the input to be read subsequently | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 386 | I<readHistory> is present you can read history | ||||||||||||||||||||||||||||||||||||||||||
| 387 | items previosly saved in a file. | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 390 | I<setHistory> is present if we can set history | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 393 | I<stifleHistory> is present you can put a limit of the nubmer of history | ||||||||||||||||||||||||||||||||||||||||||
| 394 | items to save via the I<writeHistory()> method | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 397 | I<tkRunning> is present if a Tk application may run while I<ReadLine> is | ||||||||||||||||||||||||||||||||||||||||||
| 398 | getting input. | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 401 | I<writeHistory> is present you can save history to a file via the | ||||||||||||||||||||||||||||||||||||||||||
| 402 | I<writeHistory()> method | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub Features { \%features; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Features: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | =head1 See also | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | L<Term::ReadLine::Perl5::OO> is the newer but unfinished fully OO version. | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | L<Term::ReadLine::Perl5> is the first try at the OO package that most | ||||||||||||||||||||||||||||||||||||||||||
| 421 | programmers will use. | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | L<Term::ReadLine::Perl5::readline-guide> is guide to the guts of the | ||||||||||||||||||||||||||||||||||||||||||
| 426 | non-OO portion of L<Term::ReadLine::Perl5> | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | L<Term::ReadLine::Perl5::History> describes the history | ||||||||||||||||||||||||||||||||||||||||||
| 431 | mechanism | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | L<Term::ReadLine> is a generic package which can be used to | ||||||||||||||||||||||||||||||||||||||||||
| 436 | select this among other compatible GNU Readline packages. | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||