logger.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import type { ValueOf } from '@extension/shared';
  2. type ColorType = 'success' | 'info' | 'error' | 'warning' | keyof typeof COLORS;
  3. export function colorLog(message: string, type: ColorType) {
  4. let color: ValueOf<typeof COLORS>;
  5. switch (type) {
  6. case 'success':
  7. color = COLORS.FgGreen;
  8. break;
  9. case 'info':
  10. color = COLORS.FgBlue;
  11. break;
  12. case 'error':
  13. color = COLORS.FgRed;
  14. break;
  15. case 'warning':
  16. color = COLORS.FgYellow;
  17. break;
  18. default:
  19. color = COLORS[type];
  20. break;
  21. }
  22. console.log(color, message);
  23. }
  24. const COLORS = {
  25. Reset: '\x1b[0m',
  26. Bright: '\x1b[1m',
  27. Dim: '\x1b[2m',
  28. Underscore: '\x1b[4m',
  29. Blink: '\x1b[5m',
  30. Reverse: '\x1b[7m',
  31. Hidden: '\x1b[8m',
  32. FgBlack: '\x1b[30m',
  33. FgRed: '\x1b[31m',
  34. FgGreen: '\x1b[32m',
  35. FgYellow: '\x1b[33m',
  36. FgBlue: '\x1b[34m',
  37. FgMagenta: '\x1b[35m',
  38. FgCyan: '\x1b[36m',
  39. FgWhite: '\x1b[37m',
  40. BgBlack: '\x1b[40m',
  41. BgRed: '\x1b[41m',
  42. BgGreen: '\x1b[42m',
  43. BgYellow: '\x1b[43m',
  44. BgBlue: '\x1b[44m',
  45. BgMagenta: '\x1b[45m',
  46. BgCyan: '\x1b[46m',
  47. BgWhite: '\x1b[47m',
  48. } as const;