new([%options])
returns the handle for subsequent calls to following functions. Argument is the name of the application.
Term::ReadLine::Perl5::OO - OO version of Term::ReadLine::Perl5
use Term::ReadLine::Perl5::OO; my $c = Term::ReadLine::Perl5::OO->new; while (defined(my $line = $c->readline('> '))) { if ($line =~ /\S/) { print eval $line; } }
An Object-Oriented GNU Readline line editing library like Term::ReadLine::Perl5.
This module
Nested keymap is not fully supported yet.
my $term = Term::ReadLine::Perl5::OO->new();
Create new Term::ReadLine::Perl5::OO instance.
Options are:
You can write completion callback function like this:
use Term::ReadLine::Perl5::OO; my $c = Term::ReadLine::Perl5::OO->new( completion_callback => sub { my ($line) = @_; if ($line eq 'h') { return ( 'hello', 'hello there' ); } elsif ($line eq 'm') { return ( '突然のmattn' ); } return; }, );
my $line = $term->read($prompt);
Read line with $prompt.
$prompt
Trailing newline is removed. Returns undef on EOF.
$term->history()
Get the current history data in ArrayRef[Str] .
ArrayRef[Str]
$term->write_history($filename)
Write history data to the file.
$term->read_history($filename)
Read history data from history file.
If you want to support multi byte characters, you need to set binmode to STDIN. You can add the following code before call Term::ReadLine::Perl5::OO
use Term::Encoding qw(term_encoding); my $encoding = term_encoding(); binmode *STDIN, ":encoding(${encoding})";
Term::ReadLine::Perl5::OO detects east Asian ambiguous character width from environment variable using Unicode::EastAsianWidth::Detect.
User need to set locale correctly. For more details, please read Unicode::EastAsianWidth::Detect.
Copyright (C) tokuhirom. Copyright (C) Rocky Bernstein.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Caroline, the Perl package from which this is dervied
https://github.com/antirez/linenoise/blob/master/linenoise.c, the C code from which Caroline is derived
tokuhirom <tokuhirom@gmail.com> mattn
Extended and rewritten to make more compatible with GNU ReadLine and Term::ReadLine::Perl5 by Rocky Bernstein
To install Term::ReadLine::Perl5, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::ReadLine::Perl5
CPAN shell
perl -MCPAN -e shell install Term::ReadLine::Perl5
For more information on module installation, please visit the detailed CPAN module installation guide.