color.ts
components/design-system/color.ts
31
Lines
853
Bytes
1
Exports
3
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with ui-flow. It contains 31 lines, 3 detected imports, and 1 detected exports.
Important relationships
- components/design-system/Byline.tsx
- components/design-system/Dialog.tsx
- components/design-system/Divider.tsx
- components/design-system/FuzzyPicker.tsx
- components/design-system/KeyboardShortcutHint.tsx
- components/design-system/ListItem.tsx
- components/design-system/LoadingState.tsx
- components/design-system/Pane.tsx
- commands/color/color.ts
Detected exports
color
Keywords
themecolorcolorizetextstartswithcolortypegetthemethemenamevalueskeyof
Detected imports
../../ink/colorize.js../../ink/styles.js../../utils/theme.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import { type ColorType, colorize } from '../../ink/colorize.js'
import type { Color } from '../../ink/styles.js'
import { getTheme, type Theme, type ThemeName } from '../../utils/theme.js'
/**
* Curried theme-aware color function. Resolves theme keys to raw color
* values before delegating to the ink renderer's colorize.
*/
export function color(
c: keyof Theme | Color | undefined,
theme: ThemeName,
type: ColorType = 'foreground',
): (text: string) => string {
return text => {
if (!c) {
return text
}
// Raw color values bypass theme lookup
if (
c.startsWith('rgb(') ||
c.startsWith('#') ||
c.startsWith('ansi256(') ||
c.startsWith('ansi:')
) {
return colorize(text, c, type)
}
// Theme key lookup
return colorize(text, getTheme(theme)[c as keyof Theme], type)
}
}