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

Function get256Color

src/utils/ansiToSvg.ts:150–190  ·  view source on GitHub ↗

* Get color from 256-color palette

(index: number)

Source from the content-addressed store, hash-verified

148 * Get color from 256-color palette
149 */
150function get256Color(index: number): AnsiColor {
151 // Standard colors (0-15)
152 if (index < 16) {
153 const standardColors: AnsiColor[] = [
154 { r: 0, g: 0, b: 0 }, // 0 black
155 { r: 128, g: 0, b: 0 }, // 1 red
156 { r: 0, g: 128, b: 0 }, // 2 green
157 { r: 128, g: 128, b: 0 }, // 3 yellow
158 { r: 0, g: 0, b: 128 }, // 4 blue
159 { r: 128, g: 0, b: 128 }, // 5 magenta
160 { r: 0, g: 128, b: 128 }, // 6 cyan
161 { r: 192, g: 192, b: 192 }, // 7 white
162 { r: 128, g: 128, b: 128 }, // 8 bright black
163 { r: 255, g: 0, b: 0 }, // 9 bright red
164 { r: 0, g: 255, b: 0 }, // 10 bright green
165 { r: 255, g: 255, b: 0 }, // 11 bright yellow
166 { r: 0, g: 0, b: 255 }, // 12 bright blue
167 { r: 255, g: 0, b: 255 }, // 13 bright magenta
168 { r: 0, g: 255, b: 255 }, // 14 bright cyan
169 { r: 255, g: 255, b: 255 }, // 15 bright white
170 ]
171 return standardColors[index] || DEFAULT_FG
172 }
173
174 // 216 color cube (16-231)
175 if (index < 232) {
176 const i = index - 16
177 const r = Math.floor(i / 36)
178 const g = Math.floor((i % 36) / 6)
179 const b = i % 6
180 return {
181 r: r === 0 ? 0 : 55 + r * 40,
182 g: g === 0 ? 0 : 55 + g * 40,
183 b: b === 0 ? 0 : 55 + b * 40,
184 }
185 }
186
187 // Grayscale (232-255)
188 const gray = (index - 232) * 10 + 8
189 return { r: gray, g: gray, b: gray }
190}
191
192export type AnsiToSvgOptions = {
193 fontFamily?: string

Callers 1

parseAnsiFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected