aboutsummaryrefslogtreecommitdiff
path: root/perl/readline.pm
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /perl/readline.pm
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'perl/readline.pm')
-rw-r--r--perl/readline.pm31
1 files changed, 24 insertions, 7 deletions
diff --git a/perl/readline.pm b/perl/readline.pm
index f0710b1..0629f39 100644
--- a/perl/readline.pm
+++ b/perl/readline.pm
@@ -1,12 +1,12 @@
# To get readline line editing functionality, please install
-# Term::ReadLine::Gnu (GPL) or Term::ReadLine::Perl (GPL, Artistic)
-# from CPAN.
+# Term::ReadKey and either Term::ReadLine::Gnu (GPL) or
+# Term::ReadLine::Perl (GPL, Artistic) from CPAN.
package readline;
use strict;
use warnings;
use Exporter 'import';
-our @EXPORT_OK = qw( mal_readline );
+our @EXPORT_OK = qw( mal_readline set_rl_mode );
use Term::ReadLine;
@@ -36,6 +36,13 @@ sub load_history {
close $fh;
}
+my $rl_mode = "terminal";
+
+sub set_rl_mode {
+ my($mode) = @_;
+ $rl_mode = $mode;
+}
+
sub mal_readline {
my($prompt) = @_;
my $line = undef;
@@ -44,11 +51,21 @@ sub mal_readline {
load_history();
}
- if (defined ($line = $_rl->readline($prompt))) {
- save_line($line);
- return $line;
+ if ($rl_mode eq "terminal") {
+ if (defined ($line = $_rl->readline($prompt))) {
+ save_line($line);
+ return $line;
+ } else {
+ return undef;
+ }
} else {
- return undef;
+ print "$prompt";
+ if (defined ($line = readline(*STDIN))) {
+ save_line($line);
+ return $line;
+ } else {
+ return undef;
+ }
}
}
1;