Don't use usingTerminal

The usingTerminal method synchronizes the JLine object which can lead to
deadlock if multiple threads call it. When we just to want to read the
attributes of the terminal, but not modify it, there doesn't seem to be
any reason to use a lock.
This commit is contained in:
Ethan Atkins 2019-03-23 11:04:44 -07:00
parent 447ab5011c
commit 6b82a8d07e
4 changed files with 5 additions and 5 deletions

View File

@ -127,7 +127,7 @@ private[sbt] object JLine {
// 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
private[sbt] def terminal = jline.TerminalFactory.get
private def withTerminal[T](f: jline.Terminal => T): T =
synchronized {

View File

@ -27,9 +27,9 @@ trait CommandLineUIService extends InteractionService {
}
}
override def terminalWidth: Int = JLine.usingTerminal(_.getWidth)
override def terminalWidth: Int = JLine.terminal.getWidth
override def terminalHeight: Int = JLine.usingTerminal(_.getHeight)
override def terminalHeight: Int = JLine.terminal.getHeight
}
object CommandLineUIService extends CommandLineUIService

View File

@ -82,7 +82,7 @@ object Graph {
// [info] |
// [info] +-quux
def toAscii[A](top: A, children: A => Seq[A], display: A => String, defaultWidth: Int): String = {
val maxColumn = math.max(JLine.usingTerminal(_.getWidth), defaultWidth) - 8
val maxColumn = math.max(JLine.terminal.getWidth, defaultWidth) - 8
val twoSpaces = " " + " " // prevent accidentally being converted into a tab
def limitLine(s: String): String =
if (s.length > maxColumn) s.slice(0, maxColumn - 2) + ".."

View File

@ -25,7 +25,7 @@ private[sbt] final class TaskProgress
private[this] val isStopped = new AtomicBoolean(false)
override def initial(): Unit = {
ConsoleAppender.setTerminalWidth(JLine.usingTerminal(_.getWidth))
ConsoleAppender.setTerminalWidth(JLine.terminal.getWidth)
}
override def afterReady(task: Task[_]): Unit = {