MCPcopy
hub / github.com/anomalyco/opencode / ansiToRgba

Function ansiToRgba

packages/opencode/src/cli/cmd/run/theme.ts:127–165  ·  view source on GitHub ↗
(code: number)

Source from the content-addressed store, hash-verified

125}
126
127function ansiToRgba(code: number): RGBA {
128 if (code < 16) {
129 const ansi = [
130 "#000000",
131 "#800000",
132 "#008000",
133 "#808000",
134 "#000080",
135 "#800080",
136 "#008080",
137 "#c0c0c0",
138 "#808080",
139 "#ff0000",
140 "#00ff00",
141 "#ffff00",
142 "#0000ff",
143 "#ff00ff",
144 "#00ffff",
145 "#ffffff",
146 ]
147 return RGBA.fromHex(ansi[code] ?? "#000000")
148 }
149
150 if (code < 232) {
151 const index = code - 16
152 const b = index % 6
153 const g = Math.floor(index / 6) % 6
154 const r = Math.floor(index / 36)
155 const value = (x: number) => (x === 0 ? 0 : x * 40 + 55)
156 return RGBA.fromInts(value(r), value(g), value(b))
157 }
158
159 if (code < 256) {
160 const gray = (code - 232) * 10 + 8
161 return RGBA.fromInts(gray, gray, gray)
162 }
163
164 return RGBA.fromInts(0, 0, 0)
165}
166
167function tint(base: RGBA, overlay: RGBA, value: number): RGBA {
168 return RGBA.fromInts(

Callers 3

indexedPaletteFunction · 0.70
paletteColorFunction · 0.70
resolveColorFunction · 0.70

Calls 1

valueFunction · 0.70

Tested by

no test coverage detected