From 1da9bf3ead1e840b28a685b9c07dd97e3e9260d2 Mon Sep 17 00:00:00 2001 From: Ryan Frankel Date: Fri, 8 Dec 2017 18:07:55 -0500 Subject: [PATCH 1/5] Added code from issue #110 to create an option option.forceTTY that will force TTY so that the progress bar can be used with tee and or redirected to an output file. --- lib/node-progress.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/node-progress.js b/lib/node-progress.js index 2b62641..fb3bc32 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -45,6 +45,14 @@ exports = module.exports = ProgressBar; function ProgressBar(fmt, options) { this.stream = options.stream || process.stderr; + if (options.forceTTY === true) { + var tty = require('tty').WriteStream.prototype; + Object.getOwnPropertyNames(tty).forEach(function (key) { + this.stream[key] = tty[key]; + }); // forEach + this.stream.columns = 80; // columns + } // if + if (typeof(options) == 'number') { var total = options; options = {}; From e13de7c7bcc95bfd2d62c2a4f9da9d2618c5af66 Mon Sep 17 00:00:00 2001 From: Ryan Frankel Date: Fri, 8 Dec 2017 18:16:25 -0500 Subject: [PATCH 2/5] Updated README to include the forceTTY option. --- Readme.md | 1 + lib/node-progress.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 6d4271a..2fcb078 100644 --- a/Readme.md +++ b/Readme.md @@ -40,6 +40,7 @@ These are keys in the options object you can pass to the progress bar along with - `renderThrottle` minimum time between updates in milliseconds defaulting to 16 - `clear` option to clear the bar on completion defaulting to false - `callback` optional function to call when the progress bar completes +- `forceTTY` optional boolena (true|false) to force stderr to be TTY. This allows the bar output to be redirected or use tee. ### Tokens diff --git a/lib/node-progress.js b/lib/node-progress.js index fb3bc32..e4ff6d5 100644 --- a/lib/node-progress.js +++ b/lib/node-progress.js @@ -45,12 +45,12 @@ exports = module.exports = ProgressBar; function ProgressBar(fmt, options) { this.stream = options.stream || process.stderr; - if (options.forceTTY === true) { + if (options.forceTTY === true) { // only works for stderr var tty = require('tty').WriteStream.prototype; Object.getOwnPropertyNames(tty).forEach(function (key) { - this.stream[key] = tty[key]; + process.stderr[key] = tty[key]; }); // forEach - this.stream.columns = 80; // columns + process.stderr.columns = 80; // columns } // if if (typeof(options) == 'number') { From 447b2cea59adff09a0e1ab7816073659094b840e Mon Sep 17 00:00:00 2001 From: ryan-frankel Date: Fri, 8 Dec 2017 18:17:36 -0500 Subject: [PATCH 3/5] Fixed typo. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 2fcb078..9802a3a 100644 --- a/Readme.md +++ b/Readme.md @@ -40,7 +40,7 @@ These are keys in the options object you can pass to the progress bar along with - `renderThrottle` minimum time between updates in milliseconds defaulting to 16 - `clear` option to clear the bar on completion defaulting to false - `callback` optional function to call when the progress bar completes -- `forceTTY` optional boolena (true|false) to force stderr to be TTY. This allows the bar output to be redirected or use tee. +- `forceTTY` optional boolean (true|false) to force stderr to be TTY. This allows the bar output to be redirected or use tee. ### Tokens From fbbf498ea6a0894461c451148f8885e5094a5064 Mon Sep 17 00:00:00 2001 From: ryan-frankel Date: Mon, 11 Dec 2017 10:08:29 -0500 Subject: [PATCH 4/5] Updated comment styles to be more like this repo. --- lib/node-progress.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node-progress.js b/lib/node-progress.js index e4ff6d5..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: * @@ -49,9 +51,9 @@ function ProgressBar(fmt, options) { var tty = require('tty').WriteStream.prototype; Object.getOwnPropertyNames(tty).forEach(function (key) { process.stderr[key] = tty[key]; - }); // forEach + }); process.stderr.columns = 80; // columns - } // if + } if (typeof(options) == 'number') { var total = options; From 2cda85b24ea2e239fd8f4b036492c30daee55acf Mon Sep 17 00:00:00 2001 From: ryan-frankel Date: Mon, 11 Dec 2017 14:22:13 -0500 Subject: [PATCH 5/5] Moved callback to the last "option" available. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9802a3a..4c72aa2 100644 --- a/Readme.md +++ b/Readme.md @@ -39,8 +39,8 @@ 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 -- `callback` optional function to call when the progress bar completes - `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