Skip to content

Commit d8f2dcd

Browse files
committed
refactor(ui): 统一使用主题颜色替代硬编码样式
- 移除多个组件和视图中的硬编码颜色,改为使用主题上下文提供的颜色 - 在AppContainer中添加ThemeProvider,初始化全局主题设置 - 优化消息视图、权限提示、提问提示、进程输出、状态列表等组件的颜色适配 - 调整markdown渲染和退出摘要中颜色生成逻辑,支持主题色彩 - 解决部分组件主题切换不更新的问题,确保依赖主题的子组件正确重渲染 - 更新权限提示中的风险颜色映射,改为从主题中读取 - 在PromptInput中支持高亮粘贴标记的颜色主题配置 - 移除了一些不再使用的硬编码颜色属性,提升UI一致性和可维护性
1 parent b892be8 commit d8f2dcd

36 files changed

Lines changed: 1028 additions & 149 deletions

README-en.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,74 @@ For detailed configuration instructions, see: [docs/notify_en.md](docs/notify_en
141141

142142
No. Deep Code has a built-in fine-grained permission control mechanism that lets you confirm operations before the AI assistant executes shell commands, reads/writes files, accesses the network, and more. You can configure each permission scope's policy — always allow, always ask, or deny — via the `permissions` field in `settings.json`. See [docs/permission.md](docs/permission.md) for details.
143143

144+
### How do I customize the theme?
145+
146+
Deep Code CLI includes a built-in default theme (`DEFAULT_THEME`) that works out of the box. To customize colors, set `theme.preset` to `"custom"` in `settings.json` and provide `overrides` or `tokens`.
147+
148+
**Using the default theme (no config required)**
149+
150+
No settings needed — the built-in theme is used automatically.
151+
152+
**Option 1: Partial overrides (preset="custom" + overrides)**
153+
154+
Override only the colors you want to change; the rest keep their defaults:
155+
156+
```json
157+
{
158+
"theme": {
159+
"preset": "custom",
160+
"overrides": {
161+
"accent": "#ff6600",
162+
"success": "greenBright"
163+
}
164+
}
165+
}
166+
```
167+
168+
**Option 2: Full customization (preset="custom" + tokens)**
169+
170+
Provide a complete tokens object, merged on top of the default theme:
171+
172+
```json
173+
{
174+
"theme": {
175+
"preset": "custom",
176+
"tokens": {
177+
"accent": "#229ac3",
178+
"accentAlpha": "#229ac3e6",
179+
"active": "cyanBright",
180+
"success": "green",
181+
"error": "red",
182+
"warning": "yellow",
183+
"info": "magenta",
184+
"riskLow": "#22c55e",
185+
"riskMedium": "#f59e0b",
186+
"riskHigh": "#ef4444",
187+
"text": "white",
188+
"textDim": "gray",
189+
"code": "cyan",
190+
"border": "gray",
191+
"thinking": "gray",
192+
"gradients": ["#229ac3e6", "#229ac3e6"]
193+
}
194+
}
195+
}
196+
```
197+
198+
> Note: `overrides` and `tokens` only take effect when `preset` is set to `"custom"`. When `preset` is `"default"` or unset, the built-in default theme is always used.
199+
200+
Available token descriptions:
201+
202+
| Token | Used For |
203+
|-------|----------|
204+
| `accent`, `accentAlpha`, `active` | Logo, user messages, selected items, etc. |
205+
| `success`, `error`, `warning`, `info` | Tool statuses, permission prompts, skill loading; `warning` also colors list bullets |
206+
| `riskLow`, `riskMedium`, `riskHigh` | Permission confirmation panel |
207+
| `text`, `textDim`, `code`, `border`, `thinking` | Body text, secondary text/blockquotes, code, borders, thinking status |
208+
| `gradients` | Logo and exit panel gradient colors |
209+
210+
Color values support hex (`"#ff6600"`), hex with alpha (`"#229ac3e6"`), and chalk named colors (`"cyanBright"`, `"green"`).
211+
144212
## Contributing
145213

146214
Contributions are welcome! Here's how to get started:

README-zh_CN.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,74 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
141141
}
142142
```
143143

144+
### 如何自定义主题?
145+
146+
Deep Code CLI 内置一套默认主题(`DEFAULT_THEME`),无需配置即可使用。如需自定义颜色,在 `settings.json` 中设置 `theme.preset``"custom"` 后提供 `overrides``tokens`
147+
148+
**使用默认主题(无需配置)**
149+
150+
直接使用内置主题,不做任何设置。
151+
152+
**方式一:局部覆盖(preset="custom" + overrides)**
153+
154+
只覆盖需要调整的颜色,其余保持默认值:
155+
156+
```json
157+
{
158+
"theme": {
159+
"preset": "custom",
160+
"overrides": {
161+
"accent": "#ff6600",
162+
"success": "greenBright"
163+
}
164+
}
165+
}
166+
```
167+
168+
**方式二:完全自定义(preset="custom" + tokens)**
169+
170+
提供完整的 tokens 对象,基于默认主题合并:
171+
172+
```json
173+
{
174+
"theme": {
175+
"preset": "custom",
176+
"tokens": {
177+
"accent": "#229ac3",
178+
"accentAlpha": "#229ac3e6",
179+
"active": "cyanBright",
180+
"success": "green",
181+
"error": "red",
182+
"warning": "yellow",
183+
"info": "magenta",
184+
"riskLow": "#22c55e",
185+
"riskMedium": "#f59e0b",
186+
"riskHigh": "#ef4444",
187+
"text": "white",
188+
"textDim": "gray",
189+
"code": "cyan",
190+
"border": "gray",
191+
"thinking": "gray",
192+
"gradients": ["#229ac3e6", "#229ac3e6"]
193+
}
194+
}
195+
}
196+
```
197+
198+
> 注意:`preset` 必须设为 `"custom"``overrides``tokens` 才会生效。`preset``"default"` 或不配置时始终使用系统默认主题。
199+
200+
可覆盖的 token 说明:
201+
202+
| Token | 用途 |
203+
|---------------------------------------------|----------------------------------|
204+
| `accent``accentAlpha``active` | Logo、用户消息、选中项等 |
205+
| `success``error``warning``info` | 工具状态、权限提示、技能加载,`warning` 也是列表标记色 |
206+
| `riskLow``riskMedium``riskHigh` | 权限确认面板 |
207+
| `text``textDim``code``border``thinking` | 正文、副文/引用块、代码、边框、思考状态 |
208+
| `gradients` | Logo 与退出面板的渐变色数组 |
209+
210+
颜色值支持 hex(`"#ff6600"`)、hex 含透明度(`"#229ac3e6"`)、chalk 命名色(`"cyanBright"``"green"`)。
211+
144212
## 贡献
145213

146214
欢迎贡献代码!以下是参与方式:

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,74 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
141141
}
142142
```
143143

144+
### 如何自定义主题?
145+
146+
Deep Code CLI 内置一套默认主题(`DEFAULT_THEME`),无需配置即可使用。如需自定义颜色,在 `settings.json` 中设置 `theme.preset``"custom"` 后提供 `overrides``tokens`
147+
148+
**使用默认主题(无需配置)**
149+
150+
直接使用内置主题,不做任何设置。
151+
152+
**方式一:局部覆盖(preset="custom" + overrides)**
153+
154+
只覆盖需要调整的颜色,其余保持默认值:
155+
156+
```json
157+
{
158+
"theme": {
159+
"preset": "custom",
160+
"overrides": {
161+
"accent": "#ff6600",
162+
"success": "greenBright"
163+
}
164+
}
165+
}
166+
```
167+
168+
**方式二:完全自定义(preset="custom" + tokens)**
169+
170+
提供完整的 tokens 对象,基于默认主题合并:
171+
172+
```json
173+
{
174+
"theme": {
175+
"preset": "custom",
176+
"tokens": {
177+
"accent": "#229ac3",
178+
"accentAlpha": "#229ac3e6",
179+
"active": "cyanBright",
180+
"success": "green",
181+
"error": "red",
182+
"warning": "yellow",
183+
"info": "magenta",
184+
"riskLow": "#22c55e",
185+
"riskMedium": "#f59e0b",
186+
"riskHigh": "#ef4444",
187+
"text": "white",
188+
"textDim": "gray",
189+
"code": "cyan",
190+
"border": "gray",
191+
"thinking": "gray",
192+
"gradients": ["#229ac3e6", "#229ac3e6"]
193+
}
194+
}
195+
}
196+
```
197+
198+
> 注意:`preset` 必须设为 `"custom"``overrides``tokens` 才会生效。`preset``"default"` 或不配置时始终使用系统默认主题。
199+
200+
可覆盖的 token 说明:
201+
202+
| Token | 用途 |
203+
|---------------------------------------------|----------------------------------|
204+
| `accent``accentAlpha``active` | Logo、用户消息、选中项等 |
205+
| `success``error``warning``info` | 工具状态、权限提示、技能加载,`warning` 也是列表标记色 |
206+
| `riskLow``riskMedium``riskHigh` | 权限确认面板 |
207+
| `text``textDim``code``border``thinking` | 正文、副文/引用块、代码、边框、思考状态 |
208+
| `gradients` | Logo 与退出面板的渐变色数组 |
209+
210+
颜色值支持 hex(`"#ff6600"`)、hex 含透明度(`"#229ac3e6"`)、chalk 命名色(`"cyanBright"``"green"`)。
211+
144212
## 贡献
145213

146214
欢迎贡献代码!以下是参与方式:

src/common/update-check.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as path from "path";
66
import { render, type Instance } from "ink";
77
import chalk from "chalk";
88
import { UpdatePrompt, type UpdatePromptChoice } from "../ui";
9+
import { DEFAULT_THEME } from "../ui/theme/presets";
910
import { killProcessTree } from "./process-tree";
1011

1112
export type PackageInfo = {
@@ -58,7 +59,7 @@ export async function promptForPendingUpdate(packageInfo: PackageInfo): Promise<
5859
if (ok) {
5960
writeUpdateState({ ...state, pending: null });
6061
process.stdout.write(
61-
`\n${chalk.red("Deep Code has been updated. Please restart the CLI to use the new version.")}\n\n`
62+
`\n${chalk.hex(DEFAULT_THEME.error)("Deep Code has been updated. Please restart the CLI to use the new version.")}\n\n`
6263
);
6364
}
6465
return { installed: ok };

src/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { defaultsToThinkingMode } from "./common/model-capabilities";
2+
import { resolveTheme } from "./ui/theme";
3+
import type { ThemeTokens, ThemeSettings } from "./ui/theme";
24
import * as fs from "fs";
35
import * as os from "os";
46
import * as path from "path";
@@ -51,6 +53,7 @@ export type DeepcodingSettings = {
5153
webSearchTool?: string;
5254
mcpServers?: Record<string, McpServerConfig>;
5355
permissions?: PermissionSettings;
56+
theme?: ThemeSettings;
5457
};
5558

5659
export type ResolvedDeepcodingSettings = {
@@ -65,6 +68,7 @@ export type ResolvedDeepcodingSettings = {
6568
webSearchTool?: string;
6669
mcpServers?: Record<string, McpServerConfig>;
6770
permissions: Required<PermissionSettings>;
71+
theme: ThemeTokens;
6872
};
6973

7074
export type ModelConfigSelection = {
@@ -333,6 +337,7 @@ export function resolveSettingsSources(
333337
webSearchTool: webSearchTool || undefined,
334338
mcpServers: mergeMcpServers(userSettings, projectSettings, userEnv, projectEnv, systemEnv),
335339
permissions: mergePermissions(userSettings, projectSettings),
340+
theme: resolveTheme(userSettings?.theme ?? projectSettings?.theme),
336341
};
337342
}
338343

0 commit comments

Comments
 (0)