mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121)
* style(B1-1): 格式化 ink/buddy/cli/context/screens/tasks/services/keybindings/state (43 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 修复了 Box.tsx 和 ScrollBox.tsx 中无效的 global.d.ts import。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-2): 格式化 commands (79 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-4): 格式化 components/PromptInput,FeedbackSurvey,tasks,agents,skills,design-system,wizard (73 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-5): 格式化 components其余 + hooks + tools (232 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-6): 格式化 main/entrypoints/utils/moreright (21 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 更新 README,新增 Run.ps1/TODO.md,删除 V6.md - README.md: 大幅重写,更详细版本历史和配置示例 - Run.ps1: 新增 Windows 启动脚本 - TODO.md: 新增包完成清单 - V6.md: 删除(架构重构规划已不适用) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复以前的问题 * fix: 修复 login 面板的问题 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,192 +1,99 @@
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import { extname } from 'path';
|
||||
import React, { Suspense, use, useMemo } from 'react';
|
||||
import { Ansi, Text } from '../../ink.js';
|
||||
import { getCliHighlightPromise } from '../../utils/cliHighlight.js';
|
||||
import { logForDebugging } from '../../utils/debug.js';
|
||||
import { convertLeadingTabsToSpaces } from '../../utils/file.js';
|
||||
import { hashPair } from '../../utils/hash.js';
|
||||
import { extname } from 'path'
|
||||
import React, { Suspense, use, useMemo } from 'react'
|
||||
import { Ansi, Text } from '../../ink.js'
|
||||
import { getCliHighlightPromise } from '../../utils/cliHighlight.js'
|
||||
import { logForDebugging } from '../../utils/debug.js'
|
||||
import { convertLeadingTabsToSpaces } from '../../utils/file.js'
|
||||
import { hashPair } from '../../utils/hash.js'
|
||||
|
||||
type Props = {
|
||||
code: string;
|
||||
filePath: string;
|
||||
dim?: boolean;
|
||||
skipColoring?: boolean;
|
||||
};
|
||||
code: string
|
||||
filePath: string
|
||||
dim?: boolean
|
||||
skipColoring?: boolean
|
||||
}
|
||||
|
||||
// Module-level highlight cache — hl.highlight() is the hot cost on virtual-
|
||||
// scroll remounts. useMemo doesn't survive unmount→remount. Keyed by hash
|
||||
// of code+language to avoid retaining full source strings (#24180 RSS fix).
|
||||
const HL_CACHE_MAX = 500;
|
||||
const hlCache = new Map<string, string>();
|
||||
function cachedHighlight(hl: NonNullable<Awaited<ReturnType<typeof getCliHighlightPromise>>>, code: string, language: string): string {
|
||||
const key = hashPair(language, code);
|
||||
const hit = hlCache.get(key);
|
||||
const HL_CACHE_MAX = 500
|
||||
const hlCache = new Map<string, string>()
|
||||
function cachedHighlight(
|
||||
hl: NonNullable<Awaited<ReturnType<typeof getCliHighlightPromise>>>,
|
||||
code: string,
|
||||
language: string,
|
||||
): string {
|
||||
const key = hashPair(language, code)
|
||||
const hit = hlCache.get(key)
|
||||
if (hit !== undefined) {
|
||||
hlCache.delete(key);
|
||||
hlCache.set(key, hit);
|
||||
return hit;
|
||||
hlCache.delete(key)
|
||||
hlCache.set(key, hit)
|
||||
return hit
|
||||
}
|
||||
const out = hl.highlight(code, {
|
||||
language
|
||||
});
|
||||
const out = hl.highlight(code, { language })
|
||||
if (hlCache.size >= HL_CACHE_MAX) {
|
||||
const first = hlCache.keys().next().value;
|
||||
if (first !== undefined) hlCache.delete(first);
|
||||
const first = hlCache.keys().next().value
|
||||
if (first !== undefined) hlCache.delete(first)
|
||||
}
|
||||
hlCache.set(key, out);
|
||||
return out;
|
||||
hlCache.set(key, out)
|
||||
return out
|
||||
}
|
||||
export function HighlightedCodeFallback(t0) {
|
||||
const $ = _c(20);
|
||||
const {
|
||||
code,
|
||||
filePath,
|
||||
dim: t1,
|
||||
skipColoring: t2
|
||||
} = t0;
|
||||
const dim = t1 === undefined ? false : t1;
|
||||
const skipColoring = t2 === undefined ? false : t2;
|
||||
let t3;
|
||||
if ($[0] !== code) {
|
||||
t3 = convertLeadingTabsToSpaces(code);
|
||||
$[0] = code;
|
||||
$[1] = t3;
|
||||
} else {
|
||||
t3 = $[1];
|
||||
}
|
||||
const codeWithSpaces = t3;
|
||||
|
||||
export function HighlightedCodeFallback({
|
||||
code,
|
||||
filePath,
|
||||
dim = false,
|
||||
skipColoring = false,
|
||||
}: Props): React.ReactElement {
|
||||
const codeWithSpaces = convertLeadingTabsToSpaces(code)
|
||||
if (skipColoring) {
|
||||
let t4;
|
||||
if ($[2] !== codeWithSpaces) {
|
||||
t4 = <Ansi>{codeWithSpaces}</Ansi>;
|
||||
$[2] = codeWithSpaces;
|
||||
$[3] = t4;
|
||||
} else {
|
||||
t4 = $[3];
|
||||
}
|
||||
let t5;
|
||||
if ($[4] !== dim || $[5] !== t4) {
|
||||
t5 = <Text dimColor={dim}>{t4}</Text>;
|
||||
$[4] = dim;
|
||||
$[5] = t4;
|
||||
$[6] = t5;
|
||||
} else {
|
||||
t5 = $[6];
|
||||
}
|
||||
return t5;
|
||||
return (
|
||||
<Text dimColor={dim}>
|
||||
<Ansi>{codeWithSpaces}</Ansi>
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
let t4;
|
||||
if ($[7] !== filePath) {
|
||||
t4 = extname(filePath).slice(1);
|
||||
$[7] = filePath;
|
||||
$[8] = t4;
|
||||
} else {
|
||||
t4 = $[8];
|
||||
}
|
||||
const language = t4;
|
||||
let t5;
|
||||
if ($[9] !== codeWithSpaces) {
|
||||
t5 = <Ansi>{codeWithSpaces}</Ansi>;
|
||||
$[9] = codeWithSpaces;
|
||||
$[10] = t5;
|
||||
} else {
|
||||
t5 = $[10];
|
||||
}
|
||||
let t6;
|
||||
if ($[11] !== codeWithSpaces || $[12] !== language) {
|
||||
t6 = <Highlighted codeWithSpaces={codeWithSpaces} language={language} />;
|
||||
$[11] = codeWithSpaces;
|
||||
$[12] = language;
|
||||
$[13] = t6;
|
||||
} else {
|
||||
t6 = $[13];
|
||||
}
|
||||
let t7;
|
||||
if ($[14] !== t5 || $[15] !== t6) {
|
||||
t7 = <Suspense fallback={t5}>{t6}</Suspense>;
|
||||
$[14] = t5;
|
||||
$[15] = t6;
|
||||
$[16] = t7;
|
||||
} else {
|
||||
t7 = $[16];
|
||||
}
|
||||
let t8;
|
||||
if ($[17] !== dim || $[18] !== t7) {
|
||||
t8 = <Text dimColor={dim}>{t7}</Text>;
|
||||
$[17] = dim;
|
||||
$[18] = t7;
|
||||
$[19] = t8;
|
||||
} else {
|
||||
t8 = $[19];
|
||||
}
|
||||
return t8;
|
||||
const language = extname(filePath).slice(1)
|
||||
return (
|
||||
<Text dimColor={dim}>
|
||||
<Suspense fallback={<Ansi>{codeWithSpaces}</Ansi>}>
|
||||
<Highlighted codeWithSpaces={codeWithSpaces} language={language} />
|
||||
</Suspense>
|
||||
</Text>
|
||||
)
|
||||
}
|
||||
function Highlighted(t0) {
|
||||
const $ = _c(10);
|
||||
const {
|
||||
codeWithSpaces,
|
||||
language
|
||||
} = t0;
|
||||
let t1;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = getCliHighlightPromise();
|
||||
$[0] = t1;
|
||||
} else {
|
||||
t1 = $[0];
|
||||
}
|
||||
const hl = use(t1) as NonNullable<Awaited<ReturnType<typeof getCliHighlightPromise>>> | null;
|
||||
let t2;
|
||||
if ($[1] !== codeWithSpaces || $[2] !== hl || $[3] !== language) {
|
||||
bb0: {
|
||||
if (!hl) {
|
||||
t2 = codeWithSpaces;
|
||||
break bb0;
|
||||
}
|
||||
let highlightLang = "markdown";
|
||||
if (language) {
|
||||
if (hl.supportsLanguage(language)) {
|
||||
highlightLang = language;
|
||||
} else {
|
||||
logForDebugging(`Language not supported while highlighting code, falling back to markdown: ${language}`);
|
||||
}
|
||||
}
|
||||
;
|
||||
try {
|
||||
t2 = cachedHighlight(hl, codeWithSpaces, highlightLang);
|
||||
} catch (t3) {
|
||||
const e = t3;
|
||||
if (e instanceof Error && e.message.includes("Unknown language")) {
|
||||
logForDebugging(`Language not supported while highlighting code, falling back to markdown: ${e}`);
|
||||
let t4;
|
||||
if ($[5] !== codeWithSpaces || $[6] !== hl) {
|
||||
t4 = cachedHighlight(hl, codeWithSpaces, "markdown");
|
||||
$[5] = codeWithSpaces;
|
||||
$[6] = hl;
|
||||
$[7] = t4;
|
||||
} else {
|
||||
t4 = $[7];
|
||||
}
|
||||
t2 = t4;
|
||||
break bb0;
|
||||
}
|
||||
t2 = codeWithSpaces;
|
||||
|
||||
function Highlighted({
|
||||
codeWithSpaces,
|
||||
language,
|
||||
}: {
|
||||
codeWithSpaces: string
|
||||
language: string
|
||||
}): React.ReactElement {
|
||||
const hl = use(getCliHighlightPromise())
|
||||
const out = useMemo(() => {
|
||||
if (!hl) return codeWithSpaces
|
||||
let highlightLang = 'markdown'
|
||||
if (language) {
|
||||
if (hl.supportsLanguage(language)) {
|
||||
highlightLang = language
|
||||
} else {
|
||||
logForDebugging(
|
||||
`Language not supported while highlighting code, falling back to markdown: ${language}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
$[1] = codeWithSpaces;
|
||||
$[2] = hl;
|
||||
$[3] = language;
|
||||
$[4] = t2;
|
||||
} else {
|
||||
t2 = $[4];
|
||||
}
|
||||
const out = t2;
|
||||
let t3;
|
||||
if ($[8] !== out) {
|
||||
t3 = <Ansi>{out}</Ansi>;
|
||||
$[8] = out;
|
||||
$[9] = t3;
|
||||
} else {
|
||||
t3 = $[9];
|
||||
}
|
||||
return t3;
|
||||
try {
|
||||
return cachedHighlight(hl, codeWithSpaces, highlightLang)
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.message.includes('Unknown language')) {
|
||||
logForDebugging(
|
||||
`Language not supported while highlighting code, falling back to markdown: ${e}`,
|
||||
)
|
||||
return cachedHighlight(hl, codeWithSpaces, 'markdown')
|
||||
}
|
||||
return codeWithSpaces
|
||||
}
|
||||
}, [codeWithSpaces, language, hl])
|
||||
return <Ansi>{out}</Ansi>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user