branch : pmacs2
This commit is contained in:
moculus 2008-05-16 13:24:17 +00:00
parent 45da9ec01e
commit 31327aae83
2 changed files with 26 additions and 48 deletions

View File

@ -108,11 +108,15 @@ class IperlMini(mode.Fundamental):
if type_ == 'PROMPT': if type_ == 'PROMPT':
self.window.application.set_mini_buffer_prompt(value + ' ') self.window.application.set_mini_buffer_prompt(value + ' ')
break break
elif type_ in ('ERROR', 'RESULT'): if type_ in ('ERROR', 'RESULT'):
output.append(value.replace('\\n', '\n').replace('\\\\', '\\')) value = value.replace('\\n', '\n').replace('\\\\', '\\')
elif type_ == 'RAW': value.rstrip()
if value:
output.append(value) output.append(value)
return '\n'.join(output) + '\n' if output:
return '\n'.join(output) + '\n'
else:
return ''
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)

View File

@ -4,12 +4,13 @@
# #
# licensed under the GNU GPL version 2 # licensed under the GNU GPL version 2
use Data::Dumper; # try not to pollute the namespace
use File::Basename; use Data::Dumper qw(Dumper);
use Getopt::Long; use File::Basename qw();
use Perl6::Slurp; use Getopt::Long qw();
use Scalar::Util; use Perl6::Slurp qw(slurp);
use Term::ReadLine; use Scalar::Util qw();
use Term::ReadLine qw();
Getopt::Long::Configure('bundling'); Getopt::Long::Configure('bundling');
@ -19,7 +20,7 @@ $Data::Dumper::Indent = 1;
sub usage { sub usage {
my($status) = @_; my($status) = @_;
my $prog = basename($0); my $prog = File::Basename::basename($0);
print <<EOT; print <<EOT;
usage: $prog [options] usage: $prog [options]
-h,--help show this message -h,--help show this message
@ -38,7 +39,7 @@ my @OLDARGV = @ARGV;
my $verbose = 'yes'; my $verbose = 'yes';
my $pipe; my $pipe;
my @preload; my @preload;
GetOptions( Getopt::Long::GetOptions(
'help|h' => sub { usage(0); }, 'help|h' => sub { usage(0); },
'eval|e=s' => sub { push(@preload, ['eval', $_[1]]); }, 'eval|e=s' => sub { push(@preload, ['eval', $_[1]]); },
'pipe|p' => sub { $pipe = 'line' }, 'pipe|p' => sub { $pipe = 'line' },
@ -105,27 +106,9 @@ sub escape {
return $s; return $s;
} }
sub _draw {
my ($s, $prefix, $suffix) = @_;
if($pipe) {
print "$prefix:" . escape($s) . "\n";
} else {
print $s . ($suffix ? $suffix : '');
}
}
sub draw_prompt { sub draw_prompt {
my($p) = @_; my($p) = @_;
_draw($p, "PROMPT", " "); print $pipe ? "$prefix:" . escape($p) . "\n" : $p;
}
sub draw_result {
my ($result) = @_;
$result = 'undef' unless defined($result);
_draw($result, "RESULT", "\n");
}
sub draw_error {
my ($err) = @_;
_draw($err, "ERROR");
} }
sub draw_completions { sub draw_completions {
my (@items) = @_; my (@items) = @_;
@ -135,13 +118,6 @@ sub draw_completions {
print join("\n", @items) . "\n"; print join("\n", @items) . "\n";
} }
} }
sub draw_message {
my ($mesg) = @_;
_draw($mesg, "MESSAGE");
}
sub draw_exit {
_draw("Bye.", "EXIT", "\n");
}
sub complete { sub complete {
my ($word) = @_; my ($word) = @_;
@ -215,7 +191,7 @@ sub main {
if($line =~ m/COMPLETE:(.*)$/) { if($line =~ m/COMPLETE:(.*)$/) {
draw_completions(complete($1)); draw_completions(complete($1));
} else { } else {
draw_error("malformed pipe input line"); print "malformed pipe input line\n";
} }
next; next;
} }
@ -226,10 +202,10 @@ sub main {
last; last;
} elsif($line eq 'help') { } elsif($line eq 'help') {
($input, $prompt) = ("", ">>>"); ($input, $prompt) = ("", ">>>");
draw_message($HELP); print $HELP;
} elsif($line eq 'reload') { } elsif($line eq 'reload') {
($input, $prompt) = ("", ">>>"); ($input, $prompt) = ("", ">>>");
draw_message("reloading...\n"); print "reloading...\n";
exec($0, @OLDARGV); exec($0, @OLDARGV);
} elsif($line eq 'sh') { } elsif($line eq 'sh') {
($input, $prompt) = ("", ">>>"); ($input, $prompt) = ("", ">>>");
@ -257,19 +233,17 @@ sub main {
$prompt = "..>"; $prompt = "..>";
} else { } else {
$input .= $line; $input .= $line;
my @results = eval($input); my @results = map { $_ =~ s/\n$//; repr($_); } eval($input);
if($@) { if($@) {
draw_error($@); print $@;
} elsif(scalar(@results) < 2) { } elsif(scalar(@results) < 2) {
@results = map { chomp($_); repr($_); } print $results[0] . "\n";
draw_result($results[0]);
} else { } else {
@results = map { chomp($_); repr($_); } print join(", ", @results) . "\n";
draw_result(join(", ", @results));
} }
($input, $prompt) = ("", ">>>"); ($input, $prompt) = ("", ">>>");
} }
} }
draw_exit(); print "Bye.\n";
} }
main(); main();