|
1 | | -import chalk from 'chalk'; |
| 1 | +export const COLORS = { |
| 2 | + magenta: '\x1b[35m', |
| 3 | + cyan: '\x1b[36m', |
| 4 | + yellow: '\x1b[33m', |
| 5 | + green: '\x1b[32m', |
| 6 | + red: '\x1b[31m', |
| 7 | + blue: '\x1b[34m', |
| 8 | + gray: '\x1b[90m', |
| 9 | + reset: '\x1b[0m', |
| 10 | +} as const; |
2 | 11 |
|
3 | | -// ---------------------------------------------------------------------- |
| 12 | +type ColorName = Exclude<keyof typeof COLORS, 'reset'>; |
| 13 | + |
| 14 | +const colorize = (color: ColorName, message: string): string => { |
| 15 | + return `${COLORS[color]}${message}${COLORS.reset}`; |
| 16 | +}; |
| 17 | + |
| 18 | +export const colorLogger: Record<ColorName, (message: string) => string> = { |
| 19 | + magenta: (msg) => colorize('magenta', msg), |
| 20 | + cyan: (msg) => colorize('cyan', msg), |
| 21 | + yellow: (msg) => colorize('yellow', msg), |
| 22 | + green: (msg) => colorize('green', msg), |
| 23 | + red: (msg) => colorize('red', msg), |
| 24 | + blue: (msg) => colorize('blue', msg), |
| 25 | + gray: (msg) => colorize('gray', msg), |
| 26 | +}; |
4 | 27 |
|
5 | 28 | export const highlightText = { |
6 | | - val: (text: string) => `${chalk.yellowBright(text)}`, |
7 | | - fn: (text: string) => `${chalk.magenta(text)}`, |
| 29 | + val: (msg: string) => colorize('yellow', msg), |
| 30 | + fn: (msg: string) => colorize('magenta', msg), |
8 | 31 | }; |
0 commit comments