1 | let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
|
2 | if (typeof process !== 'undefined') {
|
3 | ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
4 | isTTY = process.stdout && process.stdout.isTTY;
|
5 | }
|
6 |
|
7 | const $ = exports.$ = {
|
8 | enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
|
9 | FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
|
10 | )
|
11 | }
|
12 |
|
13 | function init(x, y) {
|
14 | let rgx = new RegExp(`\\x1b\\[${y}m`, 'g');
|
15 | let open = `\x1b[${x}m`, close = `\x1b[${y}m`;
|
16 |
|
17 | return function (txt) {
|
18 | if (!$.enabled || txt == null) return txt;
|
19 | return open + (!!~(''+txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
20 | };
|
21 | }
|
22 |
|
23 |
|
24 | exports.reset = init(0, 0);
|
25 | exports.bold = init(1, 22);
|
26 | exports.dim = init(2, 22);
|
27 | exports.italic = init(3, 23);
|
28 | exports.underline = init(4, 24);
|
29 | exports.inverse = init(7, 27);
|
30 | exports.hidden = init(8, 28);
|
31 | exports.strikethrough = init(9, 29);
|
32 |
|
33 |
|
34 | exports.black = init(30, 39);
|
35 | exports.red = init(31, 39);
|
36 | exports.green = init(32, 39);
|
37 | exports.yellow = init(33, 39);
|
38 | exports.blue = init(34, 39);
|
39 | exports.magenta = init(35, 39);
|
40 | exports.cyan = init(36, 39);
|
41 | exports.white = init(37, 39);
|
42 | exports.gray = init(90, 39);
|
43 | exports.grey = init(90, 39);
|
44 |
|
45 |
|
46 | exports.bgBlack = init(40, 49);
|
47 | exports.bgRed = init(41, 49);
|
48 | exports.bgGreen = init(42, 49);
|
49 | exports.bgYellow = init(43, 49);
|
50 | exports.bgBlue = init(44, 49);
|
51 | exports.bgMagenta = init(45, 49);
|
52 | exports.bgCyan = init(46, 49);
|
53 | exports.bgWhite = init(47, 49);
|