Set color by default only if log format enabled

I noticed that if you run `sbt -Dsbt.log.noformat=true` there are colors
printed when using the latest sbt code. When running with that property
set, the expectation is there are no colors.
This commit is contained in:
Ethan Atkins 2020-10-23 08:23:33 -07:00
parent 7a3ca0d9c2
commit 0e63873032
1 changed files with 4 additions and 1 deletions

View File

@ -314,7 +314,10 @@ object Terminal {
private[this] def useColorDefault: Boolean = {
// This approximates that both stdin and stdio are connected,
// so by default color will be turned off for pipes and redirects.
props.map(_.color).orElse(isColorEnabledProp).getOrElse((hasConsole && !isDumbTerminal) || isCI)
props
.map(_.color)
.orElse(isColorEnabledProp)
.getOrElse((hasConsole && !isDumbTerminal && logFormatEnabled.getOrElse(true)) || isCI)
}
private[this] lazy val isColorEnabledProp: Option[Boolean] =
sys.props.get("sbt.color").orElse(sys.props.get("sbt.colour")).flatMap(parseLogOption)