mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Fix interactive-editing chained commands
This commit is contained in:
parent
43f08b4cbc
commit
7638bb031b
@ -155,7 +155,7 @@ sub show_output {
|
||||
my $self = shift;
|
||||
my $output = $self->{output};
|
||||
|
||||
unless($self->{got_run} and $self->{copy_code}) {
|
||||
unless ($self->{got_run} and $self->{copy_code}) {
|
||||
open FILE, ">> log.txt";
|
||||
print FILE "------------------------------------------------------------------------\n";
|
||||
print FILE localtime() . "\n";
|
||||
@ -164,7 +164,7 @@ sub show_output {
|
||||
close FILE;
|
||||
}
|
||||
|
||||
if(exists $self->{options}->{'-paste'} or (defined $self->{got_run} and $self->{got_run} eq "paste")) {
|
||||
if (exists $self->{options}->{'-paste'} or (defined $self->{got_run} and $self->{got_run} eq 'paste')) {
|
||||
my $cmdline = $self->{cmdline};
|
||||
|
||||
$cmdline =~ s/\$sourcefile/$self->{sourcefile}/g;
|
||||
@ -444,7 +444,7 @@ sub process_cmdline_options {
|
||||
sub process_interactive_edit {
|
||||
my $self = shift;
|
||||
my $code = $self->{code};
|
||||
my (@last_code, $save_last_code, $unshift_last_code);
|
||||
my (@last_code, $unshift_last_code);
|
||||
|
||||
print " code: [$code]\n" if $self->{debug};
|
||||
|
||||
@ -474,7 +474,6 @@ sub process_interactive_edit {
|
||||
$code = $copy_code;
|
||||
$self->{only_show} = 1;
|
||||
$self->{copy_code} = 1;
|
||||
$save_last_code = 1;
|
||||
}
|
||||
|
||||
if($subcode =~ m/^\s*(?:and\s+)?(?:diff|show)\s+(\S+)\s*$/) {
|
||||
@ -500,39 +499,13 @@ sub process_interactive_edit {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if($subcode =~ m/^\s*(?:and\s+)?diff(?:\s+\S+)?\s*$/i) {
|
||||
if($#last_code < 1) {
|
||||
print "$self->{nick}: Not enough recent code to diff.\n"
|
||||
} else {
|
||||
use Text::WordDiff;
|
||||
my $diff = word_diff(\$last_code[1], \$last_code[0], { STYLE => 'Diff' });
|
||||
if($diff !~ /(?:<del>|<ins>)/) {
|
||||
$diff = "No difference.";
|
||||
} else {
|
||||
$diff =~ s/<del>(.*?)(\s+)<\/del>/<del>$1<\/del>$2/g;
|
||||
$diff =~ s/<ins>(.*?)(\s+)<\/ins>/<ins>$1<\/ins>$2/g;
|
||||
$diff =~ s/<del>((?:(?!<del>).)*)<\/del>\s*<ins>((?:(?!<ins>).)*)<\/ins>/`replaced $1 with $2`/g;
|
||||
$diff =~ s/<del>(.*?)<\/del>/`removed $1`/g;
|
||||
$diff =~ s/<ins>(.*?)<\/ins>/`inserted $1`/g;
|
||||
}
|
||||
|
||||
print "$self->{nick}: $diff\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if($subcode =~ m/^\s*(?:and\s+)?(run|paste)\s*$/i) {
|
||||
$self->{got_run} = lc $1;
|
||||
if(defined $last_code[0]) {
|
||||
$code = $last_code[0];
|
||||
$self->{only_show} = 0;
|
||||
} else {
|
||||
print "$self->{nick}: No recent code to $self->{got_run}.\n";
|
||||
exit 0;
|
||||
}
|
||||
} else {
|
||||
my $got_undo = 0;
|
||||
my $prevchange = $last_code[0];
|
||||
my @replacements;
|
||||
my $got_changes = 0;
|
||||
my $got_sub = 0;
|
||||
my $got_diff = 0;
|
||||
my $got_undo = 0;
|
||||
my $last_keyword;
|
||||
|
||||
while($subcode =~ s/^\s*(and)?\s*undo//) {
|
||||
splice @last_code, 0, 1;
|
||||
@ -545,17 +518,27 @@ sub process_interactive_edit {
|
||||
}
|
||||
}
|
||||
|
||||
my @replacements;
|
||||
my $prevchange = $last_code[0];
|
||||
my $got_changes = 0;
|
||||
my $last_keyword;
|
||||
|
||||
while(1) {
|
||||
$got_sub = 0;
|
||||
#$got_changes = 0;
|
||||
|
||||
$subcode =~ s/^\s*and\s+'/and $last_keyword '/ if defined $last_keyword;
|
||||
|
||||
if($subcode =~ m/^\s*(?:and\s+)?diff\b/i) {
|
||||
$got_diff = 1;
|
||||
last;
|
||||
}
|
||||
|
||||
if($subcode =~ m/^\s*(?:and\s+)?(run|paste)\b/i) {
|
||||
$self->{got_run} = lc $1;
|
||||
$self->{only_show} = 0;
|
||||
if ($prevchange) {
|
||||
$code = $prevchange;
|
||||
} else {
|
||||
print "$self->{nick}: No recent code to $self->{got_run}.\n";
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
|
||||
if($subcode =~ m/^\s*(and)?\s*remove \s*([^']+)?\s*'/) {
|
||||
$last_keyword = 'remove';
|
||||
my $modifier = 'first';
|
||||
@ -801,24 +784,24 @@ sub process_interactive_edit {
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if($ret) {
|
||||
if ($ret) {
|
||||
$got_changes = 1;
|
||||
}
|
||||
|
||||
$prevchange = $code;
|
||||
}
|
||||
|
||||
if($got_sub and not $got_changes) {
|
||||
if ($got_sub and not $got_changes) {
|
||||
print "$self->{nick}: No substitutions made.\n";
|
||||
exit 0;
|
||||
} elsif($got_sub and $got_changes) {
|
||||
} elsif ($got_sub and $got_changes) {
|
||||
next;
|
||||
}
|
||||
|
||||
last;
|
||||
}
|
||||
|
||||
if($#replacements > -1) {
|
||||
if (@replacements) {
|
||||
use re::engine::RE2 -strict => 1;
|
||||
@replacements = sort { $a->{'from'} cmp $b->{'from'} or $a->{'modifier'} <=> $b->{'modifier'} } @replacements;
|
||||
|
||||
@ -903,22 +886,19 @@ sub process_interactive_edit {
|
||||
}
|
||||
}
|
||||
|
||||
$save_last_code = 1;
|
||||
|
||||
unless($got_undo and not $got_changes) {
|
||||
$unshift_last_code = 1 unless $copy_code and not $got_changes;
|
||||
}
|
||||
|
||||
if($copy_code and $got_changes) {
|
||||
if ($copy_code and $got_changes) {
|
||||
$self->{only_show} = 0;
|
||||
}
|
||||
|
||||
if($got_undo and not $got_changes) {
|
||||
if ($got_undo and not $got_changes) {
|
||||
$self->{only_show} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if($save_last_code) {
|
||||
unless (($self->{got_run} or $got_diff) and not $got_changes) {
|
||||
if($unshift_last_code) {
|
||||
unshift @last_code, $code;
|
||||
}
|
||||
@ -934,6 +914,28 @@ sub process_interactive_edit {
|
||||
close FILE;
|
||||
}
|
||||
|
||||
if ($got_diff) {
|
||||
if($#last_code < 1) {
|
||||
print "$self->{nick}: Not enough recent code to diff.\n"
|
||||
} else {
|
||||
use Text::WordDiff;
|
||||
my $diff = word_diff(\$last_code[1], \$last_code[0], { STYLE => 'Diff' });
|
||||
|
||||
if($diff !~ /(?:<del>|<ins>)/) {
|
||||
$diff = "No difference.";
|
||||
} else {
|
||||
$diff =~ s/<del>(.*?)(\s+)<\/del>/<del>$1<\/del>$2/g;
|
||||
$diff =~ s/<ins>(.*?)(\s+)<\/ins>/<ins>$1<\/ins>$2/g;
|
||||
$diff =~ s/<del>((?:(?!<del>).)*)<\/del>\s*<ins>((?:(?!<ins>).)*)<\/ins>/`replaced $1 with $2`/g;
|
||||
$diff =~ s/<del>(.*?)<\/del>/`removed $1`/g;
|
||||
$diff =~ s/<ins>(.*?)<\/ins>/`inserted $1`/g;
|
||||
}
|
||||
|
||||
print "$self->{nick}: $diff\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
$self->{code} = $code;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user