From baa96be6dc1fb3a5209843b432fee78c9ca0abd8 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Fri, 10 Jul 2020 14:23:58 -0700 Subject: [PATCH] Use unprompt in watch to better manage ui state The unprompt method will actually kill the ui thread if its running. If we don't to this, we can get into a weird state where after watch is exited by , the ask user thread spins up but before it can print the prompt, the terminal prompt is changed to Running, which has an empty prompt. The end result is that jline3 never displays the prompt even though the line reader is active and reading bytes. When the user typed a prompt would appear. They also could input a command and it would run but it wasn't obvious what would happen since the prompt was missing. --- main/src/main/scala/sbt/internal/Continuous.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index 96efbb026..86125b023 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -1256,7 +1256,7 @@ private[sbt] object ContinuousCommands { watchState(channel).beforeCommand(state) } private[this] val postWatchCommand = watchCommand(postWatch) { (channel, state) => - StandardMain.exchange.channelForName(channel).foreach(_.terminal.setPrompt(Prompt.Watch)) + StandardMain.exchange.unprompt(ConsoleUnpromptEvent(Some(CommandSource(channel))), false) val ws = watchState(channel) watchStates.put(channel, ws.withPending(false)) ws.afterCommand(state) @@ -1266,7 +1266,7 @@ private[sbt] object ContinuousCommands { state } private[sbt] def stopWatchImpl(channelName: String): Unit = { - StandardMain.exchange.channelForName(channelName).foreach(_.terminal.setPrompt(Prompt.Running)) + StandardMain.exchange.unprompt(ConsoleUnpromptEvent(Some(CommandSource(channelName))), false) Option(watchStates.get(channelName)).foreach { ws => ws.afterWatch() ws.callbacks.onExit()