From e2a4aa427568ff1c5d649739c4d1f8319cf0d072 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 23 Oct 2017 20:12:34 -0700 Subject: [PATCH] fix .visible when called after .enable is set to false --- index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 861908c..05e62b3 100644 --- a/index.js +++ b/index.js @@ -58,15 +58,14 @@ for (const key of Object.keys(ansiStyles)) { styles[key] = { get() { const codes = ansiStyles[key]; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key); + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key); } }; } styles.visible = { get() { - this._emptyIfNotVisible = true; - return build.call(this, this._styles ? this._styles : [], 'visible'); + return build.call(this, this._styles || [], true, 'visible'); } }; @@ -86,7 +85,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) { close: ansiStyles.color.close, closeRe: ansiStyles.color.closeRe }; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model); + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); }; } }; @@ -109,7 +108,7 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) { close: ansiStyles.bgColor.close, closeRe: ansiStyles.bgColor.closeRe }; - return build.call(this, this._styles ? this._styles.concat(codes) : [codes], model); + return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); }; } }; @@ -117,13 +116,13 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) { const proto = Object.defineProperties(() => {}, styles); -function build(_styles, key) { +function build(_styles, _empty, key) { const builder = function () { return applyStyle.apply(builder, arguments); }; builder._styles = _styles; - builder._emptyIfNotVisible = this._emptyIfNotVisible; + builder._empty = _empty; const self = this; @@ -175,7 +174,7 @@ function applyStyle() { } if (!this.enabled || this.level <= 0 || !str) { - return this._emptyIfNotVisible ? '' : str; + return this._empty ? '' : str; } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,