summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-06-08 12:03:31 -0500
committerJesse Luehrs <doy@tozt.net>2013-06-08 12:06:41 -0500
commitf4775be782ef0cd1003190169b539b3ba2367292 (patch)
treefc70528bd046cd197fe6e4dbf96b476255deb663
parentca4d93af889b6086deabcdf1825181f46e17957a (diff)
downloadreply-f4775be782ef0cd1003190169b539b3ba2367292.tar.gz
reply-f4775be782ef0cd1003190169b539b3ba2367292.zip
allow running single commands through the repl
-rw-r--r--lib/Reply.pm43
-rw-r--r--lib/Reply/Plugin/FancyPrompt.pm2
-rw-r--r--lib/Reply/Plugin/Nopaste.pm3
3 files changed, 37 insertions, 11 deletions
diff --git a/lib/Reply.pm b/lib/Reply.pm
index 22f14d5..dbb9b24 100644
--- a/lib/Reply.pm
+++ b/lib/Reply.pm
@@ -107,19 +107,33 @@ undef.
sub run {
my $self = shift;
- while (defined(my $line = $self->_read)) {
- try {
- my @result = $self->_eval($line);
- $self->_print_result(@result);
- }
- catch {
- $self->_print_error($_);
- };
- $self->_loop;
- }
+ while ($self->run_one) { }
print "\n";
}
+sub run_one {
+ my $self = shift;
+ my ($line) = @_;
+
+ if (defined $line) {
+ $line = $self->_premangle_line($line);
+ }
+ else {
+ $line = $self->_read;
+ }
+
+ return unless defined $line;
+
+ try {
+ my @result = $self->_eval($line);
+ $self->_print_result(@result);
+ }
+ catch {
+ $self->_print_error($_);
+ };
+ $self->_loop;
+}
+
sub _load_config {
my $self = shift;
my ($file) = @_;
@@ -182,6 +196,13 @@ sub _read {
my ($line) = $self->_wrapped_plugin('read_line', $prompt);
return if !defined $line;
+ return $self->_premangle_line($line);
+}
+
+sub _premangle_line {
+ my $self = shift;
+ my ($line) = @_;
+
if ($line =~ s/^#(\w+)(?:\s+|$)//) {
($line) = $self->_chained_plugin("command_\L$1", $line);
}
@@ -219,7 +240,7 @@ sub _print_result {
sub _loop {
my $self = shift;
- $self->_chained_plugin('loop');
+ $self->_chained_plugin('loop', 1);
}
sub _wrapped_plugin {
diff --git a/lib/Reply/Plugin/FancyPrompt.pm b/lib/Reply/Plugin/FancyPrompt.pm
index d0afc38..1f36d45 100644
--- a/lib/Reply/Plugin/FancyPrompt.pm
+++ b/lib/Reply/Plugin/FancyPrompt.pm
@@ -33,7 +33,9 @@ sub prompt {
sub loop {
my $self = shift;
+ my ($continue) = @_;
$self->{counter}++;
+ $continue;
}
1;
diff --git a/lib/Reply/Plugin/Nopaste.pm b/lib/Reply/Plugin/Nopaste.pm
index dec0940..566c668 100644
--- a/lib/Reply/Plugin/Nopaste.pm
+++ b/lib/Reply/Plugin/Nopaste.pm
@@ -70,12 +70,15 @@ sub print_result {
sub loop {
my $self = shift;
+ my ($continue) = @_;
my $prompt = delete $self->{prompt};
my $line = delete $self->{line};
my $result = delete $self->{result};
$self->{history} .= "$prompt$line$result";
+
+ $continue;
}
sub command_nopaste {