Skip to content

Commit a9b07e9

Browse files
committed
fix: 🐛 Fix bar width when using ANSI styling (by @jHoldroyd)
From unmerged PR visionmedia/node-progress#160
1 parent 35662d8 commit a9b07e9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/cozy-scripts/utils/progress.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,14 @@ ProgressBar.prototype.render = function(tokens, force) {
150150
.replace(':rate', Math.round(rate))
151151

152152
/* compute the available space (non-zero) for the bar */
153+
var clean = str.replace(
154+
// eslint-disable-next-line no-control-regex
155+
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
156+
''
157+
)
153158
var availableSpace = Math.max(
154159
0,
155-
this.stream.columns - str.replace(':bar', '').length
160+
this.stream.columns - clean.replace(':bar', '').length
156161
)
157162
if (availableSpace && process.platform === 'win32') {
158163
availableSpace = availableSpace - 1

0 commit comments

Comments
 (0)