-
Notifications
You must be signed in to change notification settings - Fork 0
/
palette.ts
42 lines (37 loc) · 1.37 KB
/
palette.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint-disable import/no-mutable-exports */
import type * as Styles from 'ansi-styles';
import type * as Support from 'supports-color';
const noFormat = (str: string): string => str;
let blue = noFormat;
let bold = noFormat;
let cyan = noFormat;
let dim = noFormat;
let green = noFormat;
let magenta = noFormat;
let red = noFormat;
let underline = noFormat;
let yellow = noFormat;
function stylize(modifier: { open: string; close: string }) {
return (str: string) => `${modifier.open}${str}${modifier.close}`;
}
try {
// eslint-disable-next-line global-require
const styles: typeof Styles = require('ansi-styles');
// eslint-disable-next-line global-require
const { stdout, stderr }: typeof Support = require('supports-color');
const isSupported = stdout && stdout.has256 && stderr && stderr.has256 && !process.env.AWS_LAMBDA_LOG_GROUP_NAME;
if (isSupported) {
blue = stylize(styles.blue);
bold = stylize(styles.bold);
cyan = stylize(styles.cyan);
dim = stylize(styles.dim);
green = stylize(styles.green);
magenta = stylize(styles.magenta);
red = stylize(styles.red);
underline = stylize(styles.underline);
yellow = stylize(styles.yellow);
}
} catch {
// Coloring packages not available at this environment
}
export { blue, bold, cyan, dim, green, magenta, red, underline, yellow };