Merge pull request #6556 from sebastian-alfers/fix-carriage-return

Fix carriage return in supershell progress state
This commit is contained in:
eugene yokota 2021-06-20 19:06:34 -04:00 committed by GitHub
commit f1ec9c05c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -107,7 +107,7 @@ private[sbt] final class ProgressState(
val parts = new String(bytes, "UTF-8").split(System.lineSeparator)
def appendLine(l: String, appendNewline: Boolean): Unit = {
toWrite ++= l.getBytes("UTF-8")
toWrite ++= clearScreenBytes
if (!l.getBytes("UTF-8").endsWith("\r")) toWrite ++= clearScreenBytes
if (appendNewline) toWrite ++= lineSeparatorBytes
}
parts.dropRight(1).foreach(appendLine(_, true))

View File

@ -0,0 +1,41 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal.util
import java.io.{ File, PrintStream }
import org.scalatest.{ BeforeAndAfterAll, FlatSpec }
import sbt.internal.util.Terminal.SimpleTerminal
import scala.io.Source
class ProgressStateSpec extends FlatSpec with BeforeAndAfterAll {
private lazy val fileIn = new File("/tmp/tmp.txt")
private lazy val fileOut = Source.fromFile("/tmp/tmp.txt")
override def afterAll(): Unit = {
fileIn.delete()
fileOut.close()
super.afterAll()
}
"test" should "not clear after carriage return (\\r) " in {
val ps = new ProgressState(1, 8)
val in = "Hello\r\nWorld".getBytes()
ps.write(SimpleTerminal, in, new PrintStream(fileIn), hasProgress = true)
val clearScreenBytes = ConsoleAppender.ClearScreenAfterCursor.getBytes("UTF-8")
val check = fileOut.getLines().toList.map { line =>
line.getBytes("UTF-8").endsWith(clearScreenBytes)
}
assert(check === List(false, true))
}
}