Permalink
Browse files

fix bug that caused error on multiple calls to `program.colorize`

using a boolean check in addition to setting the color option as configurable getter
  • Loading branch information...
1 parent 0ad71b4 commit ac211efd27ee6986860d89fdd83e60f3f6a9ec63 @logicalparadox committed Jun 11, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/electron/program.js
View
9 lib/electron/program.js
@@ -69,6 +69,7 @@ function Program (base, opts) {
Drip.call(this, { delimeter: ' ' });
this.commands = [];
+ this._colorized = false;
this.opts = defaults(opts || {}, {
useColors: istty
, version: null
@@ -415,6 +416,7 @@ Program.prototype.theme = function (name, spec) {
* Just in case, if the current program is not running as a TTY,
* no string changes will be made.
*
+ * program.colorize();
* console.log('hello universe'.green);
*
* ##### Colors
@@ -432,6 +434,7 @@ Program.prototype.theme = function (name, spec) {
*/
Program.prototype.colorize = function (noColors) {
+ if (this._colorized) return this;
var self = this
, colors = {
'red': 31
@@ -449,9 +452,13 @@ Program.prototype.colorize = function (noColors) {
{ get: function () {
if (noColors || !self.opts.useColors) return this;
return '\033[' + colors[color] + 'm' + this + '\033[0m';
- }
+ }
+ , configurable: true
});
});
+
+ this._colorized = true;
+ return this;
};
/*!

0 comments on commit ac211ef

Please sign in to comment.