use codes directly in nested styles array
This commit is contained in:
parent
7d69b22f29
commit
8989561232
1 changed files with 9 additions and 4 deletions
13
index.js
13
index.js
|
|
@ -23,7 +23,8 @@ Object.keys(ansiStyles).forEach(function (key) {
|
||||||
|
|
||||||
styles[key] = {
|
styles[key] = {
|
||||||
get: function () {
|
get: function () {
|
||||||
return build.call(this, this._styles ? this._styles.concat(key) : [key]);
|
var codes = ansiStyles[key];
|
||||||
|
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
@ -31,13 +32,17 @@ Object.keys(ansiStyles).forEach(function (key) {
|
||||||
// eslint-disable-next-line func-names
|
// eslint-disable-next-line func-names
|
||||||
var proto = defineProps(function chalk() {}, styles);
|
var proto = defineProps(function chalk() {}, styles);
|
||||||
|
|
||||||
function build(_styles) {
|
function build(_styles, key) {
|
||||||
var builder = function () {
|
var builder = function () {
|
||||||
return applyStyle.apply(builder, arguments);
|
return applyStyle.apply(builder, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
builder._styles = _styles;
|
builder._styles = _styles;
|
||||||
builder.level = this.level;
|
builder.level = this.level;
|
||||||
|
|
||||||
|
// see below for fix regarding invisible grey/dim combination on windows.
|
||||||
|
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
|
||||||
|
|
||||||
// __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 */
|
||||||
|
|
@ -70,12 +75,12 @@ function applyStyle() {
|
||||||
// see https://github.com/chalk/chalk/issues/58
|
// see https://github.com/chalk/chalk/issues/58
|
||||||
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
|
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
|
||||||
var originalDim = ansiStyles.dim.open;
|
var originalDim = ansiStyles.dim.open;
|
||||||
if (isSimpleWindowsTerm && (nestedStyles.indexOf('gray') !== -1 || nestedStyles.indexOf('grey') !== -1)) {
|
if (isSimpleWindowsTerm && this.hasGrey) {
|
||||||
ansiStyles.dim.open = '';
|
ansiStyles.dim.open = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var code = ansiStyles[nestedStyles[i]];
|
var code = nestedStyles[i];
|
||||||
|
|
||||||
// Replace any instances already present with a re-opening code
|
// Replace any instances already present with a re-opening code
|
||||||
// otherwise only the part of the string until said closing code
|
// otherwise only the part of the string until said closing code
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue