Don't require newlines for main classes

There typically are fewer than 10 main classes in a project so allow the
user to just input a single digit in those cases. Otherwise fallback to
a line reader.
This commit is contained in:
Ethan Atkins 2019-12-12 20:05:49 -08:00
parent 44ef718448
commit c7b52203a0
1 changed files with 18 additions and 1 deletions

View File

@ -1486,7 +1486,24 @@ object Defaults extends BuildCommon {
} }
def askForMainClass(classes: Seq[String]): Option[String] = def askForMainClass(classes: Seq[String]): Option[String] =
sbt.SelectMainClass(Some(SimpleReader readLine _), classes) sbt.SelectMainClass(
if (classes.length >= 10) Some(SimpleReader.readLine(_))
else
Some(s => {
def print(st: String) = { scala.Console.out.print(st); scala.Console.out.flush() }
print(s)
Terminal.withRawSystemIn {
Terminal.wrappedSystemIn.read match {
case -1 => None
case b =>
val res = b.toChar.toString
println(res)
Some(res)
}
}
}),
classes
)
def pickMainClass(classes: Seq[String]): Option[String] = def pickMainClass(classes: Seq[String]): Option[String] =
sbt.SelectMainClass(None, classes) sbt.SelectMainClass(None, classes)