summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-10-07 22:32:45 -0500
committerAdriaan Moors <adriaan@lightbend.com>2016-10-08 17:00:49 -0500
commitd571fa07fbacedc099ff71b050918c679185dc82 (patch)
treeecf928955189fbe5bf085962db2a3c9c2b278010
parent9d3f0777ff883a7c59da3fa7fee156890f51701e (diff)
downloadscala-d571fa07fbacedc099ff71b050918c679185dc82.tar.gz
scala-d571fa07fbacedc099ff71b050918c679185dc82.tar.bz2
scala-d571fa07fbacedc099ff71b050918c679185dc82.zip
Repl prints '\n' as newline, not "^J"
Work around a weird bug in JLine. Fix https://github.com/scala/scala-dev/issues/240
-rw-r--r--src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala
index 95964e18d9..35523f9512 100644
--- a/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala
+++ b/src/repl-jline/scala/tools/nsc/interpreter/jline/JLineReader.scala
@@ -91,11 +91,19 @@ private class JLineConsoleReader extends jconsole.ConsoleReader with interpreter
printColumns_(items: List[String])
}
+ // Workaround for JLine weirdness. (See https://github.com/scala/scala-dev/issues/240)
+ // Emit control characters as-is, instead of representing them as e.g. "^J" (for '\n').
+ // `rawPrint` is package protected in jline.console.ConsoleReader, while `rawPrintln` is private
+ // Copy/paste part of it as `_rawPrint` (to avoid name clash);
+ // the super class impl also sets `cursorOk`, but that's out of reach for us.
+ private def _rawPrint(str: String) = getOutput.write(str)
+ private def rawPrintln(str: String) = { _rawPrint(str); println() }
+
private def printColumns_(items: List[String]): Unit = if (items exists (_ != "")) {
val grouped = tabulate(items)
var linesLeft = if (isPaginationEnabled()) height - 1 else Int.MaxValue
grouped foreach { xs =>
- println(xs.mkString)
+ rawPrintln(xs.mkString)
linesLeft -= 1
if (linesLeft <= 0) {
linesLeft = emulateMore()
@@ -106,7 +114,7 @@ private class JLineConsoleReader extends jconsole.ConsoleReader with interpreter
}
def readOneKey(prompt: String) = {
- this.print(prompt)
+ _rawPrint(prompt)
this.flush()
this.readCharacter()
}