Perl: add step9_interop test
[jackhill/mal.git] / perl / readline.pm
CommitLineData
9e5b2151
JM
1# To get readline line editing functionality, please install
2# Term::ReadLine::Gnu (GPL) or Term::ReadLine::Perl (GPL, Artistic)
3# from CPAN.
4
5package readline;
6use strict;
7use warnings;
8use Exporter 'import';
9our @EXPORT_OK = qw( readline );
10
11use Term::ReadLine;
12
13my $_rl = Term::ReadLine->new('Mal');
14$_rl->ornaments(0);
15#print "Using ReadLine implementation: " . $_rl->ReadLine() . "\n";
16my $OUT = $_rl->OUT || \*STDOUT;
17my $_history_loaded = 0;
18
19sub readline {
20 my($prompt) = @_;
21 my $line = undef;
22 if (! $_history_loaded) {
23 $_history_loaded = 1;
24 # TODO: load history
25 }
26
27 if (defined ($line = $_rl->readline($prompt))) {
28 $_rl->addhistory($line) if $line =~ /\S/;
29 # TODO: save history
30 return $line;
31 } else {
32 return undef;
33 }
34}
351;