From d571fa07fbacedc099ff71b050918c679185dc82 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 7 Oct 2016 22:32:45 -0500 Subject: Repl prints '\n' as newline, not "^J" Work around a weird bug in JLine. Fix https://github.com/scala/scala-dev/issues/240 --- .../scala/tools/nsc/interpreter/jline/JLineReader.scala | 12 ++++++++++-- 1 file 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() } -- cgit v1.2.3