Don't display progress in skip tasks in batch mode

In sbt 1.4.0-RC1, if a user ran `sbt console`, the progress lines would
be printed after they had entered the console. This was because the
prompt state was incorrect. To get the prompt in the correct state, we
initialize the prompt to batch and then switch to pending when either
sbt enters the shell or the network client attaches in interactive mode.
We also will now immediately print progress as soon as we enter a skip
task to clear out the progress lines and display the warning about a
running task if there is another client connected while the task is
running.
This commit is contained in:
Ethan Atkins 2020-09-18 12:52:31 -07:00
parent cc0445db4e
commit 41afe9fbdb
4 changed files with 19 additions and 11 deletions

View File

@ -142,7 +142,7 @@ trait Terminal extends AutoCloseable {
private[sbt] def withRawOutput[R](f: => R): R
private[sbt] def restore(): Unit = {}
private[sbt] def progressState: ProgressState
private[this] val promptHolder: AtomicReference[Prompt] = new AtomicReference(Prompt.Pending)
private[this] val promptHolder: AtomicReference[Prompt] = new AtomicReference(Prompt.Batch)
private[sbt] final def prompt: Prompt = promptHolder.get
private[sbt] final def setPrompt(newPrompt: Prompt): Unit =
if (prompt != Prompt.NoPrompt) promptHolder.set(newPrompt)

View File

@ -1035,6 +1035,7 @@ object BuiltinCommands {
if (Terminal.startedByRemoteClient && !exchange.hasServer) {
Exec(Shutdown, None) +: s1
} else {
if (Terminal.console.prompt == Prompt.Batch) Terminal.console.setPrompt(Prompt.Pending)
exchange prompt ConsolePromptEvent(s0)
val minGCInterval = Project
.extract(s1)

View File

@ -106,7 +106,10 @@ private[sbt] class TaskProgress(
override def afterReady(task: Task[_]): Unit =
if (!closed.get) {
Util.ignoreResult(active.put(task, schedule(threshold, recurring = false)(doReport())))
if (skipReportTasks.contains(getShortName(task))) {
lastTaskCount.set(-1) // force a report for remote clients
report()
} else Util.ignoreResult(active.put(task, schedule(threshold, recurring = false)(doReport())))
} else {
logger.debug(s"called afterReady for ${taskName(task)} after task progress was closed")
}
@ -175,19 +178,23 @@ private[sbt] class TaskProgress(
}
}
private[this] def getShortName(task: Task[_]): String = {
val name = taskName(task)
name.lastIndexOf('/') match {
case -1 => name
case i =>
var j = i + 1
while (name(j) == ' ') j += 1
name.substring(j)
}
}
private[this] def filter(
tasks: Vector[(Task[_], Long)]
): (Vector[(Task[_], Long)], Boolean) = {
tasks.foldLeft((Vector.empty[(Task[_], Long)], false)) {
case ((tasks, skip), pair @ (t, _)) =>
val n = taskName(t)
val shortName = n.lastIndexOf('/') match {
case -1 => n
case i =>
var j = i + 1
while (n(j) == ' ') j += 1
n.substring(j)
}
val shortName = getShortName(t)
val newSkip = skip || skipReportTasks.contains(shortName)
if (hiddenTasks.contains(shortName)) (tasks, newSkip) else (tasks :+ pair, newSkip)
}

View File

@ -97,7 +97,7 @@ final class NetworkChannel(
case t => t.close()
}
interactive.set(value)
if (!isInteractive) terminal.setPrompt(Prompt.Batch)
if (isInteractive) terminal.setPrompt(Prompt.Pending)
attached.set(true)
pendingRequests.remove(id)
jsonRpcRespond("", id)