From bd9dd90649a4d0524a8ad37cf08d04de27e2dbc7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 31 Jan 2016 22:35:45 +0530 Subject: [PATCH] REPL: print newline before exit No tests added because the only way to test this seems to be to launch a new process and send "Ctrl+D" into it, which seems cumbersome for such small change --- .../kotlin/cli/jvm/repl/messages/ReplConsoleWriter.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplConsoleWriter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplConsoleWriter.kt index e5585bde644..1ec366bcd9c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplConsoleWriter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/messages/ReplConsoleWriter.kt @@ -17,6 +17,17 @@ 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)