MCPcopy Create free account
hub / github.com/freecodexyz/free-code / themeColorToAnsi

Function themeColorToAnsi

src/utils/theme.ts:633–646  ·  view source on GitHub ↗
(themeColor: string)

Source from the content-addressed store, hash-verified

631 * Uses chalk to generate the escape codes, with 256-color mode for Apple Terminal.
632 */
633export function themeColorToAnsi(themeColor: string): string {
634 const rgbMatch = themeColor.match(/rgb\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)/)
635 if (rgbMatch) {
636 const r = parseInt(rgbMatch[1]!, 10)
637 const g = parseInt(rgbMatch[2]!, 10)
638 const b = parseInt(rgbMatch[3]!, 10)
639 // Use chalk.rgb which auto-converts to 256 colors when level is 2
640 // Extract just the opening escape sequence by using a marker
641 const colored = chalkForChart.rgb(r, g, b)('X')
642 return colored.slice(0, colored.indexOf('X'))
643 }
644 // Fallback to magenta if parsing fails
645 return '\x1b[35m'
646}

Callers 1

generateTokenChartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected