Skip to content

Commit

Permalink
Proof of concept for debugging a script
Browse files Browse the repository at this point in the history
  • Loading branch information
azawawi committed Nov 4, 2014
1 parent bcfbb15 commit 9e517cb
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions test_proc_async.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,73 @@

use v6;

#my $pc = Proc::Async.new( $*EXECUTABLE, ['--'], :w );
#my $pc = Proc::Async.new( "reply", ['--'], :w );
#my $pc = Proc::Async.new( "python", :w );
my $pc = Proc::Async.new( "pry", :w );
my $pc = Proc::Async.new( "perl6-debug-m", ['test.pl'], :w );

my $so = $pc.stdout;
my $se = $pc.stderr;

my $stdout = "";
my $stderr = "";
$so.act: { say "Output:\n$_\n---"; $stdout ~= $_; };
$se.act: { say "Input:\n$_\n---"; $stderr ~= $_ };
$so.act: {
my $response = $_;
if $response ~~ /'+' \s+ (.+?) \s+ '(' (\d+) \s+ '-' \s+ (\d+) ')'/ {
my ($file, $from, $to) = ~$0, ~$1, ~$2;
say $file;

my $pm = $pc.start;
# Create color ranges from the ANSI color sequences in the output text
my @ranges = gather {
my $colors;
my $start;
my $len = 0;
for $response.comb(/ \x1B '[' [ (\d+) ';'? ]+ 'm' /, :match) -> $/ {

while True {
my $expr = prompt("!> ");
my $ppr = $pc.print( "$expr\n" );
# Take the marked text range if possible
take {
"from" => $start,
"to" => $/.from - $len,
"colors" => $colors,
} if defined $colors;

# Decode colors into a simple CSS class name
$colors = $/[0].list.Str;

# Since we're going to remove ANSI colors
# we need to shift positions to the left
$start = $/.from - $len;
$len += $/.chars;
}

#$pc.close-stdin;
# Take the **remaining** marked text range if possible
take {
"from" => $start,
"to" => $response.chars - $len,
"colors" => $colors,
} if defined $colors;

};

say $_ for @ranges;

}
say "Output:\n$_\n---"; $stdout ~= $_;
}
$se.act: {
say "Input:\n$_\n---"; $stderr ~= $_
}

my $pm = $pc.start;

while True {
my $command = prompt(">>> ");
say "You have entered $command";
my $ppr = $pc.print($command ~ "\n");
await $ppr;
}

say "Finished waiting";

# done processing

$pc.close-stdin;
my $ps = await $pm;

Expand Down

0 comments on commit 9e517cb

Please sign in to comment.