Don't start an ask user thread for dead console

If there is no system console available, then there is no point in
making an ask user thread. An ask user thread can only be created when
the terminal prompt is in the Prompt.Running or Prompt.Loading state.
The console channel will now set itself to be in the Prompt.NoPrompt
state if it detects that there is no System.console available.

The motivation for this change is that jline was printing a lot of extra
text during scripted and server tests. Whenever a jline3 linereader is
closed, it prints a newline so the logs were filled with unnecessary
newlines.
This commit is contained in:
Ethan Atkins 2020-07-10 13:15:16 -07:00
parent 366c49a764
commit dea7bdfa89
4 changed files with 17 additions and 11 deletions

View File

@ -644,10 +644,13 @@ private[sbt] object ProgressState {
val isRunning = terminal.prompt == Prompt.Running val isRunning = terminal.prompt == Prompt.Running
val isBatch = terminal.prompt == Prompt.Batch val isBatch = terminal.prompt == Prompt.Batch
val isWatch = terminal.prompt == Prompt.Watch val isWatch = terminal.prompt == Prompt.Watch
val noPrompt = terminal.prompt == Prompt.NoPrompt
if (terminal.isSupershellEnabled) { if (terminal.isSupershellEnabled) {
if (!pe.skipIfActive.getOrElse(false) || (!isRunning && !isBatch)) { if (!pe.skipIfActive.getOrElse(false) || (!isRunning && !isBatch)) {
terminal.withPrintStream { ps => terminal.withPrintStream { ps =>
val info = if (isRunning || isBatch && pe.channelName.fold(true)(_ == terminal.name)) { val info =
if ((isRunning || isBatch || noPrompt) && pe.channelName
.fold(true)(_ == terminal.name)) {
pe.items.map { item => pe.items.map { item =>
val elapsed = item.elapsedMicros / 1000000L val elapsed = item.elapsedMicros / 1000000L
s" | => ${item.name} ${elapsed}s" s" | => ${item.name} ${elapsed}s"

View File

@ -45,4 +45,5 @@ private[sbt] object Prompt {
private[sbt] case object Batch extends NoPrompt private[sbt] case object Batch extends NoPrompt
private[sbt] case object Watch extends NoPrompt private[sbt] case object Watch extends NoPrompt
private[sbt] case object Loading extends NoPrompt private[sbt] case object Loading extends NoPrompt
private[sbt] case object NoPrompt extends NoPrompt
} }

View File

@ -126,7 +126,8 @@ trait Terminal extends AutoCloseable {
private[sbt] val progressState = new ProgressState(1) private[sbt] val progressState = new ProgressState(1)
private[this] val promptHolder: AtomicReference[Prompt] = new AtomicReference(Prompt.Running) private[this] val promptHolder: AtomicReference[Prompt] = new AtomicReference(Prompt.Running)
private[sbt] final def prompt: Prompt = promptHolder.get private[sbt] final def prompt: Prompt = promptHolder.get
private[sbt] final def setPrompt(newPrompt: Prompt): Unit = promptHolder.set(newPrompt) private[sbt] final def setPrompt(newPrompt: Prompt): Unit =
if (prompt != Prompt.NoPrompt) promptHolder.set(newPrompt)
/** /**
* Returns the number of lines that the input string will cover given the current width of the * Returns the number of lines that the input string will cover given the current width of the

View File

@ -25,6 +25,7 @@ private[sbt] final class ConsoleChannel(
override val userThread: UserThread = new UserThread(this) override val userThread: UserThread = new UserThread(this)
private[sbt] def terminal = Terminal.console private[sbt] def terminal = Terminal.console
if (System.console == null) terminal.setPrompt(Prompt.NoPrompt)
} }
private[sbt] object ConsoleChannel { private[sbt] object ConsoleChannel {
private[sbt] def defaultName = "console0" private[sbt] def defaultName = "console0"