Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force tty #168

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ These are keys in the options object you can pass to the progress bar along with
- `incomplete` incomplete character defaulting to "-"
- `renderThrottle` minimum time between updates in milliseconds defaulting to 16
- `clear` option to clear the bar on completion defaulting to false
- `forceTTY` optional boolean (true|false) to force stderr to be TTY. This allows the bar output to be redirected or use tee.
- `callback` optional function to call when the progress bar completes

### Tokens
Expand Down
10 changes: 10 additions & 0 deletions lib/node-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exports = module.exports = ProgressBar;
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
* - `callback` optional function to call when the progress bar completes
* - `clear` will clear the progress bar upon termination
* - `forceTTY` - optional boolean (true|false) to force stderr to be TTY. This
* allows the bar output to be redirected or use tee.
*
* Tokens:
*
Expand All @@ -45,6 +47,14 @@ exports = module.exports = ProgressBar;
function ProgressBar(fmt, options) {
this.stream = options.stream || process.stderr;

if (options.forceTTY === true) { // only works for stderr
var tty = require('tty').WriteStream.prototype;
Object.getOwnPropertyNames(tty).forEach(function (key) {
process.stderr[key] = tty[key];
});
process.stderr.columns = 80; // columns
}

if (typeof(options) == 'number') {
var total = options;
options = {};
Expand Down