Skip to content

Commit e7a3288

Browse files
committed
Add support for chalk.rgb and chalk.bgRgb
1 parent 99ec49e commit e7a3288

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
module.exports = ansiHTML
44

5+
var _rgbANSI = /\[38;2;([^;]+);([^;]+);([^m]+)m(.*?)\[39m/g;
6+
var _bgRgbANSI = /\[48;2;([^;]+);([^;]+);([^m]+)m(.*?)\[49m/g;
7+
58
// Reference to https://github.com/sindresorhus/ansi-regex
69
var _regANSI = /(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/
710

@@ -51,6 +54,16 @@ var _closeTags = {
5154
* @returns {*}
5255
*/
5356
function ansiHTML (text) {
57+
if (_rgbANSI.test(text)) {
58+
return ansiHTML(text.replace(_rgbANSI, function (match, r, g, b, txt) {
59+
return `<span style="color: rgb(${r},${g},${b})">${txt}</span>`;
60+
}));
61+
}
62+
if (_bgRgbANSI.test(text)) {
63+
return ansiHTML(text.replace(_bgRgbANSI, function (match, r, g, b, txt) {
64+
return `<span style="background-color: rgb(${r},${g},${b})">${txt}</span>`;
65+
}));
66+
}
5467
// Returns the text if the string has no ANSI escape code.
5568
if (!_regANSI.test(text)) {
5669
return text

0 commit comments

Comments
 (0)