parent
45da9ec01e
commit
31327aae83
|
@ -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)
|
||||
if output:
|
||||
return '\n'.join(output) + '\n'
|
||||
else:
|
||||
return ''
|
||||
|
||||
def __init__(self, w):
|
||||
mode.Fundamental.__init__(self, w)
|
||||
|
|
62
tools/iperl
62
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 <<EOT;
|
||||
usage: $prog [options]
|
||||
-h,--help show this message
|
||||
|
@ -38,7 +39,7 @@ my @OLDARGV = @ARGV;
|
|||
my $verbose = 'yes';
|
||||
my $pipe;
|
||||
my @preload;
|
||||
GetOptions(
|
||||
Getopt::Long::GetOptions(
|
||||
'help|h' => 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();
|
||||
|
|
Loading…
Reference in New Issue