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.
This commit is contained in:
Ethan Atkins 2020-11-05 09:37:06 -08:00
parent e5164cdf43
commit e18f14b3c3
1 changed files with 5 additions and 8 deletions

View File

@ -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)