mirror of https://github.com/sbt/sbt.git
Disable noisy jline log lines
JLine will spam the console with error messages if certain commands get interrupted. This is very noticeable and annoying in tab completions. We can stop doing work in background as well since we've silenced the jline logging.
This commit is contained in:
parent
a2047a0b2c
commit
ddc4e850b5
|
|
@ -144,6 +144,9 @@ trait Terminal extends AutoCloseable {
|
|||
}
|
||||
|
||||
object Terminal {
|
||||
// Disable noisy jline log spam
|
||||
if (System.getProperty("sbt.jline.verbose", "false") != "true")
|
||||
jline.internal.Log.setOutput(new PrintStream(_ => {}, false))
|
||||
def consoleLog(string: String): Unit = {
|
||||
Terminal.console.printStream.println(s"[info] $string")
|
||||
}
|
||||
|
|
@ -405,34 +408,15 @@ object Terminal {
|
|||
|
||||
private[this] def wrap(terminal: jline.Terminal): Terminal = {
|
||||
val term: jline.Terminal with jline.Terminal2 = new jline.Terminal with jline.Terminal2 {
|
||||
/*
|
||||
* JLine spams the log with stacktraces if we directly interrupt the thread that is shelling
|
||||
* out to run an stty command. To avoid this, run certain commands on a background thread.
|
||||
*/
|
||||
private[this] def doInBackground[T](f: => T): Unit = {
|
||||
val result = new ArrayBlockingQueue[Either[Throwable, Any]](1)
|
||||
new Thread("sbt-terminal-background-work-thread") {
|
||||
setDaemon(true)
|
||||
start()
|
||||
override def run(): Unit = {
|
||||
try result.put(Right(f))
|
||||
catch { case t: Throwable => result.put(Left(t)) }
|
||||
}
|
||||
}
|
||||
result.take match {
|
||||
case Left(e) => throw e
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
private[this] val hasConsole = System.console != null
|
||||
private[this] def alive = hasConsole && attached.get
|
||||
private[this] val term2: jline.Terminal2 = terminal match {
|
||||
case t: jline.Terminal2 => t
|
||||
case _ => new DefaultTerminal2(terminal)
|
||||
}
|
||||
override def init(): Unit = if (alive) doInBackground(terminal.init())
|
||||
override def restore(): Unit = if (alive) doInBackground(terminal.restore())
|
||||
override def reset(): Unit = if (alive) doInBackground(terminal.reset())
|
||||
override def init(): Unit = if (alive) terminal.init()
|
||||
override def restore(): Unit = if (alive) terminal.restore()
|
||||
override def reset(): Unit = if (alive) terminal.reset()
|
||||
override def isSupported: Boolean = terminal.isSupported
|
||||
override def getWidth: Int = terminal.getWidth
|
||||
override def getHeight: Int = terminal.getHeight
|
||||
|
|
@ -442,11 +426,8 @@ object Terminal {
|
|||
override def hasWeirdWrap: Boolean = terminal.hasWeirdWrap
|
||||
override def isEchoEnabled: Boolean = terminal.isEchoEnabled
|
||||
|
||||
/*
|
||||
* Do this on a background thread so that jline doesn't spam the logs if interrupted
|
||||
*/
|
||||
override def setEchoEnabled(enabled: Boolean): Unit =
|
||||
if (alive) doInBackground(terminal.setEchoEnabled(enabled))
|
||||
if (alive) terminal.setEchoEnabled(enabled)
|
||||
override def disableInterruptCharacter(): Unit =
|
||||
if (alive) terminal.disableInterruptCharacter()
|
||||
override def enableInterruptCharacter(): Unit =
|
||||
|
|
|
|||
Loading…
Reference in New Issue