Perl: add vector, hash-map, metadata, atom support. TCO let*
[jackhill/mal.git] / perl / readline.pm
1 # To get readline line editing functionality, please install
2 # Term::ReadLine::Gnu (GPL) or Term::ReadLine::Perl (GPL, Artistic)
3 # from CPAN.
4
5 package readline;
6 use strict;
7 use warnings;
8 use Exporter 'import';
9 our @EXPORT_OK = qw( mal_readline );
10
11 use Term::ReadLine;
12
13 my $_rl = Term::ReadLine->new('Mal');
14 $_rl->ornaments(0);
15 #print "Using ReadLine implementation: " . $_rl->ReadLine() . "\n";
16 my $OUT = $_rl->OUT || \*STDOUT;
17 my $_history_loaded = 0;
18
19 sub mal_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 }
35 1;