ConsoleProgressBar: auto-trim text info to fit expected length.

This commit is contained in:
Jonathan Bernard 2015-06-28 06:52:18 -05:00
parent 84b3c3fa23
commit 4b4998026f
2 changed files with 6 additions and 3 deletions

View File

@ -2,7 +2,7 @@ apply plugin: "groovy"
apply plugin: "maven"
group = "com.jdbernard"
version = "3.5"
version = "3.6"
repositories {
mavenCentral() }

View File

@ -42,13 +42,16 @@ class ConsoleProgressBar {
def remMin = curPercent < 0.05 ? '?' : (int) (remTime / 60)
def remSec = curPercent < 0.05 ? '?' : (int) (((remTime / 60.0) - remMin) * 60)
lastInfo = info
if (info.length() > 16) info = info[0..<16]
if (info.length() < 16) info = info.padRight(16)
out.print '\b' * lastLinePrinted.length()
lastLinePrinted = '=' * numEq + (curStep > 0 ? "0" : "") + '-' * (MAX_STEP - curStep)
lastLinePrinted += " ${info.padRight(16)} -- (" +
lastLinePrinted += " ${info} -- (" +
"${String.format('%5.2f', curPercent * 100)}%, ${remMin ? remMin + 'm ' : ''}${remSec}s) "
out.print lastLinePrinted
lastStepAmount = curStep;
lastInfo = info
}
out.flush()
}