mirror of
http://10.0.2.1:3031/sauer/claude-code.git
synced 2026-06-30 11:16:58 +10:00
190 lines
17 KiB
TypeScript
190 lines
17 KiB
TypeScript
|
|
import { c as _c } from "react/compiler-runtime";
|
||
|
|
import * as React from 'react';
|
||
|
|
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
||
|
|
import { useSettings } from '../hooks/useSettings.js';
|
||
|
|
import { Ansi, Box, type DOMElement, measureElement, NoSelect, Text, useTheme } from '../ink.js';
|
||
|
|
import { isFullscreenEnvEnabled } from '../utils/fullscreen.js';
|
||
|
|
import sliceAnsi from '../utils/sliceAnsi.js';
|
||
|
|
import { countCharInString } from '../utils/stringUtils.js';
|
||
|
|
import { HighlightedCodeFallback } from './HighlightedCode/Fallback.js';
|
||
|
|
import { expectColorFile } from './StructuredDiff/colorDiff.js';
|
||
|
|
type Props = {
|
||
|
|
code: string;
|
||
|
|
filePath: string;
|
||
|
|
width?: number;
|
||
|
|
dim?: boolean;
|
||
|
|
};
|
||
|
|
const DEFAULT_WIDTH = 80;
|
||
|
|
export const HighlightedCode = memo(function HighlightedCode(t0) {
|
||
|
|
const $ = _c(21);
|
||
|
|
const {
|
||
|
|
code,
|
||
|
|
filePath,
|
||
|
|
width,
|
||
|
|
dim: t1
|
||
|
|
} = t0;
|
||
|
|
const dim = t1 === undefined ? false : t1;
|
||
|
|
const ref = useRef(null);
|
||
|
|
const [measuredWidth, setMeasuredWidth] = useState(width || DEFAULT_WIDTH);
|
||
|
|
const [theme] = useTheme();
|
||
|
|
const settings = useSettings();
|
||
|
|
const syntaxHighlightingDisabled = settings.syntaxHighlightingDisabled ?? false;
|
||
|
|
let t2;
|
||
|
|
bb0: {
|
||
|
|
if (syntaxHighlightingDisabled) {
|
||
|
|
t2 = null;
|
||
|
|
break bb0;
|
||
|
|
}
|
||
|
|
let t3;
|
||
|
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||
|
|
t3 = expectColorFile();
|
||
|
|
$[0] = t3;
|
||
|
|
} else {
|
||
|
|
t3 = $[0];
|
||
|
|
}
|
||
|
|
const ColorFile = t3;
|
||
|
|
if (!ColorFile) {
|
||
|
|
t2 = null;
|
||
|
|
break bb0;
|
||
|
|
}
|
||
|
|
let t4;
|
||
|
|
if ($[1] !== code || $[2] !== filePath) {
|
||
|
|
t4 = new ColorFile(code, filePath);
|
||
|
|
$[1] = code;
|
||
|
|
$[2] = filePath;
|
||
|
|
$[3] = t4;
|
||
|
|
} else {
|
||
|
|
t4 = $[3];
|
||
|
|
}
|
||
|
|
t2 = t4;
|
||
|
|
}
|
||
|
|
const colorFile = t2;
|
||
|
|
let t3;
|
||
|
|
let t4;
|
||
|
|
if ($[4] !== width) {
|
||
|
|
t3 = () => {
|
||
|
|
if (!width && ref.current) {
|
||
|
|
const {
|
||
|
|
width: elementWidth
|
||
|
|
} = measureElement(ref.current);
|
||
|
|
if (elementWidth > 0) {
|
||
|
|
setMeasuredWidth(elementWidth - 2);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
t4 = [width];
|
||
|
|
$[4] = width;
|
||
|
|
$[5] = t3;
|
||
|
|
$[6] = t4;
|
||
|
|
} else {
|
||
|
|
t3 = $[5];
|
||
|
|
t4 = $[6];
|
||
|
|
}
|
||
|
|
useEffect(t3, t4);
|
||
|
|
let t5;
|
||
|
|
bb1: {
|
||
|
|
if (colorFile === null) {
|
||
|
|
t5 = null;
|
||
|
|
break bb1;
|
||
|
|
}
|
||
|
|
let t6;
|
||
|
|
if ($[7] !== colorFile || $[8] !== dim || $[9] !== measuredWidth || $[10] !== theme) {
|
||
|
|
t6 = colorFile.render(theme, measuredWidth, dim);
|
||
|
|
$[7] = colorFile;
|
||
|
|
$[8] = dim;
|
||
|
|
$[9] = measuredWidth;
|
||
|
|
$[10] = theme;
|
||
|
|
$[11] = t6;
|
||
|
|
} else {
|
||
|
|
t6 = $[11];
|
||
|
|
}
|
||
|
|
t5 = t6;
|
||
|
|
}
|
||
|
|
const lines = t5;
|
||
|
|
let t6;
|
||
|
|
bb2: {
|
||
|
|
if (!isFullscreenEnvEnabled()) {
|
||
|
|
t6 = 0;
|
||
|
|
break bb2;
|
||
|
|
}
|
||
|
|
const lineCount = countCharInString(code, "\n") + 1;
|
||
|
|
let t7;
|
||
|
|
if ($[12] !== lineCount) {
|
||
|
|
t7 = lineCount.toString();
|
||
|
|
$[12] = lineCount;
|
||
|
|
$[13] = t7;
|
||
|
|
} else {
|
||
|
|
t7 = $[13];
|
||
|
|
}
|
||
|
|
t6 = t7.length + 2;
|
||
|
|
}
|
||
|
|
const gutterWidth = t6;
|
||
|
|
let t7;
|
||
|
|
if ($[14] !== code || $[15] !== dim || $[16] !== filePath || $[17] !== gutterWidth || $[18] !== lines || $[19] !== syntaxHighlightingDisabled) {
|
||
|
|
t7 = <Box ref={ref}>{lines ? <Box flexDirection="column">{lines.map((line, i) => gutterWidth > 0 ? <CodeLine key={i} line={line} gutterWidth={gutterWidth} /> : <Text key={i}><Ansi>{line}</Ansi></Text>)}</Box> : <HighlightedCodeFallback code={code} filePath={filePath} dim={dim} skipColoring={syntaxHighlightingDisabled} />}</Box>;
|
||
|
|
$[14] = code;
|
||
|
|
$[15] = dim;
|
||
|
|
$[16] = filePath;
|
||
|
|
$[17] = gutterWidth;
|
||
|
|
$[18] = lines;
|
||
|
|
$[19] = syntaxHighlightingDisabled;
|
||
|
|
$[20] = t7;
|
||
|
|
} else {
|
||
|
|
t7 = $[20];
|
||
|
|
}
|
||
|
|
return t7;
|
||
|
|
});
|
||
|
|
function CodeLine(t0) {
|
||
|
|
const $ = _c(13);
|
||
|
|
const {
|
||
|
|
line,
|
||
|
|
gutterWidth
|
||
|
|
} = t0;
|
||
|
|
let t1;
|
||
|
|
if ($[0] !== gutterWidth || $[1] !== line) {
|
||
|
|
t1 = sliceAnsi(line, 0, gutterWidth);
|
||
|
|
$[0] = gutterWidth;
|
||
|
|
$[1] = line;
|
||
|
|
$[2] = t1;
|
||
|
|
} else {
|
||
|
|
t1 = $[2];
|
||
|
|
}
|
||
|
|
const gutter = t1;
|
||
|
|
let t2;
|
||
|
|
if ($[3] !== gutterWidth || $[4] !== line) {
|
||
|
|
t2 = sliceAnsi(line, gutterWidth);
|
||
|
|
$[3] = gutterWidth;
|
||
|
|
$[4] = line;
|
||
|
|
$[5] = t2;
|
||
|
|
} else {
|
||
|
|
t2 = $[5];
|
||
|
|
}
|
||
|
|
const content = t2;
|
||
|
|
let t3;
|
||
|
|
if ($[6] !== gutter) {
|
||
|
|
t3 = <NoSelect fromLeftEdge={true}><Text><Ansi>{gutter}</Ansi></Text></NoSelect>;
|
||
|
|
$[6] = gutter;
|
||
|
|
$[7] = t3;
|
||
|
|
} else {
|
||
|
|
t3 = $[7];
|
||
|
|
}
|
||
|
|
let t4;
|
||
|
|
if ($[8] !== content) {
|
||
|
|
t4 = <Text><Ansi>{content}</Ansi></Text>;
|
||
|
|
$[8] = content;
|
||
|
|
$[9] = t4;
|
||
|
|
} else {
|
||
|
|
t4 = $[9];
|
||
|
|
}
|
||
|
|
let t5;
|
||
|
|
if ($[10] !== t3 || $[11] !== t4) {
|
||
|
|
t5 = <Box flexDirection="row">{t3}{t4}</Box>;
|
||
|
|
$[10] = t3;
|
||
|
|
$[11] = t4;
|
||
|
|
$[12] = t5;
|
||
|
|
} else {
|
||
|
|
t5 = $[12];
|
||
|
|
}
|
||
|
|
return t5;
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsIm1lbW8iLCJ1c2VFZmZlY3QiLCJ1c2VNZW1vIiwidXNlUmVmIiwidXNlU3RhdGUiLCJ1c2VTZXR0aW5ncyIsIkFuc2kiLCJCb3giLCJET01FbGVtZW50IiwibWVhc3VyZUVsZW1lbnQiLCJOb1NlbGVjdCIsIlRleHQiLCJ1c2VUaGVtZSIsImlzRnVsbHNjcmVlbkVudkVuYWJsZWQiLCJzbGljZUFuc2kiLCJjb3VudEN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