| 43 | |
| 44 | // 256-color palette |
| 45 | function get256Color(n: number): string { |
| 46 | if (n < 16) { |
| 47 | const fg = FG_COLORS[n + 30] ?? FG_COLORS[n + 82]; // handle 0-7 and 8-15 |
| 48 | if (fg) return fg; |
| 49 | } |
| 50 | if (n < 232) { |
| 51 | // 6×6×6 color cube |
| 52 | const i = n - 16; |
| 53 | const b = i % 6; |
| 54 | const g = Math.floor(i / 6) % 6; |
| 55 | const r = Math.floor(i / 36); |
| 56 | const toHex = (v: number) => |
| 57 | (v === 0 ? 0 : 55 + v * 40).toString(16).padStart(2, "0"); |
| 58 | return `#${toHex(r)}${toHex(g)}${toHex(b)}`; |
| 59 | } |
| 60 | // Grayscale ramp |
| 61 | const gray = (n - 232) * 10 + 8; |
| 62 | const hex = gray.toString(16).padStart(2, "0"); |
| 63 | return `#${hex}${hex}${hex}`; |
| 64 | } |
| 65 | |
| 66 | interface AnsiStyle { |
| 67 | color?: string; |