jline for repl
This commit is contained in:
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="jline">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/dependencies/jline-2.6.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/dependencies/jline-2.6-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
@@ -21,6 +21,7 @@ classpath="$root/out/production/cli"
|
||||
classpath="$classpath:$root/out/production/backend:$root/out/production/frontend:$root/out/production/frontend.java:$root/out/production/jet.as.java.psi:$root/out/production/util"
|
||||
classpath="$classpath:$root/out/production/stdlib:$root/out/production/runtime"
|
||||
classpath="$classpath:$root/lib/*:$ideaRoot/lib/*:$ideaRoot/lib/rt/*"
|
||||
classpath="$classpath:$root/dependencies/jline-2.6.jar"
|
||||
|
||||
exec java $JAVA_OPTS \
|
||||
-ea \
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<pathelement path="${idea.sdk}/lib/resources_en.jar"/>
|
||||
|
||||
<fileset dir="${basedir}/lib" includes="**/*.jar"/>
|
||||
<fileset dir="${basedir}/dependencies" includes="jline-*.jar"/>
|
||||
<fileset dir="${basedir}/js/js.translator/lib" includes="*.jar"/>
|
||||
</path>
|
||||
|
||||
@@ -165,6 +166,7 @@
|
||||
<zipgroupfileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
<zipgroupfileset dir="${basedir}/ideaSDK/core" includes="*.jar"/>
|
||||
<zipgroupfileset dir="${basedir}/js/js.translator/lib" includes="*.jar"/>
|
||||
<zipgroupfileset dir="${basedir}/dependencies" includes="jline-*.jar"/>
|
||||
|
||||
<zap pattern="com.thoughtworks.xstream.converters.extended.ISO8601*"/>
|
||||
<zap pattern="com.thoughtworks.xstream.converters.reflection.CGLIBEnhancedConverter*"/>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" name="asm" level="project" />
|
||||
<orderEntry type="module" module-name="js.translator" />
|
||||
<orderEntry type="library" name="jline" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
package org.jetbrains.jet.cli.jvm.repl;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import jline.console.ConsoleReader;
|
||||
import jline.console.history.FileHistory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import javax.sound.midi.SysexMessage;
|
||||
import java.io.Console;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,6 +37,8 @@ public class ReplFromTerminal {
|
||||
private Throwable replInitializationFailed;
|
||||
private final Object waitRepl = new Object();
|
||||
|
||||
private final ConsoleReader consoleReader;
|
||||
|
||||
public ReplFromTerminal(@NotNull final Disposable disposable, @NotNull final CompilerDependencies compilerDependencies) {
|
||||
final List<File> extraClasspath = Collections.<File>emptyList();
|
||||
new Thread("initialize-repl") {
|
||||
@@ -52,6 +54,14 @@ public class ReplFromTerminal {
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
try {
|
||||
consoleReader = new ConsoleReader("kotlin", System.in, System.out, null);
|
||||
consoleReader.setHistoryEnabled(true);
|
||||
consoleReader.setHistory(new FileHistory(new File(new File(System.getProperty("user.home")), ".kotlin_history")));
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ReplInterpreter getReplInterpreter() {
|
||||
@@ -74,24 +84,38 @@ public class ReplFromTerminal {
|
||||
}
|
||||
|
||||
private void doRun() {
|
||||
System.out.println("Kotlin");
|
||||
while (true) {
|
||||
boolean next = one();
|
||||
if (!next) {
|
||||
break;
|
||||
try {
|
||||
System.out.println("Kotlin");
|
||||
while (true) {
|
||||
boolean next = one();
|
||||
if (!next) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
} finally {
|
||||
try {
|
||||
((FileHistory) consoleReader.getHistory()).flush();
|
||||
} catch (Exception e) {
|
||||
System.err.println("failed to flush history: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean one() {
|
||||
System.out.print(">>> ");
|
||||
String line = System.console().readLine();
|
||||
if (line == null) {
|
||||
return false;
|
||||
try {
|
||||
String line = consoleReader.readLine(">>> ");
|
||||
if (line == null) {
|
||||
return false;
|
||||
}
|
||||
Object value = getReplInterpreter().eval(line);
|
||||
System.out.println(value);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
Object value = getReplInterpreter().eval(line);
|
||||
System.out.println(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies) {
|
||||
|
||||
@@ -63,6 +63,11 @@
|
||||
<!-- dx.jar -->
|
||||
<get src="http://search.maven.org/remotecontent?filepath=com/google/android/tools/dx/1.7/dx-1.7.jar" dest="dependencies/dx.jar"/>
|
||||
<get src="http://search.maven.org/remotecontent?filepath=com/google/android/tools/dx/1.7/dx-1.7-sources.jar" dest="dependencies/dx-sources.jar"/>
|
||||
|
||||
<get src="http://repo1.maven.org/maven2/jline/jline/2.6/jline-2.6.jar"
|
||||
dest="dependencies/jline-2.6.jar"/>
|
||||
<get src="http://repo1.maven.org/maven2/jline/jline/2.6/jline-2.6-sources.jar"
|
||||
dest="dependencies/jline-2.6-sources.jar"/>
|
||||
</target>
|
||||
|
||||
<macrodef name="execute_update">
|
||||
|
||||
Reference in New Issue
Block a user