Caroline
view release on metacpan or search on metacpan
lib/Caroline.pm view on Meta::CPAN
You can write completion callback function like this:
use Caroline;
my $c = Caroline->new(
completion_callback => sub {
my ($line) = @_;
if ($line eq 'h') {
return (
'hello',
'hello there'
);
} elsif ($line eq 'm') {
return (
'çªç¶ã®mattn'
);
}
return;
},
);
=back
=item C<< my $line = $caroline->read($prompt); >>
Read line with C<$prompt>.
Trailing newline is removed. Returns undef on EOF.
=item C<< $caroline->history_add($line) >>
Add $line to the history.
=item C<< $caroline->history() >>
Get the current history data in C< ArrayRef[Str] >.
=item C<< $caroline->write_history_file($filename) >>
Write history data to the file.
=item C<< $caroline->read_history_file($filename) >>
Read history data from history file.
=back
=head1 Multi byte character support
If you want to support multi byte characters, you need to set binmode to STDIN.
You can add the following code before call Caroline.
use Term::Encoding qw(term_encoding);
my $encoding = term_encoding();
binmode *STDIN, ":encoding(${encoding})";
=head1 About east Asian ambiguous width characters
Caroline detects east Asian ambiguous character width from environment variable using L<Unicode::EastAsianWidth::Detect>.
User need to set locale correctly. For more details, please read L<Unicode::EastAsianWidth::Detect>.
=head1 LICENSE
Copyright (C) tokuhirom.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<https://github.com/antirez/linenoise/blob/master/linenoise.c>
=head1 AUTHOR
tokuhirom E<lt>tokuhirom@gmail.comE<gt>
mattn
=cut
( run in 0.941 second using v1.01-cache-2.11-cpan-ceb78f64989 )