Merge pull request #225 from eatkins/divide-by-zero

Divide by zero
This commit is contained in:
eugene yokota 2019-09-24 20:54:20 -04:00 committed by GitHub
commit 0c9ac98b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -373,24 +373,23 @@ class ConsoleAppender private[ConsoleAppender] (
}
val width = ConsoleAppender.terminalWidth
val extra: Int = info.foldLeft(0)(_ + terminalLines(width)(_))
val currentLength = info.foldLeft(info.length)(_ + terminalLines(width)(_))
val previousLines = progressLines.getAndSet(info)
val prevExtra = previousLines.foldLeft(0)(_ + terminalLines(width)(_))
val prevLength = previousLines.foldLeft(previousLines.length)(_ + terminalLines(width)(_))
val prevPadding = padding.get
val newPadding =
math.max(0, previousLines.length + prevExtra + prevPadding - info.length - extra)
val newPadding = math.max(0, prevLength + prevPadding - currentLength)
padding.set(newPadding)
deleteConsoleLines(newPadding)
deleteConsoleLines(blankZone)
info.foreach(i => out.println(i))
out.print(cursorUp(blankZone + info.length + newPadding + extra))
out.print(cursorUp(blankZone + currentLength + newPadding))
out.flush()
}
private def terminalLines(width: Int): String => Int =
(progressLine: String) => (progressLine.length - 1) / width
(progressLine: String) => if (width > 0) (progressLine.length - 1) / width else 0
private def deleteConsoleLines(n: Int): Unit = {
(1 to n) foreach { _ =>
out.println(DeleteLine)