From 6ce239da8ff4f26dd407386ffbe18355a52e9af5 Mon Sep 17 00:00:00 2001 From: Jamie Holdroyd Date: Mon, 14 Aug 2017 03:13:57 +0100 Subject: [PATCH] Fix bar width when using ANSI styling --- lib/node-progress.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node-progress.js b/lib/node-progress.js index 2b62641..602cffd 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -145,7 +145,8 @@ ProgressBar.prototype.render = function (tokens) { .replace(':rate', Math.round(rate)); /* compute the available space (non-zero) for the bar */ - var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length); + var clean = str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); + var availableSpace = Math.max(0, this.stream.columns - clean.replace(':bar', '').length); if(availableSpace && process.platform === 'win32'){ availableSpace = availableSpace - 1; }