Skip to content

Commit a39d509

Browse files
committed
[GR-18339] Fix a few repl usability issues
PullRequest: graalpython/659
2 parents b7f54b2 + e4e21bc commit a39d509

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,17 @@ public int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
642642
continuePrompt = doEcho ? sys.getMember("ps2").asString() : null;
643643
}
644644
if (e.isIncompleteSource()) {
645-
// read another line of input
645+
// read more input until we get an empty line
646646
consoleHandler.setPrompt(continuePrompt);
647647
String additionalInput = consoleHandler.readLine();
648+
while (additionalInput != null && !additionalInput.isEmpty()) {
649+
sb.append(additionalInput).append('\n');
650+
consoleHandler.setPrompt(continuePrompt);
651+
additionalInput = consoleHandler.readLine();
652+
}
648653
if (additionalInput == null) {
649654
throw new EOFException();
650655
}
651-
sb.append(additionalInput).append('\n');
652656
// The only continuation in the while loop
653657
continue;
654658
} else if (e.isExit()) {
@@ -666,16 +670,18 @@ public int readEvalPrint(Context context, ConsoleHandler consoleHandler) {
666670
break;
667671
}
668672
} catch (EOFException e) {
669-
try {
670-
evalInternal(context, "import site; exit()\n");
671-
} catch (PolyglotException e2) {
672-
if (e2.isExit()) {
673-
// don't use the exit code from the PolyglotException
674-
return lastStatus;
675-
} else if (e2.isCancelled()) {
676-
continue;
673+
if (!noSite) {
674+
try {
675+
evalInternal(context, "import site; exit()\n");
676+
} catch (PolyglotException e2) {
677+
if (e2.isExit()) {
678+
// don't use the exit code from the PolyglotException
679+
return lastStatus;
680+
} else if (e2.isCancelled()) {
681+
continue;
682+
}
683+
throw new RuntimeException("error while calling exit", e);
677684
}
678-
throw new RuntimeException("error while calling exit", e);
679685
}
680686
System.out.println();
681687
return lastStatus;

0 commit comments

Comments
 (0)