Skip to content

Commit 330b250

Browse files
committed
Add interruptBegin and interruptEnd methods
This allows one to employ custom logging facilities during an interrupt, like for example when one wants to log both to a file and to lines above the bar.
1 parent 30d70d9 commit 330b250

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ var timer = setInterval(function () {
139139
}, 1000);
140140
```
141141

142+
It's also possible to start and stop interrupts manually, allowing synchronous
143+
logging between through the `interruptBegin` and `interruptEnd` methods:
144+
145+
```js
146+
bar.interruptBegin();
147+
console.log('message');
148+
bar.interruptEnd();
149+
```
150+
142151
You can see more examples in the `examples` folder.
143152

144153
## License

lib/node-progress.js

+21
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ ProgressBar.prototype.interrupt = function (message) {
215215
this.stream.write(this.lastDraw);
216216
};
217217

218+
/**
219+
* Begin a interrupt so the user can manually write messages above the bar.
220+
*
221+
* @api public
222+
*/
223+
224+
ProgressBar.prototype.interruptBegin = function () {
225+
this.stream.clearLine();
226+
this.stream.cursorTo(0);
227+
};
228+
229+
/**
230+
* End a interrupt, rendering the last draw again.
231+
*
232+
* @api public
233+
*/
234+
235+
ProgressBar.prototype.interruptEnd = function () {
236+
this.stream.write(this.lastDraw);
237+
};
238+
218239
/**
219240
* Terminates a progress bar.
220241
*

0 commit comments

Comments
 (0)