Merge pull request #6557 from eed3si9n/wip/proxy_terminal

lazily initialize ProxyTerminal to SimpleTerminal
This commit is contained in:
eugene yokota 2021-06-20 18:07:11 -04:00 committed by GitHub
commit 62f6bd15e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -346,7 +346,7 @@ object Terminal {
consoleTerminalHolder.set(newConsoleTerminal())
if (hasVirtualIO) {
hasProgress.set(isServer && isAnsiSupported)
activeTerminal.set(consoleTerminalHolder.get)
Terminal.set(consoleTerminalHolder.get)
try withOut(withIn(f))
finally {
jline.TerminalFactory.reset()
@ -382,7 +382,16 @@ object Terminal {
}
private[this] object ProxyTerminal extends Terminal {
private def t: Terminal = activeTerminal.get
private def t: Terminal = {
val current = activeTerminal.get
// if the activeTerminal is yet to be initialized on use,
// initialize to the conventional simple terminal for compatibility and testing
if (current ne null) current
else {
Terminal.set(Terminal.SimpleTerminal)
activeTerminal.get
}
}
override private[sbt] def progressState: ProgressState = t.progressState
override private[sbt] def enterRawMode(): Unit = t.enterRawMode()
override private[sbt] def exitRawMode(): Unit = t.exitRawMode()

View File

@ -21,8 +21,8 @@ class ManagedLoggerSpec extends FlatSpec with Matchers {
"ManagedLogger" should "log to console" in {
val log = newLogger("foo")
context.addAppender("foo", asyncStdout -> Level.Info)
log.info("test")
log.debug("test")
log.info("test_info")
log.debug("test_debug")
}
it should "support event logging" in {