Skip to content

Commit 8ef3972

Browse files
committed
fix(clear): check before using stream.clearLine to prevent crash in Docker, fix #95
1 parent 191256e commit 8ef3972

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/node-progress.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ ProgressBar.prototype.render = function (tokens) {
145145
/* compute the available space (non-zero) for the bar */
146146
var availableSpace = Math.max(0, this.stream.columns - str.replace(':bar', '').length);
147147
if(availableSpace && process.platform === 'win32'){
148-
availableSpace = availableSpace - 1;
148+
availableSpace = availableSpace - 1;
149149
}
150-
150+
151151
var width = Math.min(this.width, availableSpace);
152152

153153
/* TODO: the following assumes the user has one ':bar' token */
@@ -221,8 +221,10 @@ ProgressBar.prototype.interrupt = function (message) {
221221

222222
ProgressBar.prototype.terminate = function () {
223223
if (this.clear) {
224-
this.stream.clearLine();
225-
this.stream.cursorTo(0);
224+
if (this.stream.clearLine) {
225+
this.stream.clearLine();
226+
this.stream.cursorTo(0);
227+
}
226228
} else {
227229
this.stream.write('\n');
228230
}

0 commit comments

Comments
 (0)