Skip to content

Commit e546137

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

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/cozy-scripts/utils/progress.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,14 @@ ProgressBar.prototype.render = function(tokens, force) {
154154
.replace(':rate', Math.round(rate))
155155

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

0 commit comments

Comments
 (0)