Skip to content

Commit

Permalink
Add interruptBegin and interruptEnd methods
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
silverwind committed Jun 22, 2017
1 parent 30d70d9 commit 3c5a944
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("hello");
bar.interruptEnd();
```

You can see more examples in the `examples` folder.

## License
Expand Down
21 changes: 21 additions & 0 deletions lib/node-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 3c5a944

Please sign in to comment.