source dump of claude code
at main 37 lines 1.1 kB view raw
1import { 2 ColorDiff, 3 ColorFile, 4 getSyntaxTheme as nativeGetSyntaxTheme, 5 type SyntaxTheme, 6} from 'color-diff-napi' 7import { isEnvDefinedFalsy } from '../../utils/envUtils.js' 8 9export type ColorModuleUnavailableReason = 'env' 10 11/** 12 * Returns a static reason why the color-diff module is unavailable, or null if available. 13 * 'env' = disabled via CLAUDE_CODE_SYNTAX_HIGHLIGHT 14 * 15 * The TS port of color-diff works in all build modes, so the only way to 16 * disable it is via the env var. 17 */ 18export function getColorModuleUnavailableReason(): ColorModuleUnavailableReason | null { 19 if (isEnvDefinedFalsy(process.env.CLAUDE_CODE_SYNTAX_HIGHLIGHT)) { 20 return 'env' 21 } 22 return null 23} 24 25export function expectColorDiff(): typeof ColorDiff | null { 26 return getColorModuleUnavailableReason() === null ? ColorDiff : null 27} 28 29export function expectColorFile(): typeof ColorFile | null { 30 return getColorModuleUnavailableReason() === null ? ColorFile : null 31} 32 33export function getSyntaxTheme(themeName: string): SyntaxTheme | null { 34 return getColorModuleUnavailableReason() === null 35 ? nativeGetSyntaxTheme(themeName) 36 : null 37}