From 4b4998026f1e520eb08bd6f0d853e7291411781c Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Sun, 28 Jun 2015 06:52:18 -0500 Subject: [PATCH] ConsoleProgressBar: auto-trim text info to fit expected length. --- build.gradle | 2 +- .../groovy/com/jdbernard/util/ConsoleProgressBar.groovy | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 1c0b19f..b146926 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: "groovy" apply plugin: "maven" group = "com.jdbernard" -version = "3.5" +version = "3.6" repositories { mavenCentral() } diff --git a/src/main/groovy/com/jdbernard/util/ConsoleProgressBar.groovy b/src/main/groovy/com/jdbernard/util/ConsoleProgressBar.groovy index 7f6a399..94876e9 100644 --- a/src/main/groovy/com/jdbernard/util/ConsoleProgressBar.groovy +++ b/src/main/groovy/com/jdbernard/util/ConsoleProgressBar.groovy @@ -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() }