source dump of claude code
at main 30 lines 853 B view raw
1import { type ColorType, colorize } from '../../ink/colorize.js' 2import type { Color } from '../../ink/styles.js' 3import { getTheme, type Theme, type ThemeName } from '../../utils/theme.js' 4 5/** 6 * Curried theme-aware color function. Resolves theme keys to raw color 7 * values before delegating to the ink renderer's colorize. 8 */ 9export function color( 10 c: keyof Theme | Color | undefined, 11 theme: ThemeName, 12 type: ColorType = 'foreground', 13): (text: string) => string { 14 return text => { 15 if (!c) { 16 return text 17 } 18 // Raw color values bypass theme lookup 19 if ( 20 c.startsWith('rgb(') || 21 c.startsWith('#') || 22 c.startsWith('ansi256(') || 23 c.startsWith('ansi:') 24 ) { 25 return colorize(text, c, type) 26 } 27 // Theme key lookup 28 return colorize(text, getTheme(theme)[c as keyof Theme], type) 29 } 30}