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 | export const $ = {
|
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 | export const reset = init(0, 0);
|
25 | export const bold = init(1, 22);
|
26 | export const dim = init(2, 22);
|
27 | export const italic = init(3, 23);
|
28 | export const underline = init(4, 24);
|
29 | export const inverse = init(7, 27);
|
30 | export const hidden = init(8, 28);
|
31 | export const strikethrough = init(9, 29);
|
32 |
|
33 |
|
34 | export const black = init(30, 39);
|
35 | export const red = init(31, 39);
|
36 | export const green = init(32, 39);
|
37 | export const yellow = init(33, 39);
|
38 | export const blue = init(34, 39);
|
39 | export const magenta = init(35, 39);
|
40 | export const cyan = init(36, 39);
|
41 | export const white = init(37, 39);
|
42 | export const gray = init(90, 39);
|
43 | export const grey = init(90, 39);
|
44 |
|
45 |
|
46 | export const bgBlack = init(40, 49);
|
47 | export const bgRed = init(41, 49);
|
48 | export const bgGreen = init(42, 49);
|
49 | export const bgYellow = init(43, 49);
|
50 | export const bgBlue = init(44, 49);
|
51 | export const bgMagenta = init(45, 49);
|
52 | export const bgCyan = init(46, 49);
|
53 | export const bgWhite = init(47, 49);
|