Update to jline 3.3.1 and jansi 1.16
Note that the history file name was changed (.kotlin_history -> .kotlinc_history) because the history is now stored in a different (incompatible) format. #KT-11369 Fixed
This commit is contained in:
@@ -17,17 +17,6 @@
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.messages
|
||||
|
||||
class ReplConsoleWriter : ReplWriter {
|
||||
init {
|
||||
Runtime.getRuntime().addShutdownHook(object : Thread("Kotlin REPL shutdown hook") {
|
||||
override fun run() {
|
||||
// Print an empty line to make the command prompt start from the beginning of the line after REPL exits.
|
||||
// This is essentially a workaround of a jline2 bug.
|
||||
// TODO: remove this as soon as we update to jline3
|
||||
println()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun printlnWelcomeMessage(x: String) = println(x)
|
||||
override fun printlnHelpMessage(x: String) = println(x)
|
||||
override fun outputCompileError(x: String) = println(x)
|
||||
@@ -39,4 +28,4 @@ class ReplConsoleWriter : ReplWriter {
|
||||
override fun notifyIncomplete() {}
|
||||
override fun notifyCommandSuccess() {}
|
||||
override fun sendInternalErrorReport(x: String) {}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-10
@@ -16,22 +16,38 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.repl.reader
|
||||
|
||||
import jline.console.ConsoleReader
|
||||
import jline.console.history.FileHistory
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplFromTerminal
|
||||
import org.jline.reader.EndOfFileException
|
||||
import org.jline.reader.LineReader
|
||||
import org.jline.reader.LineReaderBuilder
|
||||
import org.jline.reader.UserInterruptException
|
||||
import org.jline.terminal.TerminalBuilder
|
||||
import java.io.File
|
||||
|
||||
class ConsoleReplCommandReader : ReplCommandReader {
|
||||
private val consoleReader = ConsoleReader("kotlin", System.`in`, System.`out`, null).apply {
|
||||
isHistoryEnabled = true
|
||||
expandEvents = false
|
||||
history = FileHistory(File(File(System.getProperty("user.home")), ".kotlin_history"))
|
||||
}
|
||||
private val lineReader = LineReaderBuilder.builder()
|
||||
.appName("kotlin")
|
||||
.terminal(TerminalBuilder.terminal())
|
||||
.variable(LineReader.HISTORY_FILE, File(File(System.getProperty("user.home")), ".kotlinc_history").absolutePath)
|
||||
.build()
|
||||
.apply {
|
||||
setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION)
|
||||
}
|
||||
|
||||
override fun readLine(next: ReplFromTerminal.WhatNextAfterOneLine): String? {
|
||||
val prompt = if (next == ReplFromTerminal.WhatNextAfterOneLine.INCOMPLETE) "... " else ">>> "
|
||||
return consoleReader.readLine(prompt)
|
||||
try {
|
||||
return lineReader.readLine(prompt)
|
||||
}
|
||||
catch (e: UserInterruptException) {
|
||||
println("<interrupted>")
|
||||
System.out.flush()
|
||||
return ""
|
||||
}
|
||||
catch (e: EndOfFileException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun flushHistory() = (consoleReader.history as FileHistory).flush()
|
||||
}
|
||||
override fun flushHistory() = lineReader.history.save()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user