diff --git a/Readme.md b/Readme.md index 6d4271a..4c72aa2 100644 --- a/Readme.md +++ b/Readme.md @@ -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 diff --git a/lib/node-progress.js b/lib/node-progress.js index 2b62641..3397bec 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -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: * @@ -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 = {};