Skip to content

Commit c0f01fa

Browse files
committed
Simpler JLine integration
Move the JLine integration back into the "rhino-tools" module, but make it optional using "compileOnly". The module will use JLine if it's in the classpath and will fall back gracefully if it's not. Include JLine in the "rhino-all" module so that the "rhino-all" JAR contains JLine by default so that we have a nice initial user experience. This will give us command-line editing and history. Command completion and highlighting are a task for another day.
1 parent 8b50950 commit c0f01fa

File tree

16 files changed

+84
-114
lines changed

16 files changed

+84
-114
lines changed

rhino-all/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ dependencies {
1616
implementation project(':rhino')
1717
implementation project(':rhino-tools')
1818
implementation project(':rhino-xml')
19-
implementation project(':rhino-cli')
19+
runtimeOnly 'org.jline:jline-terminal:3.30.0'
20+
runtimeOnly 'org.jline:jline-reader:3.30.0'
21+
runtimeOnly 'org.jline:jline-terminal-ffm:3.30.0'
22+
runtimeOnly 'org.jline:jline-terminal-jni:3.30.0'
2023
}
2124

2225
shadowJar {

rhino-cli/build.gradle

Lines changed: 0 additions & 51 deletions
This file was deleted.

rhino-cli/src/main/java/module-info.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

rhino-cli/src/main/resources/META-INF/services/org.mozilla.javascript.tools.ConsoleProvider

Lines changed: 0 additions & 1 deletion
This file was deleted.

rhino-tools/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ plugins {
44

55
dependencies {
66
implementation project(':rhino')
7+
compileOnly 'org.jline:jline-terminal:3.30.0'
8+
compileOnly 'org.jline:jline-reader:3.30.0'
79
testImplementation project(':testutils')
810
}
911

rhino-tools/src/main/java/module-info.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module org.mozilla.rhino.tools {
22
requires transitive org.mozilla.rhino;
33
requires transitive java.desktop;
4+
requires static org.jline.terminal;
5+
requires static org.jline.reader;
46

57
exports org.mozilla.javascript.tools;
68
exports org.mozilla.javascript.tools.debugger;
@@ -10,5 +12,6 @@
1012
uses org.mozilla.javascript.tools.ConsoleProvider;
1113

1214
provides org.mozilla.javascript.tools.ConsoleProvider with
13-
org.mozilla.javascript.tools.shell.BasicConsoleProvider;
15+
org.mozilla.javascript.tools.shell.BasicConsoleProvider,
16+
org.mozilla.javascript.tools.shell.JLineConsoleProvider;
1417
}

rhino-tools/src/main/java/org/mozilla/javascript/tools/Console.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.mozilla.javascript.tools;
22

3+
import java.io.Closeable;
34
import java.io.IOException;
45
import java.io.PrintStream;
56

67
/**
78
* A generic interface for a console that supports input from the user and displays input on the
89
* screen.
910
*/
10-
public interface Console {
11+
public interface Console extends Closeable {
1112
String getImplementation();
1213

1314
String readLine(String prompt) throws IOException;

rhino-tools/src/main/java/org/mozilla/javascript/tools/ConsoleProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package org.mozilla.javascript.tools;
22

3-
import org.mozilla.javascript.Scriptable;
4-
53
/**
64
* This is a service interface to provide consoles. It allows there to be multiple console
75
* implementations at runtime based on classpath.
86
*/
97
public interface ConsoleProvider {
108
/** Create the console. Must not be called unless "isSupported" returned true. */
11-
Console newConsole(Scriptable scope);
9+
Console newConsole();
1210

1311
/** Return whether the console is possible to use at all */
1412
boolean isSupported();

rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/BasicConsole.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public BasicConsole() {
2323
setErr(System.err);
2424
}
2525

26+
@Override
27+
public void close() throws IOException {}
28+
2629
@Override
2730
public String getImplementation() {
2831
return "Default console";

rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/BasicConsoleProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package org.mozilla.javascript.tools.shell;
22

3-
import org.mozilla.javascript.Scriptable;
43
import org.mozilla.javascript.tools.Console;
54
import org.mozilla.javascript.tools.ConsoleProvider;
65

76
public class BasicConsoleProvider implements ConsoleProvider {
87
@Override
9-
public Console newConsole(Scriptable scope) {
8+
public Console newConsole() {
109
return new BasicConsole();
1110
}
1211

0 commit comments

Comments
 (0)