diff --git a/Readme.md b/Readme.md index 6d4271a..a73c2f4 100644 --- a/Readme.md +++ b/Readme.md @@ -139,6 +139,15 @@ var timer = setInterval(function () { }, 1000); ``` +It's also possible to start and stop interrupts manually, allowing synchronous +logging between through the `interruptBegin` and `interruptEnd` methods: + +```js +bar.interruptBegin(); +console.log('message'); +bar.interruptEnd(); +``` + You can see more examples in the `examples` folder. ## License diff --git a/lib/node-progress.js b/lib/node-progress.js index 2b62641..d0cd76c 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -215,6 +215,27 @@ ProgressBar.prototype.interrupt = function (message) { this.stream.write(this.lastDraw); }; +/** + * Begin a interrupt so the user can manually write messages above the bar. + * + * @api public + */ + +ProgressBar.prototype.interruptBegin = function () { + this.stream.clearLine(); + this.stream.cursorTo(0); +}; + +/** + * End a interrupt, rendering the last draw again. + * + * @api public + */ + +ProgressBar.prototype.interruptEnd = function () { + this.stream.write(this.lastDraw); +}; + /** * Terminates a progress bar. *