From 2cfbfcc842733a5541ea99f56ca2eb7968d8b6c9 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Wed, 10 Oct 2018 18:28:59 -0700 Subject: [PATCH] Disable re-run feature on windows For whatever reason, I couldn't get jline to work on windows, so I'm disabling the re-run with 'r' feature. This can almost surely be fixed, but the way I was invoking jline was blocking the continuous build from exiting when the user pressed enter. --- main-command/src/main/scala/sbt/Watched.scala | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/main-command/src/main/scala/sbt/Watched.scala b/main-command/src/main/scala/sbt/Watched.scala index 57267bb2e..d697bb56c 100644 --- a/main-command/src/main/scala/sbt/Watched.scala +++ b/main-command/src/main/scala/sbt/Watched.scala @@ -109,27 +109,34 @@ object Watched { type WatchSource = Source def terminateWatch(key: Int): Boolean = Watched.isEnter(key) - private def withCharBufferedStdIn[R](f: InputStream => R): R = JLine.usingTerminal { terminal => - val in = terminal.wrapInIfNeeded(System.in) - try { - while (in.available > 0) in.read() + private[this] val isWin = Properties.isWin + private def drain(is: InputStream): Unit = while (is.available > 0) is.read() + private def withCharBufferedStdIn[R](f: InputStream => R): R = + if (!isWin) JLine.usingTerminal { terminal => terminal.init() - f(in) - } finally { - while (in.available > 0) in.read() - terminal.reset() - } - } + val in = terminal.wrapInIfNeeded(System.in) + try { + drain(in) + f(in) + } finally { + drain(in) + terminal.reset() + } + } else + try { + drain(System.in) + f(System.in) + } finally drain(System.in) private[sbt] final val handleInput: InputStream => Action = in => { @tailrec def scanInput(): Action = { if (in.available > 0) { in.read() match { - case key if isEnter(key) => CancelWatch - case key if isR(key) => Trigger - case key if key >= 0 => scanInput() - case _ => Ignore + case key if isEnter(key) => CancelWatch + case key if isR(key) && !isWin => Trigger + case key if key >= 0 => scanInput() + case _ => Ignore } } else { Ignore @@ -137,8 +144,9 @@ object Watched { } scanInput() } + private[this] val reRun = if (isWin) "" else " or 'r' to re-run the command" private def waitMessage(project: String): String = - s"Waiting for source changes$project... (press enter to interrupt or 'r' to re-run the command)" + s"Waiting for source changes$project... (press enter to interrupt$reRun)" val defaultStartWatch: Int => Option[String] = count => Some(s"$count. ${waitMessage("")}") @deprecated("Use defaultStartWatch in conjunction with the watchStartMessage key", "1.3.0") val defaultWatchingMessage: WatchState => String = ws => defaultStartWatch(ws.count).get