From a9b07e943f0ba82395e420dffeb56db73624c1fa Mon Sep 17 00:00:00 2001 From: CPatchane Date: Mon, 21 Jan 2019 14:06:57 +0100 Subject: [PATCH] fix: :bug: Fix bar width when using ANSI styling (by @jHoldroyd) From unmerged PR https://github.com/visionmedia/node-progress/pull/160 --- packages/cozy-scripts/utils/progress.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cozy-scripts/utils/progress.js b/packages/cozy-scripts/utils/progress.js index 10e560769..02a1c1b92 100644 --- a/packages/cozy-scripts/utils/progress.js +++ b/packages/cozy-scripts/utils/progress.js @@ -150,9 +150,14 @@ ProgressBar.prototype.render = function(tokens, force) { .replace(':rate', Math.round(rate)) /* compute the available space (non-zero) for the bar */ + var clean = str.replace( + // eslint-disable-next-line no-control-regex + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, + '' + ) var availableSpace = Math.max( 0, - this.stream.columns - str.replace(':bar', '').length + this.stream.columns - clean.replace(':bar', '').length ) if (availableSpace && process.platform === 'win32') { availableSpace = availableSpace - 1