check parent builder object for enabled status (#142)
This commit is contained in:
parent
5a69476142
commit
0d2144904b
2 changed files with 35 additions and 1 deletions
14
index.js
14
index.js
|
|
@ -36,8 +36,20 @@ function build(_styles) {
|
||||||
return applyStyle.apply(builder, arguments);
|
return applyStyle.apply(builder, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
builder._styles = _styles;
|
builder._styles = _styles;
|
||||||
builder.enabled = this.enabled;
|
|
||||||
|
Object.defineProperty(builder, 'enabled', {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () {
|
||||||
|
return self.enabled;
|
||||||
|
},
|
||||||
|
set: function (v) {
|
||||||
|
self.enabled = v;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// __proto__ is used because we must return a function, but there is
|
// __proto__ is used because we must return a function, but there is
|
||||||
// no way to create a function with a different prototype.
|
// no way to create a function with a different prototype.
|
||||||
/* eslint-disable no-proto */
|
/* eslint-disable no-proto */
|
||||||
|
|
|
||||||
22
test.js
22
test.js
|
|
@ -138,6 +138,28 @@ describe('chalk.enabled', function () {
|
||||||
assert.equal(chalk.red('foo'), 'foo');
|
assert.equal(chalk.red('foo'), 'foo');
|
||||||
chalk.enabled = true;
|
chalk.enabled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should enable/disable colors based on overall chalk enabled property, not individual instances', function () {
|
||||||
|
chalk.enabled = true;
|
||||||
|
var red = chalk.red;
|
||||||
|
assert.equal(red.enabled, true);
|
||||||
|
chalk.enabled = false;
|
||||||
|
assert.equal(red.enabled, chalk.enabled);
|
||||||
|
chalk.enabled = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should propagate enable/disable changes from child colors', function () {
|
||||||
|
chalk.enabled = true;
|
||||||
|
var red = chalk.red;
|
||||||
|
assert.equal(red.enabled, true);
|
||||||
|
assert.equal(chalk.enabled, true);
|
||||||
|
red.enabled = false;
|
||||||
|
assert.equal(red.enabled, false);
|
||||||
|
assert.equal(chalk.enabled, false);
|
||||||
|
chalk.enabled = true;
|
||||||
|
assert.equal(red.enabled, true);
|
||||||
|
assert.equal(chalk.enabled, true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('chalk.constructor', function () {
|
describe('chalk.constructor', function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue