Skip to content

Commit

Permalink
Repl demo: intercept Control-C
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Apr 12, 2020
1 parent d283a03 commit bf35624
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,8 @@ public Object execute(String line) throws Exception {
consoleEngine().println(er.result());
out = null;
boolean success = er.status() == 0 ? true : false;
if ( (cmd.pipe().equals(pipeName.get(Pipe.OR)) && success)
|| (cmd.pipe().equals(pipeName.get(Pipe.AND)) && !success)) {
if ((cmd.pipe().equals(pipeName.get(Pipe.OR)) && success)
|| (cmd.pipe().equals(pipeName.get(Pipe.AND)) && !success)) {
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions demo/src/main/java/org/jline/demo/Repl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.jline.script.GroovyEngine;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.terminal.Terminal.Signal;
import org.jline.terminal.Terminal.SignalHandler;
import org.jline.utils.InfoCmp;
import org.jline.utils.InfoCmp.Capability;
import org.jline.utils.OSUtils;
Expand Down Expand Up @@ -449,6 +451,8 @@ public static void main(String[] args) {
parser.setEscapeChars(null);
parser.setRegexCommand("[:]{0,1}[a-zA-Z!]{1,}\\S*"); // change default regex to support shell commands
Terminal terminal = TerminalBuilder.builder().build();
Thread executeThread = Thread.currentThread();
terminal.handle(Signal.INT, signal -> executeThread.interrupt());
//
// ScriptEngine and command registeries
//
Expand Down

0 comments on commit bf35624

Please sign in to comment.