From 874a357f25870ddaba7be8fe71b97269aae3dd32 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Wed, 26 Jun 2013 10:07:32 -0400 Subject: [PATCH] jline/jansi fixes for windows. Fixes #763, fixes #562. The startup script should set sbt.cygwin=true if running from cygwin. This will set the terminal type properly for JLine if not already set. If sbt.cygwin=false or unset and os.name includes "windows", JAnsi is downloaded by the launcher and installed on standard out/err. The value for jline.terminal is transformed from explicit jline.X to the basic types "windows", "unix", or "none". Now that sbt uses JLine 2.0, these types are understood by both sbt's JLine and Scala's. Older Scala versions shaded the classes but not the terminal property so both couldn't be configured with a class name at the same time. --- .../src/main/scala/sbt/LineReader.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/util/complete/src/main/scala/sbt/LineReader.scala b/util/complete/src/main/scala/sbt/LineReader.scala index 6d81a2391..e3d3df0f0 100644 --- a/util/complete/src/main/scala/sbt/LineReader.scala +++ b/util/complete/src/main/scala/sbt/LineReader.scala @@ -64,6 +64,24 @@ abstract class JLine extends LineReader } private object JLine { + private[this] val TerminalProperty = "jline.terminal" + + fixTerminalProperty() + + // translate explicit class names to type in order to support + // older Scala, since it shaded classes but not the system property + private[sbt] def fixTerminalProperty() { + val newValue = System.getProperty(TerminalProperty) match { + case "jline.UnixTerminal" => "unix" + case null if System.getProperty("sbt.cygwin") != null => "unix" + case "jline.WindowsTerminal" => "windows" + case "jline.AnsiWindowsTerminal" => "windows" + case "jline.UnsupportedTerminal" => "none" + case x => x + } + if(newValue != null) System.setProperty(TerminalProperty, newValue) + } + // When calling this, ensure that enableEcho has been or will be called. // TerminalFactory.get will initialize the terminal to disable echo. private def terminal = jline.TerminalFactory.get