fix .visible when called after .enable is set to false

This commit is contained in:
Josh Junon 2017-10-23 20:12:34 -07:00
parent ede310303b
commit e2a4aa4275

View file

@ -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,