2 const colorConvert = require('color-convert');
4 const wrapAnsi16 = (fn, offset) => function () {
5 const code = fn.apply(colorConvert, arguments);
6 return `\u001B[${code + offset}m`;
9 const wrapAnsi256 = (fn, offset) => function () {
10 const code = fn.apply(colorConvert, arguments);
11 return `\u001B[${38 + offset};5;${code}m`;
14 const wrapAnsi16m = (fn, offset) => function () {
15 const rgb = fn.apply(colorConvert, arguments);
16 return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
19 function assembleStyles() {
20 const codes = new Map();
24 // 21 isn't widely supported and 22 does the same thing
31 strikethrough: [9, 29]
46 greenBright: [92, 39],
47 yellowBright: [93, 39],
49 magentaBright: [95, 39],
64 bgBlackBright: [100, 49],
65 bgRedBright: [101, 49],
66 bgGreenBright: [102, 49],
67 bgYellowBright: [103, 49],
68 bgBlueBright: [104, 49],
69 bgMagentaBright: [105, 49],
70 bgCyanBright: [106, 49],
71 bgWhiteBright: [107, 49]
76 styles.color.grey = styles.color.gray;
78 for (const groupName of Object.keys(styles)) {
79 const group = styles[groupName];
81 for (const styleName of Object.keys(group)) {
82 const style = group[styleName];
85 open: `\u001B[${style[0]}m`,
86 close: `\u001B[${style[1]}m`
89 group[styleName] = styles[styleName];
91 codes.set(style[0], style[1]);
94 Object.defineProperty(styles, groupName, {
99 Object.defineProperty(styles, 'codes', {
105 const ansi2ansi = n => n;
106 const rgb2rgb = (r, g, b) => [r, g, b];
108 styles.color.close = '\u001B[39m';
109 styles.bgColor.close = '\u001B[49m';
111 styles.color.ansi = {
112 ansi: wrapAnsi16(ansi2ansi, 0)
114 styles.color.ansi256 = {
115 ansi256: wrapAnsi256(ansi2ansi, 0)
117 styles.color.ansi16m = {
118 rgb: wrapAnsi16m(rgb2rgb, 0)
121 styles.bgColor.ansi = {
122 ansi: wrapAnsi16(ansi2ansi, 10)
124 styles.bgColor.ansi256 = {
125 ansi256: wrapAnsi256(ansi2ansi, 10)
127 styles.bgColor.ansi16m = {
128 rgb: wrapAnsi16m(rgb2rgb, 10)
131 for (let key of Object.keys(colorConvert)) {
132 if (typeof colorConvert[key] !== 'object') {
136 const suite = colorConvert[key];
138 if (key === 'ansi16') {
142 if ('ansi16' in suite) {
143 styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
144 styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
147 if ('ansi256' in suite) {
148 styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
149 styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
152 if ('rgb' in suite) {
153 styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
154 styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
161 // Make the export immutable
162 Object.defineProperty(module, 'exports', {