Merge pull request #6171 from eatkins/ctrl-c-watch

Fix ctrl+c handling after exiting watch
This commit is contained in:
eugene yokota 2020-11-26 12:30:59 -05:00 committed by GitHub
commit 29358529f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -121,6 +121,10 @@ object LineReader {
// ignore // ignore
} }
historyPath.foreach(f => reader.setVariable(JLineReader.HISTORY_FILE, f)) historyPath.foreach(f => reader.setVariable(JLineReader.HISTORY_FILE, f))
val signalRegistration = terminal match {
case _: Terminal.ConsoleTerminal => Some(Signals.register(() => terminal.write(-1)))
case _ => None
}
try terminal.withRawInput { try terminal.withRawInput {
Option(mask.map(reader.readLine(prompt, _)).getOrElse(reader.readLine(prompt))) Option(mask.map(reader.readLine(prompt, _)).getOrElse(reader.readLine(prompt)))
} catch { } catch {
@ -132,6 +136,7 @@ object LineReader {
_: UncheckedIOException => _: UncheckedIOException =>
throw new InterruptedException throw new InterruptedException
} finally { } finally {
signalRegistration.foreach(_.remove())
terminal.prompt.reset() terminal.prompt.reset()
term.close() term.close()
} }

View File

@ -172,7 +172,7 @@ private[sbt] object JLine3 {
if (buffer.isEmpty && !peek) fillBuffer() if (buffer.isEmpty && !peek) fillBuffer()
(if (peek) buffer.peek else buffer.take) match { (if (peek) buffer.peek else buffer.take) match {
case null => -2 case null => -2
case i => if (i == -3) throw new ClosedException else i case i => if (i == -3) throw new InterruptedException else i
} }
} }
override def peek(timeout: Long): Int = buffer.peek() match { override def peek(timeout: Long): Int = buffer.peek() match {

View File

@ -1003,10 +1003,12 @@ object BuiltinCommands {
val s1 = exchange.run(s0) val s1 = exchange.run(s0)
val exec: Exec = getExec(s1, Duration.Inf) val exec: Exec = getExec(s1, Duration.Inf)
val remaining: List[Exec] = val wait = s"${ContinuousCommands.waitWatch} $channel"
Exec(FailureWall, None) :: Exec(s"${ContinuousCommands.waitWatch} $channel", None) :: val onFailure =
s1.remainingCommands s1.onFailure.map(of => if (of.commandLine == Shell) of.withCommandLine(wait) else of)
val newState = s1.copy(remainingCommands = exec +: remaining) val waitExec = Exec(wait, None)
val remaining: List[Exec] = Exec(FailureWall, None) :: waitExec :: s1.remainingCommands
val newState = s1.copy(remainingCommands = exec +: remaining, onFailure = onFailure)
if (exec.commandLine.trim.isEmpty) newState if (exec.commandLine.trim.isEmpty) newState
else newState.clearGlobalLog else newState.clearGlobalLog
case _ => s0 case _ => s0

View File

@ -116,7 +116,7 @@ private[sbt] object Continuous extends DeprecatedContinuous {
case None => StandardMain.exchange.run(s) -> ConsoleChannel.defaultName case None => StandardMain.exchange.run(s) -> ConsoleChannel.defaultName
} }
val ws = ContinuousCommands.setupWatchState(channel, initialCount, commands, s1) val ws = ContinuousCommands.setupWatchState(channel, initialCount, commands, s1)
s"${ContinuousCommands.runWatch} $channel" :: ws s"${ContinuousCommands.runWatch} $channel" :: s"${ContinuousCommands.waitWatch} $channel" :: ws
} }
@deprecated("The input task version of watch is no longer available", "1.4.0") @deprecated("The input task version of watch is no longer available", "1.4.0")
@ -1279,7 +1279,7 @@ private[sbt] object ContinuousCommands {
case None => state case None => state
case Some(cs) => case Some(cs) =>
val pre = StashOnFailure :: s"$preWatch $channel" :: Nil val pre = StashOnFailure :: s"$preWatch $channel" :: Nil
val post = FailureWall :: PopOnFailure :: s"$postWatch $channel" :: s"$waitWatch $channel" :: Nil val post = FailureWall :: PopOnFailure :: s"$postWatch $channel" :: Nil
pre ::: cs.commands.toList ::: post ::: state pre ::: cs.commands.toList ::: post ::: state
} }
} }