mirror of https://github.com/sbt/sbt.git
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:
parent
366c49a764
commit
dea7bdfa89
|
|
@ -644,20 +644,23 @@ private[sbt] object ProgressState {
|
|||
val isRunning = terminal.prompt == Prompt.Running
|
||||
val isBatch = terminal.prompt == Prompt.Batch
|
||||
val isWatch = terminal.prompt == Prompt.Watch
|
||||
val noPrompt = terminal.prompt == Prompt.NoPrompt
|
||||
if (terminal.isSupershellEnabled) {
|
||||
if (!pe.skipIfActive.getOrElse(false) || (!isRunning && !isBatch)) {
|
||||
terminal.withPrintStream { ps =>
|
||||
val info = if (isRunning || isBatch && pe.channelName.fold(true)(_ == terminal.name)) {
|
||||
pe.items.map { item =>
|
||||
val elapsed = item.elapsedMicros / 1000000L
|
||||
s" | => ${item.name} ${elapsed}s"
|
||||
val info =
|
||||
if ((isRunning || isBatch || noPrompt) && pe.channelName
|
||||
.fold(true)(_ == terminal.name)) {
|
||||
pe.items.map { item =>
|
||||
val elapsed = item.elapsedMicros / 1000000L
|
||||
s" | => ${item.name} ${elapsed}s"
|
||||
}
|
||||
} else {
|
||||
pe.command.toSeq.flatMap { cmd =>
|
||||
val tail = if (isWatch) Nil else "enter 'cancel' to stop evaluation" :: Nil
|
||||
s"sbt server is running '$cmd'" :: tail
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pe.command.toSeq.flatMap { cmd =>
|
||||
val tail = if (isWatch) Nil else "enter 'cancel' to stop evaluation" :: Nil
|
||||
s"sbt server is running '$cmd'" :: tail
|
||||
}
|
||||
}
|
||||
|
||||
val currentLength = info.foldLeft(0)(_ + terminal.lineCount(_))
|
||||
val previousLines = state.progressLines.getAndSet(info)
|
||||
|
|
|
|||
|
|
@ -45,4 +45,5 @@ private[sbt] object Prompt {
|
|||
private[sbt] case object Batch extends NoPrompt
|
||||
private[sbt] case object Watch extends NoPrompt
|
||||
private[sbt] case object Loading extends NoPrompt
|
||||
private[sbt] case object NoPrompt extends NoPrompt
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ trait Terminal extends AutoCloseable {
|
|||
private[sbt] val progressState = new ProgressState(1)
|
||||
private[this] val promptHolder: AtomicReference[Prompt] = new AtomicReference(Prompt.Running)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ private[sbt] final class ConsoleChannel(
|
|||
|
||||
override val userThread: UserThread = new UserThread(this)
|
||||
private[sbt] def terminal = Terminal.console
|
||||
if (System.console == null) terminal.setPrompt(Prompt.NoPrompt)
|
||||
}
|
||||
private[sbt] object ConsoleChannel {
|
||||
private[sbt] def defaultName = "console0"
|
||||
|
|
|
|||
Loading…
Reference in New Issue