diff --git a/.idea/libraries/jline.xml b/.idea/libraries/jline.xml
new file mode 100644
index 00000000000..f0546fcd609
--- /dev/null
+++ b/.idea/libraries/jline.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bin/kotlin b/bin/kotlin
index d6e08fa1d27..c69766e61cf 100755
--- a/bin/kotlin
+++ b/bin/kotlin
@@ -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 \
diff --git a/build.xml b/build.xml
index 5e477762b97..6db692014f7 100644
--- a/build.xml
+++ b/build.xml
@@ -21,6 +21,7 @@
+
@@ -165,6 +166,7 @@
+
diff --git a/compiler/cli/cli.iml b/compiler/cli/cli.iml
index 03add988345..c0cbe2baf01 100644
--- a/compiler/cli/cli.iml
+++ b/compiler/cli/cli.iml
@@ -15,6 +15,7 @@
+
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplFromTerminal.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplFromTerminal.java
index b3f417ee94d..c7b9ebb9912 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplFromTerminal.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplFromTerminal.java
@@ -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 extraClasspath = Collections.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) {
diff --git a/update_dependencies.xml b/update_dependencies.xml
index a92ac8769f9..553d2070ea7 100644
--- a/update_dependencies.xml
+++ b/update_dependencies.xml
@@ -63,6 +63,11 @@
+
+
+