colorDiff.ts
components/StructuredDiff/colorDiff.ts
38
Lines
1137
Bytes
5
Exports
2
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 38 lines, 2 detected imports, and 5 detected exports.
Important relationships
Detected exports
ColorModuleUnavailableReasongetColorModuleUnavailableReasonexpectColorDiffexpectColorFilegetSyntaxTheme
Keywords
getcolormoduleunavailablereasoncolordiffcolorfilegetsyntaxthemenativegetsyntaxthemesyntaxthemeisenvdefinedfalsycolormoduleunavailablereasoncolor-diffclaude_code_syntax_highlight
Detected imports
color-diff-napi../../utils/envUtils.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 {
ColorDiff,
ColorFile,
getSyntaxTheme as nativeGetSyntaxTheme,
type SyntaxTheme,
} from 'color-diff-napi'
import { isEnvDefinedFalsy } from '../../utils/envUtils.js'
export type ColorModuleUnavailableReason = 'env'
/**
* Returns a static reason why the color-diff module is unavailable, or null if available.
* 'env' = disabled via CLAUDE_CODE_SYNTAX_HIGHLIGHT
*
* The TS port of color-diff works in all build modes, so the only way to
* disable it is via the env var.
*/
export function getColorModuleUnavailableReason(): ColorModuleUnavailableReason | null {
if (isEnvDefinedFalsy(process.env.CLAUDE_CODE_SYNTAX_HIGHLIGHT)) {
return 'env'
}
return null
}
export function expectColorDiff(): typeof ColorDiff | null {
return getColorModuleUnavailableReason() === null ? ColorDiff : null
}
export function expectColorFile(): typeof ColorFile | null {
return getColorModuleUnavailableReason() === null ? ColorFile : null
}
export function getSyntaxTheme(themeName: string): SyntaxTheme | null {
return getColorModuleUnavailableReason() === null
? nativeGetSyntaxTheme(themeName)
: null
}