From e18f14b3c3d60d1559987318a857b255353f254f Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Thu, 5 Nov 2020 09:37:06 -0800 Subject: [PATCH] Fix tab completions if color is disabled Tab completions did not work well in sbt 1.4.x when run with -Dsbt.color=false. This was because we were stripping a bunch of ansi codes, which caused some problems with the jline 3 completion engine. Instead of stripping the ansi codes, we can set the jline max_colors capability to 1 if color is disabled. With this change, the completions are similar to 1.3.13 except that in jline 2 the user has to hit tab twice to see all of the available candidates while in jline 3, the candidates are immediately printed below the prompt. --- .../src/main/scala/sbt/internal/util/JLine3.scala | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/util-logging/src/main/scala/sbt/internal/util/JLine3.scala b/internal/util-logging/src/main/scala/sbt/internal/util/JLine3.scala index 9de086fd3..48046ae66 100644 --- a/internal/util-logging/src/main/scala/sbt/internal/util/JLine3.scala +++ b/internal/util-logging/src/main/scala/sbt/internal/util/JLine3.scala @@ -124,12 +124,7 @@ private[sbt] object JLine3 { override val output: OutputStream = new OutputStream { override def write(b: Int): Unit = write(Array[Byte](b.toByte)) override def write(b: Array[Byte]): Unit = if (!closed.get) term.withPrintStream { ps => - val (toWrite, len) = if (b.contains(27.toByte)) { - if (!term.isAnsiSupported || !term.isColorEnabled) { - EscHelpers.strip(b, !term.isAnsiSupported, !term.isColorEnabled) - } else (b, b.length) - } else (b, b.length) - if (len == toWrite.length) ps.write(toWrite) else ps.write(toWrite, 0, len) + ps.write(b) term.prompt match { case a: Prompt.AskUser => a.write(b) case _ => @@ -188,8 +183,10 @@ private[sbt] object JLine3 { case c => c } } - override def getNumericCapability(cap: Capability): Integer = - term.getNumericCapability(cap.toString) + override def getNumericCapability(cap: Capability): Integer = { + if (cap == Capability.max_colors && !term.isColorEnabled) 1 + else term.getNumericCapability(cap.toString) + } override def getBooleanCapability(cap: Capability): Boolean = term.getBooleanCapability(cap.toString) def getAttributes(): Attributes = attributesFromMap(term.getAttributes)