Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #233 from eed3si9n/bport/new
Browse files Browse the repository at this point in the history
[1.3.x] Fixes sbt new by restoring the terminal
  • Loading branch information
eed3si9n authored Dec 12, 2019
2 parents 5ad8893 + 093ae55 commit b164a6b
Showing 1 changed file with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.apache.logging.log4j.{ Level => XLevel }
import org.apache.logging.log4j.message.{ Message, ObjectMessage, ReusableObjectMessage }
import org.apache.logging.log4j.core.{ LogEvent => XLogEvent }
import org.apache.logging.log4j.core.appender.AbstractAppender

import scala.util.control.NonFatal
import ConsoleAppender._

object ConsoleLogger {
Expand Down Expand Up @@ -102,9 +102,11 @@ object ConsoleAppender {
private[sbt] final val DeleteLine = "\u001B[2K"
private[sbt] final val CursorLeft1000 = "\u001B[1000D"
private[sbt] final val CursorDown1 = cursorDown(1)
private[this] val widthHolder: AtomicInteger = new AtomicInteger
private[sbt] def terminalWidth = widthHolder.get
private[sbt] def setTerminalWidth(n: Int): Unit = widthHolder.set(n)
private[sbt] lazy val terminalWidth = usingTerminal { t =>
t.getWidth
}
@deprecated("no longer used", "1.3.5")
private[sbt] def setTerminalWidth(n: Int): Unit = ()
private[this] val showProgressHolder: AtomicBoolean = new AtomicBoolean(false)
def setShowProgress(b: Boolean): Unit = showProgressHolder.set(b)
def showProgress: Boolean = showProgressHolder.get
Expand Down Expand Up @@ -289,22 +291,24 @@ object ConsoleAppender {

private[this] def ansiSupported =
try {
val terminal = jline.TerminalFactory.get
terminal.restore // #460
terminal.isAnsiSupported
usingTerminal { t =>
t.isAnsiSupported
}
} catch {
case _: Exception => !isWindows

// sbt 0.13 drops JLine 1.0 from the launcher and uses 2.x as a normal dependency
// when 0.13 is used with a 0.12 launcher or earlier, the JLine classes from the launcher get loaded
// this results in a linkage error as detected below. The detection is likely jvm specific, but the priority
// is avoiding mistakenly identifying something as a launcher incompatibility when it is not
case e: IncompatibleClassChangeError if e.getMessage == jline1to2CompatMsg =>
throw new IncompatibleClassChangeError(
"JLine incompatibility detected. Check that the sbt launcher is version 0.13.x or later."
)
case NonFatal(_) => !isWindows
}

/**
* For accessing the JLine Terminal object.
* This ensures re-enabling echo after getting the Terminal.
*/
private[this] def usingTerminal[T](f: jline.Terminal => T): T = {
val t = jline.TerminalFactory.get
t.restore
val result = f(t)
t.restore
result
}
private[this] def os = System.getProperty("os.name")
private[this] def isWindows = os.toLowerCase(Locale.ENGLISH).indexOf("windows") >= 0

Expand Down

0 comments on commit b164a6b

Please sign in to comment.