Skip to content

Commit

Permalink
fix .visible when called after .enable is set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Oct 24, 2017
1 parent ede3103 commit e2a4aa4
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions index.js
Expand Up @@ -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');
}
};

Expand All @@ -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);
};
}
};
Expand All @@ -109,21 +108,21 @@ 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);
};
}
};
}

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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e2a4aa4

Please sign in to comment.