Skip to content

Commit ae4736f

Browse files
committed
[GR-26181] Upgrade to JLine 3.13.2.
PullRequest: graalpython/1303
2 parents 5d0380f + f4f1f5a commit ae4736f

File tree

6 files changed

+362
-194
lines changed

6 files changed

+362
-194
lines changed

THIRD_PARTY_LICENSE.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,3 +3160,43 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31603160
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31613161
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31623162
SOFTWARE.
3163+
3164+
================================================================================
3165+
3166+
JLine 3.13
3167+
3168+
Copyright (c) 2002-2016, the original author or authors.
3169+
Copyright (c) 2002-2018, the original author or authors.
3170+
All rights reserved.
3171+
3172+
https://opensource.org/licenses/BSD-3-Clause
3173+
3174+
Redistribution and use in source and binary forms, with or
3175+
without modification, are permitted provided that the following
3176+
conditions are met:
3177+
3178+
Redistributions of source code must retain the above copyright
3179+
notice, this list of conditions and the following disclaimer.
3180+
3181+
Redistributions in binary form must reproduce the above copyright
3182+
notice, this list of conditions and the following disclaimer
3183+
in the documentation and/or other materials provided with
3184+
the distribution.
3185+
3186+
Neither the name of JLine nor the names of its contributors
3187+
may be used to endorse or promote products derived from this
3188+
software without specific prior written permission.
3189+
3190+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3191+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
3192+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
3193+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
3194+
EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
3195+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
3196+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3197+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3198+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
3199+
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3200+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3201+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3202+
OF THE POSSIBILITY OF SUCH DAMAGE.

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,13 @@ public final String readLine() {
7171

7272
public abstract void setPrompt(String prompt);
7373

74-
public void addCompleter(@SuppressWarnings("unused") Function<String, List<String>> completer) {
75-
// ignore by default
76-
}
77-
7874
public void setContext(@SuppressWarnings("unused") Context context) {
7975
// ignore by default
8076
}
8177

8278
@SuppressWarnings("unused")
83-
public void setHistory(BooleanSupplier shouldRecord, IntSupplier getSize, Consumer<String> addItem, IntFunction<String> getItem, BiConsumer<Integer, String> setItem, IntConsumer removeItem,
84-
Runnable clear) {
79+
public void setupReader(BooleanSupplier shouldRecord, IntSupplier getSize, Consumer<String> addItem, IntFunction<String> getItem, BiConsumer<Integer, String> setItem, IntConsumer removeItem,
80+
Runnable clear, Function<String, List<String>> completer) {
8581
// ignore by default
8682
}
8783

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -44,26 +44,18 @@
4444
import java.io.IOException;
4545
import java.io.InputStream;
4646
import java.io.InputStreamReader;
47-
import java.io.OutputStream;
48-
import java.io.PrintStream;
4947

5048
public class DefaultConsoleHandler extends ConsoleHandler {
5149

5250
private final BufferedReader in;
53-
private final PrintStream out;
54-
private String prompt;
5551

56-
public DefaultConsoleHandler(InputStream in, OutputStream out) {
52+
public DefaultConsoleHandler(InputStream in) {
5753
this.in = new BufferedReader(new InputStreamReader(in));
58-
this.out = new PrintStream(out);
5954
}
6055

6156
@Override
6257
public String readLine(boolean showPrompt) {
6358
try {
64-
if (prompt != null && showPrompt) {
65-
out.print(prompt);
66-
}
6759
return in.readLine();
6860
} catch (IOException e) {
6961
throw new RuntimeException(e);
@@ -72,6 +64,5 @@ public String readLine(boolean showPrompt) {
7264

7365
@Override
7466
public void setPrompt(String prompt) {
75-
this.prompt = prompt;
7667
}
7768
}

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
import org.graalvm.polyglot.Value;
5858

5959
import com.oracle.truffle.llvm.toolchain.launchers.common.Driver;
60-
61-
import jline.console.UserInterruptException;
60+
import java.util.function.Function;
61+
import org.graalvm.shadowed.org.jline.reader.UserInterruptException;
6262

6363
public class GraalPythonMain extends AbstractLanguageLauncher {
6464
public static void main(String[] args) {
@@ -81,7 +81,7 @@ public static void main(String[] args) {
8181
private boolean quietFlag = false;
8282
private boolean noUserSite = false;
8383
private boolean noSite = false;
84-
private boolean stdinIsInteractive = System.console() != null;
84+
private final boolean stdinIsInteractive = System.console() != null;
8585
private boolean unbufferedIO = false;
8686
private boolean multiContext = false;
8787
private VersionAction versionAction = VersionAction.None;
@@ -458,7 +458,8 @@ protected void launch(Builder contextBuilder) {
458458
contextBuilder.option("python.UnbufferedIO", Boolean.toString(unbufferedIO));
459459

460460
ConsoleHandler consoleHandler = createConsoleHandler(System.in, System.out);
461-
contextBuilder.arguments(getLanguageId(), programArgs.toArray(new String[0])).in(consoleHandler.createInputStream());
461+
contextBuilder.arguments(getLanguageId(), programArgs.toArray(new String[programArgs.size()]));
462+
contextBuilder.in(consoleHandler.createInputStream());
462463
contextBuilder.option("python.TerminalIsInteractive", Boolean.toString(stdinIsInteractive));
463464
contextBuilder.option("python.TerminalWidth", Integer.toString(consoleHandler.getTerminalWidth()));
464465
contextBuilder.option("python.TerminalHeight", Integer.toString(consoleHandler.getTerminalHeight()));
@@ -684,11 +685,12 @@ protected void collectArguments(Set<String> options) {
684685
options.add("--show-version");
685686
}
686687

687-
public ConsoleHandler createConsoleHandler(InputStream inStream, OutputStream outStream) {
688-
if (inputFile != null || commandString != null) {
689-
return new DefaultConsoleHandler(inStream, outStream);
688+
private ConsoleHandler createConsoleHandler(InputStream inStream, OutputStream outStream) {
689+
if (!stdinIsInteractive) {
690+
return new DefaultConsoleHandler(inStream);
691+
} else {
692+
return new JLineConsoleHandler(inStream, outStream, false);
690693
}
691-
return new JLineConsoleHandler(inStream, outStream, false);
692694
}
693695

694696
/**
@@ -799,34 +801,37 @@ private void setupREPL(Context context, ConsoleHandler consoleHandler) {
799801
// history feature
800802
evalInternal(context, "import sys\ngetattr(sys, '__interactivehook__', lambda: None)()\n");
801803
final Value readline = evalInternal(context, "import readline; readline");
802-
final Value completer = readline.getMember("get_completer").execute();
804+
final Value getCompleter = readline.getMember("get_completer").execute();
803805
final Value shouldRecord = readline.getMember("get_auto_history");
804806
final Value addHistory = readline.getMember("add_history");
805807
final Value getHistoryItem = readline.getMember("get_history_item");
806808
final Value setHistoryItem = readline.getMember("replace_history_item");
807809
final Value deleteHistoryItem = readline.getMember("remove_history_item");
808810
final Value clearHistory = readline.getMember("clear_history");
809811
final Value getHistorySize = readline.getMember("get_current_history_length");
810-
consoleHandler.setHistory(
811-
() -> shouldRecord.execute().asBoolean(),
812-
() -> getHistorySize.execute().asInt(),
813-
(item) -> addHistory.execute(item),
814-
(pos) -> getHistoryItem.execute(pos).asString(),
815-
(pos, item) -> setHistoryItem.execute(pos, item),
816-
(pos) -> deleteHistoryItem.execute(pos),
817-
() -> clearHistory.execute());
818812

819-
if (completer.canExecute()) {
820-
consoleHandler.addCompleter((buffer) -> {
813+
Function<String, List<String>> completer = null;
814+
if (getCompleter.canExecute()) {
815+
completer = (buffer) -> {
821816
List<String> candidates = new ArrayList<>();
822-
Value candidate = completer.execute(buffer, candidates.size());
817+
Value candidate = getCompleter.execute(buffer, candidates.size());
823818
while (candidate.isString()) {
824819
candidates.add(candidate.asString());
825-
candidate = completer.execute(buffer, candidates.size());
820+
candidate = getCompleter.execute(buffer, candidates.size());
826821
}
827822
return candidates;
828-
});
823+
};
829824
}
825+
consoleHandler.setupReader(
826+
() -> shouldRecord.execute().asBoolean(),
827+
() -> getHistorySize.execute().asInt(),
828+
(item) -> addHistory.execute(item),
829+
(pos) -> getHistoryItem.execute(pos).asString(),
830+
(pos, item) -> setHistoryItem.execute(pos, item),
831+
(pos) -> deleteHistoryItem.execute(pos),
832+
() -> clearHistory.execute(),
833+
completer);
834+
830835
}
831836

832837
/**

0 commit comments

Comments
 (0)