Support ansi by default if color is supported

Scalatest will check the ansiCodesSupported value of a console appender
to decide whether or not to colorize its output. We were setting
isAnsiSupported to false by default in ci to prevent the ConsoleAppender
from adding ansi codes to the output. The only place though where we
were doing that was in adding a ClearScreenAfterCursor to the end of
each log line. This was done for supershell but there is actually other
logic in supershell processing that adds these anyway.
This commit is contained in:
Ethan Atkins 2020-11-04 13:25:52 -08:00
parent 4983fbd536
commit 3b09ff6af7
2 changed files with 3 additions and 5 deletions

View File

@ -460,8 +460,7 @@ trait Appender extends AutoCloseable {
// according to https://github.com/sbt/sbt/issues/5608, sometimes we get a null message
if (message == null) ()
else {
val len =
labelColor.length + label.length + messageColor.length + reset.length * 3 + ClearScreenAfterCursor.length
val len = labelColor.length + label.length + messageColor.length + reset.length * 3
val builder: StringBuilder = new StringBuilder(len)
message.linesIterator.foreach { line =>
builder.ensureCapacity(len + line.length + 4)
@ -477,7 +476,6 @@ trait Appender extends AutoCloseable {
fmted(labelColor, label)
builder.append("] ")
fmted(messageColor, line)
if (ansiCodesSupported) builder.append(ClearScreenAfterCursor)
write(builder.toString)
}
}
@ -495,7 +493,7 @@ trait Appender extends AutoCloseable {
// the output may have unwanted colors but it would still be legible. This should
// only be relevant if the log message string itself contains ansi escape sequences
// other than color codes which is very unlikely.
val toWrite = if (!ansiCodesSupported || !useFormat && msg.getBytes.contains(27.toByte)) {
val toWrite = if ((!ansiCodesSupported || !useFormat) && msg.getBytes.contains(27.toByte)) {
val (bytes, len) =
EscHelpers.strip(msg.getBytes, stripAnsi = !ansiCodesSupported, stripColor = !useFormat)
new String(bytes, 0, len)

View File

@ -308,7 +308,7 @@ object Terminal {
}
private[this] lazy val superShellEnabled = sys.props.get("sbt.supershell").map(_ == "true")
private[sbt] lazy val isAnsiSupported: Boolean =
logFormatEnabled.orElse(superShellEnabled).getOrElse(useColorDefault && !isCI)
logFormatEnabled.orElse(superShellEnabled).getOrElse(useColorDefault)
private[this] val isDumbTerminal = "dumb" == System.getenv("TERM")
private[this] val hasConsole = Option(java.lang.System.console).isDefined
private[this] def useColorDefault: Boolean = {