MCPcopy Index your code
hub / github.com/codeaashu/claude-code / get256Color

Function get256Color

web/components/tools/AnsiRenderer.tsx:45–64  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

43
44// 256-color palette
45function 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
66interface AnsiStyle {
67 color?: string;

Callers 1

parseAnsiFunction · 0.70

Calls 2

toHexFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected