MCPcopy Create free account
hub / github.com/IIIIQIIII/claude-code / render

Method render

src/native-ts/color-diff/index.ts:862–934  ·  view source on GitHub ↗
(themeName: string, width: number, dim: boolean)

Source from the content-addressed store, hash-verified

860 }
861
862 render(themeName: string, width: number, dim: boolean): string[] | null {
863 const mode = detectColorMode(themeName)
864 const theme = buildTheme(themeName, mode)
865 const lang = detectLanguage(this.filePath, this.firstLine)
866 const hlState = { lang, stack: null }
867
868 // Warm highlighter with prefix lines (highlight.js is stateless per call,
869 // so this is a no-op for now — preserved for API parity)
870 void this.prefixContent
871
872 const maxDigits = String(maxLineNumber(this.hunk)).length
873 let oldLine = this.hunk.oldStart
874 let newLine = this.hunk.newStart
875 const effectiveWidth = Math.max(1, width - maxDigits - 2 - 1)
876
877 // First pass: assign markers + line numbers
878 type Entry = { lineNumber: number; marker: Marker; code: string }
879 const entries: Entry[] = this.hunk.lines.map(rawLine => {
880 const marker = parseMarker(rawLine.slice(0, 1))
881 const code = rawLine.slice(1)
882 let lineNumber: number
883 switch (marker) {
884 case '+':
885 lineNumber = newLine++
886 break
887 case '-':
888 lineNumber = oldLine++
889 break
890 case ' ':
891 lineNumber = newLine
892 oldLine++
893 newLine++
894 break
895 }
896 return { lineNumber, marker, code }
897 })
898
899 // Word-diff ranges (skip when dim — too loud)
900 const ranges: Range[][] = entries.map(() => [])
901 if (!dim) {
902 const markers = entries.map(e => e.marker)
903 for (const [delIdx, addIdx] of findAdjacentPairs(markers)) {
904 const [delR, addR] = wordDiffStrings(
905 entries[delIdx]!.code,
906 entries[addIdx]!.code,
907 )
908 ranges[delIdx] = delR
909 ranges[addIdx] = addR
910 }
911 }
912
913 // Second pass: highlight + transform pipeline
914 const out: string[] = []
915 for (let i = 0; i < entries.length; i++) {
916 const { lineNumber, marker, code } = entries[i]!
917 const tokens: Block[] =
918 marker === '-'
919 ? [[defaultStyle(theme), code]]

Callers

nothing calls this directly

Calls 15

detectColorModeFunction · 0.85
buildThemeFunction · 0.85
maxLineNumberFunction · 0.85
parseMarkerFunction · 0.85
findAdjacentPairsFunction · 0.85
wordDiffStringsFunction · 0.85
highlightLineFunction · 0.85
removeNewlinesFunction · 0.85
applyBackgroundFunction · 0.85
dimContentFunction · 0.85
addMarkerFunction · 0.85
addLineNumberFunction · 0.85

Tested by

no test coverage detected