Skip to content

Commit a5da21f

Browse files
committed
refactor(ui): 优化主题管理和界面相关代码
- 移除 ExitSummaryView 中对宽度的传参,简化组件接口 - 在颜色淡化函数中添加非 hex 色值直接返回的处理,避免错误 - 修改 inlineCode 颜色为更合适的透明紫色 - 修正 markdown 代码块渲染,使用正确的颜色函数 - 精简 slash-commands 中 /new 命令描述文本 - 重构 ThemeManager 中的 revertTheme 方法,改用加载主题设置并解析对比度后应用新主题
1 parent a52d684 commit a5da21f

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/ui/components/MessageView/markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function renderMarkdownSegments(text: string, maxWidth?: number): Markdow
3939
for (const seg of fenceSegments) {
4040
if (seg.kind === "code") {
4141
const langTag = seg.lang ? tc.dim(`[${seg.lang}]`) + "\n" : "";
42-
segments.push({ kind: "code", body: langTag + tc.dim(seg.body), lang: seg.lang });
42+
segments.push({ kind: "code", body: langTag + tc.code(seg.body), lang: seg.lang });
4343
continue;
4444
}
4545
const blocks = splitTableBlocks(seg.body);

src/ui/core/slash-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const BUILTIN_SLASH_COMMANDS: SlashCommandItem[] = [
4646
kind: "new",
4747
name: "new",
4848
label: "/new",
49-
description: "Start a new session with empty context; previous session stays on disk (resumable with /resume)",
49+
description: "Start a new session (previous session resumable with /resume)",
5050
},
5151
{
5252
kind: "init",

src/ui/theme/ThemeManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ export class ThemeManager {
115115
*/
116116
revertTheme(): void {
117117
this.currentPreset = this.loadPresetFromSettings();
118-
const savedSettings = resolveCurrentSettings(this.projectRoot);
119-
this.applyTheme(savedSettings.theme, this.currentPreset);
118+
const themeSettings = this.loadThemeSettings();
119+
const newTheme = this.resolveWithContrast(themeSettings);
120+
this.applyTheme(newTheme, this.currentPreset);
120121
}
121122

122123
/**

src/ui/theme/colors-theme.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ export interface ColorsTheme {
4242

4343
/**
4444
* 将 hex 颜色淡化(混合灰色)。
45+
* 对非 hex 命名色(如 ANSI 的 "white"、"black")返回原色,不做淡化。
4546
*/
4647
function dimHex(hex: string, ratio: number): string {
47-
const h = hex.replace("#", "");
48+
if (!hex.startsWith("#")) {
49+
return hex;
50+
}
51+
const h = hex.slice(1);
4852
const r = parseInt(h.slice(0, 2), 16);
4953
const g = parseInt(h.slice(2, 4), 16);
5054
const b = parseInt(h.slice(4, 6), 16);
@@ -143,7 +147,7 @@ export function buildThemeTokens(
143147
hover: c.LightBlue,
144148
},
145149
inlineCode: {
146-
foreground: c.AccentBlue,
150+
foreground: `${c.AccentPurple}cc`,
147151
background: dimHex(c.Background, 0.08),
148152
border: dimHex(fg, 0.7),
149153
},

src/ui/views/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ function App({ projectRoot, initialPrompt, onRestart }: AppProps): React.ReactEl
795795
onCancel={handlePermissionCancel}
796796
/>
797797
) : isExiting ? (
798-
<ExitSummaryView session={exitSession} width={screenWidth} />
798+
<ExitSummaryView session={exitSession} />
799799
) : (
800800
<PromptInput
801801
projectRoot={projectRoot}

src/ui/views/ExitSummaryView.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { buildExitSummaryData } from "../exit-summary";
77

88
type Props = {
99
session: SessionEntry | null;
10-
width: number;
1110
};
1211

1312
function formatNumber(n: number): string {

0 commit comments

Comments
 (0)