From 31327aae83b4368be2a97fbe09c328d61cedef78 Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 16 May 2008 13:24:17 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- mode/iperlmini.py | 12 ++++++--- tools/iperl | 62 ++++++++++++++--------------------------------- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/mode/iperlmini.py b/mode/iperlmini.py index d63a00a..5796e38 100644 --- a/mode/iperlmini.py +++ b/mode/iperlmini.py @@ -108,11 +108,15 @@ class IperlMini(mode.Fundamental): if type_ == 'PROMPT': self.window.application.set_mini_buffer_prompt(value + ' ') break - elif type_ in ('ERROR', 'RESULT'): - output.append(value.replace('\\n', '\n').replace('\\\\', '\\')) - elif type_ == 'RAW': + if type_ in ('ERROR', 'RESULT'): + value = value.replace('\\n', '\n').replace('\\\\', '\\') + value.rstrip() + if value: output.append(value) - return '\n'.join(output) + '\n' + if output: + return '\n'.join(output) + '\n' + else: + return '' def __init__(self, w): mode.Fundamental.__init__(self, w) diff --git a/tools/iperl b/tools/iperl index 8a952db..0f8acb6 100755 --- a/tools/iperl +++ b/tools/iperl @@ -4,12 +4,13 @@ # # licensed under the GNU GPL version 2 -use Data::Dumper; -use File::Basename; -use Getopt::Long; -use Perl6::Slurp; -use Scalar::Util; -use Term::ReadLine; +# try not to pollute the namespace +use Data::Dumper qw(Dumper); +use File::Basename qw(); +use Getopt::Long qw(); +use Perl6::Slurp qw(slurp); +use Scalar::Util qw(); +use Term::ReadLine qw(); Getopt::Long::Configure('bundling'); @@ -19,7 +20,7 @@ $Data::Dumper::Indent = 1; sub usage { my($status) = @_; - my $prog = basename($0); + my $prog = File::Basename::basename($0); print < sub { usage(0); }, 'eval|e=s' => sub { push(@preload, ['eval', $_[1]]); }, 'pipe|p' => sub { $pipe = 'line' }, @@ -105,27 +106,9 @@ sub escape { return $s; } -sub _draw { - my ($s, $prefix, $suffix) = @_; - if($pipe) { - print "$prefix:" . escape($s) . "\n"; - } else { - print $s . ($suffix ? $suffix : ''); - } -} - sub draw_prompt { my($p) = @_; - _draw($p, "PROMPT", " "); -} -sub draw_result { - my ($result) = @_; - $result = 'undef' unless defined($result); - _draw($result, "RESULT", "\n"); -} -sub draw_error { - my ($err) = @_; - _draw($err, "ERROR"); + print $pipe ? "$prefix:" . escape($p) . "\n" : $p; } sub draw_completions { my (@items) = @_; @@ -135,13 +118,6 @@ sub draw_completions { print join("\n", @items) . "\n"; } } -sub draw_message { - my ($mesg) = @_; - _draw($mesg, "MESSAGE"); -} -sub draw_exit { - _draw("Bye.", "EXIT", "\n"); -} sub complete { my ($word) = @_; @@ -215,7 +191,7 @@ sub main { if($line =~ m/COMPLETE:(.*)$/) { draw_completions(complete($1)); } else { - draw_error("malformed pipe input line"); + print "malformed pipe input line\n"; } next; } @@ -226,10 +202,10 @@ sub main { last; } elsif($line eq 'help') { ($input, $prompt) = ("", ">>>"); - draw_message($HELP); + print $HELP; } elsif($line eq 'reload') { ($input, $prompt) = ("", ">>>"); - draw_message("reloading...\n"); + print "reloading...\n"; exec($0, @OLDARGV); } elsif($line eq 'sh') { ($input, $prompt) = ("", ">>>"); @@ -257,19 +233,17 @@ sub main { $prompt = "..>"; } else { $input .= $line; - my @results = eval($input); + my @results = map { $_ =~ s/\n$//; repr($_); } eval($input); if($@) { - draw_error($@); + print $@; } elsif(scalar(@results) < 2) { - @results = map { chomp($_); repr($_); } - draw_result($results[0]); + print $results[0] . "\n"; } else { - @results = map { chomp($_); repr($_); } - draw_result(join(", ", @results)); + print join(", ", @results) . "\n"; } ($input, $prompt) = ("", ">>>"); } } - draw_exit(); + print "Bye.\n"; } main();