[Bps-public-commit] r15020 - in Prophet/trunk: .

sartak at bestpractical.com sartak at bestpractical.com
Mon Aug 11 19:01:36 EDT 2008


Author: sartak
Date: Mon Aug 11 19:01:35 2008
New Revision: 15020

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/Makefile.PL
   Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm

Log:
 r69246 at onn:  sartak | 2008-08-11 19:01:28 -0400
 Use Term::ReadLine for prophet's shell so it's not torturous


Modified: Prophet/trunk/Makefile.PL
==============================================================================
--- Prophet/trunk/Makefile.PL	(original)
+++ Prophet/trunk/Makefile.PL	Mon Aug 11 19:01:35 2008
@@ -25,6 +25,10 @@
 requires('XML::Atom::SimpleFeed');
 
 features(
+    'Prophet shell' => [
+        -default => 1,
+        'Term::ReadLine',
+    ],
     'Web server' => [
         -default => 1,
         'HTTP::Server::Simple', # HTTP::Server::Simple::CGI
@@ -56,7 +60,6 @@
         'Net::Bonjour',
         'HTTP::Server::Simple::Bonjour',
     ],
-
 );
 
 all_from('lib/Prophet.pm');

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Shell.pm	Mon Aug 11 19:01:35 2008
@@ -4,9 +4,26 @@
 extends 'Prophet::CLI::Command';
 use Path::Class 'file';
 
+has name => (
+    is => 'ro',
+    isa => 'Str',
+    default => sub { file($0)->basename },
+);
+
+has term => (
+    is      => 'ro',
+    isa     => 'Term::ReadLine',
+    lazy    => 1,
+    handles => [qw/readline addhistory/],
+    default => sub {
+        require Term::ReadLine;
+        return Term::ReadLine->new("Prophet shell");
+    },
+);
+
 sub prompt {
-    my $binary = file($0)->basename;
-    return "$binary> ";
+    my $self = shift;
+    return $self->name . '> ';
 }
 
 sub run {
@@ -14,12 +31,10 @@
 
     local $| = 1;
 
-    while (1) {
-        print $self->prompt;
-        my $input = <>;
-        last if !defined($input);
+    while (defined(local $_ = $self->readline($self->prompt))) {
+        next if /^\s*$/;
 
-        local @ARGV = split ' ', $input;
+        local @ARGV = split ' ', $_;
         eval { $self->run_one_command };
         warn $@ if $@;
     }



More information about the Bps-public-commit mailing list