From e0a193c7cae36cc22bed247a93c7a84bedd9e791 Mon Sep 17 00:00:00 2001 From: Steven Evans Date: Thu, 2 Aug 2018 12:11:03 -0400 Subject: [PATCH] [bug] 'createProgressBar' - actually possible to fill the entire bar --- utils/helpers/createProgressBarText.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utils/helpers/createProgressBarText.ts b/utils/helpers/createProgressBarText.ts index 8cd628277..37f433a00 100644 --- a/utils/helpers/createProgressBarText.ts +++ b/utils/helpers/createProgressBarText.ts @@ -34,11 +34,14 @@ export function createProgressBarText(params: IProgressBarConfiguration) { }; // tslint:disable-next-line:prefer-object-spread - const derivedParams: IProgressBarConfigurationMaterialized = Object.assign({}, defaultParams, params); + const derived: IProgressBarConfigurationMaterialized = Object.assign({}, defaultParams, params); + // Ensure it is 0..1 + derived.progress = Math.max(Math.min(derived.progress, 1), 0); - const bars: number = Math.floor(derivedParams.progress / (1 / derivedParams.totalTicks)); - const dashes: number = derivedParams.totalTicks - bars; + // This way there is always at least one bar filled in... + const bars: number = Math.max(Math.floor(derived.progress / (1 / derived.totalTicks)), 1); + const dashes: number = Math.max(derived.totalTicks - bars, 0); // String.prototype.repeat isn't completley supported, but good enough for our purposes - return `[${"|".repeat(bars + 1)}${"-".repeat(dashes + 1)}]`; + return `[${"|".repeat(bars)}${"-".repeat(dashes)}]`; }