mirror of https://github.com/sbt/sbt.git
Merge pull request #5737 from eatkins/reprompt
Add reprompt fast track command
This commit is contained in:
commit
3c5b88a83a
|
|
@ -74,13 +74,13 @@ object LineReader {
|
|||
parser: Parser[_],
|
||||
terminal: Terminal,
|
||||
): LineReader = {
|
||||
val term = JLine3(terminal)
|
||||
// We may want to consider insourcing LineReader.java from jline. We don't otherwise
|
||||
// directly need jline3 for sbt.
|
||||
val reader = LineReaderBuilder.builder().terminal(term).completer(completer(parser)).build()
|
||||
historyPath.foreach(f => reader.setVariable(JLineReader.HISTORY_FILE, f))
|
||||
new LineReader {
|
||||
override def readLine(prompt: String, mask: Option[Char]): Option[String] = {
|
||||
val term = JLine3(terminal)
|
||||
val reader = LineReaderBuilder.builder().terminal(term).completer(completer(parser)).build()
|
||||
historyPath.foreach(f => reader.setVariable(JLineReader.HISTORY_FILE, f))
|
||||
try terminal.withRawInput {
|
||||
Option(mask.map(reader.readLine(prompt, _)).getOrElse(reader.readLine(prompt)))
|
||||
} catch {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ private[sbt] object UITask {
|
|||
def readLine(): Either[String, String] =
|
||||
try {
|
||||
val clear = terminal.ansi(ClearPromptLine, "")
|
||||
@tailrec def impl(): Either[String, String] = {
|
||||
val res = {
|
||||
val thread = Thread.currentThread
|
||||
if (thread.isInterrupted || closed.get) throw interrupted
|
||||
val reader = LineReader.createReader(history(state), parser, terminal)
|
||||
|
|
@ -76,16 +76,17 @@ private[sbt] object UITask {
|
|||
case None => Left(TerminateAction)
|
||||
case Some(s: String) =>
|
||||
s.trim() match {
|
||||
case "" => impl()
|
||||
// We need to put the empty string on the fast track queue so that we can
|
||||
// reprompt the user if another command is running on the server.
|
||||
case "" => Left("")
|
||||
case cmd @ (`Shutdown` | `TerminateAction` | `Cancel`) => Left(cmd)
|
||||
case cmd => Right(cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
val res = impl()
|
||||
terminal.setPrompt(Prompt.Pending)
|
||||
res
|
||||
} catch { case e: InterruptedException => Right("") }
|
||||
} catch { case e: InterruptedException => Left("") }
|
||||
override def close(): Unit = closed.set(true)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -446,7 +446,7 @@ private[sbt] final class CommandExchange {
|
|||
case null =>
|
||||
case mt: FastTrackTask =>
|
||||
mt.task match {
|
||||
case `attach` => mt.channel.prompt(ConsolePromptEvent(lastState.get))
|
||||
case `attach` | "" => mt.channel.prompt(ConsolePromptEvent(lastState.get))
|
||||
case `Cancel` =>
|
||||
Option(currentExecRef.get).foreach(cancel)
|
||||
mt.channel.prompt(ConsolePromptEvent(lastState.get))
|
||||
|
|
|
|||
Loading…
Reference in New Issue