Skip to content

Commit

Permalink
Added support for colored interpolation. Fixes #20 & fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Jun 9, 2018
1 parent a098b3c commit c4601e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"options": {
"default": {
"coloredInterpolation": false,
"displayScope": true,
"displayBadge": true,
"displayDate": false,
Expand Down
26 changes: 22 additions & 4 deletions signale.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ class Signale {
return `[${this.timestamp}]`;
}

_formatMessage(str, type) {
str = arrayify(str);

if (this._config.coloredInterpolation) {
const _ = Object.assign({}, util.inspect.styles);

Object.keys(util.inspect.styles).forEach(x => {
util.inspect.styles[x] = type.color || _[x];
});

str = util.formatWithOptions({colors: true}, ...str);
util.inspect.styles = Object.assign({}, _);
return str;
}

return util.format(...str);
}

_meta() {
const meta = [];
if (this._config.displayDate) {
Expand All @@ -138,8 +156,8 @@ class Signale {
return meta;
}

_hasAdditional({suffix, prefix}, args) {
return (suffix || prefix) ? '' : util.format(...args);
_hasAdditional({suffix, prefix}, args, type) {
return (suffix || prefix) ? '' : this._formatMessage(args, type);
}

_buildSignale(type, ...args) {
Expand All @@ -151,10 +169,10 @@ class Signale {
} else {
const [{prefix, message, suffix}] = args;
additional = Object.assign({}, {suffix, prefix});
msg = message ? util.format(...message) : this._hasAdditional(additional, args);
msg = message ? this._formatMessage(message, type) : this._hasAdditional(additional, args, type);
}
} else {
msg = util.format(...args);
msg = this._formatMessage(args, type);
}

const signale = this._meta();
Expand Down

0 comments on commit c4601e6

Please sign in to comment.