color.ts
 1  import { type ColorType, colorize } from '../../ink/colorize.js'
 2  import type { Color } from '../../ink/styles.js'
 3  import { 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   */
 9  export 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  }