export const COLORS = {
  reset: '\x1b[0m',
  bold: '\x1b[1m',
  dim: '\x1b[2m',
  red: '\x1b[31m',
  green: '\x1b[32m',
  yellow: '\x1b[33m',
  blue: '\x1b[34m',
  cyan: '\x1b[36m',
  gray: '\x1b[90m',
} as const;

function colorsEnabled(): boolean {
  if (process.env['NO_COLOR'] !== undefined) return false;
  const fc = process.env['FORCE_COLOR'];
  if (fc !== undefined) return fc !== '0' && fc.toLowerCase() !== 'false';
  return process.stdout?.isTTY === true;
}

export const c = (color: keyof typeof COLORS, s: string): string =>
  colorsEnabled() ? COLORS[color] + s + COLORS.reset : s;
