Created
August 12, 2016 13:14
-
-
Save lizmat/ca54ab85f554307d2fa3b0ec12687d56 to your computer and use it in GitHub Desktop.
ctrl-cing in the REPL WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/REPL.pm b/src/core/REPL.pm | |
index 2583703..d243606 100644 | |
--- a/src/core/REPL.pm | |
+++ b/src/core/REPL.pm | |
@@ -294,6 +294,7 @@ do { | |
} | |
} | |
+say "compiling {code}"; | |
self.compiler.eval(code, |%(adverbs)) | |
} | |
@@ -318,6 +319,19 @@ do { | |
my $prompt = self.interactive_prompt; | |
my $code = ""; | |
+ my $ctrl-c = Promise.new; | |
+ my $running = False; | |
+ signal(SIGINT).tap: { | |
+ if $running { | |
+ $running = False; | |
+ $ctrl-c.keep("\nAborted") | |
+ } | |
+ else { | |
+ say "\nGoodbye!"; | |
+ exit 0; | |
+ } | |
+ } | |
+ | |
REPL: loop { | |
my $newcode = self.repl-read(~$prompt); | |
@@ -337,11 +351,24 @@ do { | |
my $*CTXSAVE := self; | |
my $*MAIN_CTX; | |
- | |
- my $output := self.repl-eval( | |
- $code, | |
- :outer_ctx($!save_ctx), | |
- |%adverbs); | |
+ my $output; | |
+ | |
+ await Promise.anyof( | |
+ start { | |
+ ENTER $running = True; | |
+ LEAVE $running = False; | |
+ $output := | |
+ self.repl-eval($code,:outer_ctx($!save_ctx),|%adverbs); | |
+ }, | |
+ $ctrl-c | |
+ ); | |
+ | |
+ if $ctrl-c.status == Kept { | |
+ # somehow kill the running thread | |
+ say $ctrl-c.result; | |
+ $ctrl-c = Promise.new; | |
+ next; | |
+ } | |
if self.input-incomplete($output) { | |
$prompt = '* '; | |
@@ -361,6 +388,7 @@ do { | |
} | |
CATCH { | |
+ $running = False; | |
say $_; | |
$code = ''; | |
$prompt = self.interactive_prompt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment