Merge pull request #6107 from eatkins/watch-poll

Fix watch for dumb terminals
This commit is contained in:
eugene yokota 2020-11-18 10:22:44 -05:00 committed by GitHub
commit e5ea54d7f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -327,6 +327,9 @@ object Terminal {
if (isColorEnabled && doRed) Console.RED + str + Console.RESET
else str
private[this] def hasVirtualIO = System.getProperty("sbt.io.virtual", "") == "true" || !isCI
private[sbt] def canPollSystemIn: Boolean = hasConsole && !isDumbTerminal && hasVirtualIO
/**
*
* @param isServer toggles whether or not this is a server of client process
@ -337,7 +340,7 @@ object Terminal {
private[sbt] def withStreams[T](isServer: Boolean)(f: => T): T = {
// In ci environments, don't touch the io streams unless run with -Dsbt.io.virtual=true
if (hasConsole && !isDumbTerminal) consoleTerminalHolder.set(newConsoleTerminal())
if (System.getProperty("sbt.io.virtual", "") == "true" || !isCI) {
if (hasVirtualIO) {
hasProgress.set(isServer && isAnsiSupported)
activeTerminal.set(consoleTerminalHolder.get)
try withOut(withIn(f))

View File

@ -783,11 +783,20 @@ private[sbt] object Continuous extends DeprecatedContinuous {
}
executor => {
val interrupted = new AtomicBoolean(false)
@tailrec def read(): Int = {
if (terminal.name.startsWith("network")) terminal.inputStream.read
else if (Terminal.canPollSystemIn || terminal.inputStream.available > 0)
terminal.inputStream.read
else {
Thread.sleep(50)
read()
}
}
@tailrec def impl(): Option[Watch.Action] = {
val action =
try {
interrupted.set(false)
terminal.inputStream.read match {
read() match {
case -1 => throw new InterruptedException
case 3 => Watch.CancelWatch // ctrl+c on windows
case byte => inputHandler(byte.toChar.toString)