Honor shellPrompt override

sbt 1.4.0 generates the shell prompt using the terminal properties for
the specific terminal for which the prompt is rendered. The mechanism
for doing this broke the prompt for projects that overrode the
shellPrompt key, notably the play plugin. After this change, the play
custom prompt is correctly rendered with 1.4.0-SNAPSHOT.
This commit is contained in:
Ethan Atkins 2020-09-11 10:50:20 -07:00
parent 96b4f7b8e6
commit a471e7384d
2 changed files with 17 additions and 7 deletions

View File

@ -44,6 +44,9 @@ private[sbt] trait UITask extends Runnable with AutoCloseable {
}
private[sbt] object UITask {
case object NoShellPrompt extends (State => String) {
override def apply(state: State): String = ""
}
trait Reader extends AutoCloseable {
def readLine(): Either[String, String]
override def close(): Unit = {}
@ -93,11 +96,15 @@ private[sbt] object UITask {
private[this] def history(s: State): Option[File] =
s.get(historyPath).getOrElse(Some(new File(s.baseDir, ".history")))
private[sbt] def shellPrompt(terminal: Terminal, s: State): String =
s.get(terminalShellPrompt) match {
case Some(pf) => pf(terminal, s)
case None =>
def ansi(s: String): String = if (terminal.isAnsiSupported) s"$s" else ""
s"${ansi(DeleteLine)}> ${ansi(ClearScreenAfterCursor)}"
s.get(sbt.BasicKeys.shellPrompt) match {
case Some(NoShellPrompt) | None =>
s.get(terminalShellPrompt) match {
case Some(pf) => pf(terminal, s)
case None =>
def ansi(s: String): String = if (terminal.isAnsiSupported) s"$s" else ""
s"${ansi(DeleteLine)}> ${ansi(ClearScreenAfterCursor)}"
}
case Some(p) => p(s)
}
private[sbt] class AskUserTask(
state: State,

View File

@ -2558,9 +2558,12 @@ object Classpaths {
val base = ModuleID(id.groupID, id.name, sbtVersion.value).withCrossVersion(cross)
CrossVersion(scalaVersion, binVersion)(base).withCrossVersion(Disabled())
},
shellPrompt := shellPromptFromState,
shellPrompt := sbt.internal.ui.UITask.NoShellPrompt,
terminalShellPrompt := { (t, s) =>
shellPromptFromState(t)(s)
shellPrompt.value match {
case sbt.internal.ui.UITask.NoShellPrompt => shellPromptFromState(t)(s)
case p => p(s)
}
},
dynamicDependency := { (): Unit },
transitiveClasspathDependency := { (): Unit },