Merge pull request #3182 from eed3si9n/wip/interactive

Add InteractionService from sbt-core-next
This commit is contained in:
Dale Wijnand 2017-05-09 07:31:56 +01:00 committed by GitHub
commit 934fabae25
4 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package sbt
import sbt.internal.util.SimpleReader
trait CommandLineUIService extends InteractionService {
override def readLine(prompt: String, mask: Boolean): Option[String] = {
val maskChar = if (mask) Some('*') else None
SimpleReader.readLine(prompt, maskChar)
}
// TODO - Implement this better.
override def confirm(msg: String): Boolean = {
object Assent {
def unapply(in: String): Boolean = {
(in == "y" || in == "yes")
}
}
SimpleReader.readLine(msg + " (yes/no): ", None) match {
case Some(Assent()) => true
case _ => false
}
}
}
object CommandLineUIService extends CommandLineUIService

View File

@ -258,6 +258,7 @@ object Defaults extends BuildCommon {
.map(java.lang.Boolean.parseBoolean)
.getOrElse(GCUtil.defaultForceGarbageCollection),
minForcegcInterval :== GCUtil.defaultMinForcegcInterval,
interactionService :== CommandLineUIService,
serverPort := 5000 + (Hash
.toHex(Hash(appConfiguration.value.baseDirectory.toString))
.## % 1000)

View File

@ -0,0 +1,17 @@
package sbt
/**
* InteractionService provides an abstration over standard input.
* In the future this could be used to ask for inputs from
* other forms of sbt clients such as thin clients and IDEs.
*/
abstract class InteractionService {
/** Prompts the user for input, optionally with a mask for characters. */
def readLine(prompt: String, mask: Boolean): Option[String]
/** Ask the user to confirm something (yes or no) before continuing. */
def confirm(msg: String): Boolean
// TODO - Ask for input with autocomplete?
}

View File

@ -429,6 +429,7 @@ object Keys {
val sbtBinaryVersion = SettingKey[String]("sbt-binary-version", "Defines the binary compatibility version substring.", BPlusSetting)
val skip = TaskKey[Boolean]("skip", "For tasks that support it (currently only 'compile' and 'update'), setting skip to true will force the task to not to do its work. This exact semantics may vary by task.", BSetting)
val templateResolverInfos = SettingKey[Seq[TemplateResolverInfo]]("templateResolverInfos", "Template resolvers used for 'new'.", BSetting)
val interactionService = TaskKey[InteractionService]("interactionService", "Service used to ask for user input through the current user interface(s).", CTask)
// special
val sessionVars = AttributeKey[SessionVar.Map]("session-vars", "Bindings that exist for the duration of the session.", Invisible)