|
| 1 | +const codes = { |
| 2 | + blue: '\x1b[34m', |
| 3 | + bold: '\x1b[1m', |
| 4 | + cyan: '\x1b[36m', |
| 5 | + dim: '\x1b[2m', |
| 6 | + green: '\x1b[32m', |
| 7 | + magenta: '\x1b[35m', |
| 8 | + red: '\x1b[31m', |
| 9 | + reset: '\x1b[0m', |
| 10 | + underline: '\x1b[4m', |
| 11 | + white: '\x1b[37m', |
| 12 | + yellow: '\x1b[33m', |
| 13 | +} |
| 14 | + |
| 15 | +function colorize(str: string, ...styles: (keyof typeof codes)[]) { |
| 16 | + const start = styles.map((s) => codes[s] || '').join('') |
| 17 | + return `${start}${str}${codes.reset}` |
| 18 | +} |
| 19 | + |
| 20 | +export const miniChalk = { |
| 21 | + blue: (str: string) => colorize(str, 'blue'), |
| 22 | + bold: (str: string) => colorize(str, 'bold'), |
| 23 | + cyan: (str: string) => colorize(str, 'cyan'), |
| 24 | + dim: (str: string) => colorize(str, 'dim'), |
| 25 | + green: (str: string) => colorize(str, 'green'), |
| 26 | + magenta: (str: string) => colorize(str, 'magenta'), |
| 27 | + red: (str: string) => colorize(str, 'red'), |
| 28 | + underline: (str: string) => colorize(str, 'underline'), |
| 29 | + white: (str: string) => colorize(str, 'white'), |
| 30 | + yellow: (str: string) => colorize(str, 'yellow'), |
| 31 | + |
| 32 | + // combos |
| 33 | + redBold: (str: string) => colorize(str, 'red', 'bold'), |
| 34 | + yellowBold: (str: string) => colorize(str, 'yellow', 'bold'), |
| 35 | +} |
0 commit comments